 # Sbox2ANF.zip

• PUDN用户
了解作者
• C/C++
开发工具
• 1KB
文件大小
• zip
文件格式
• 0
收藏次数
• 1 积分
下载积分
• 3
下载次数
• 2010-02-20 20:44
上传日期
This code for network security .Sbox which is used for give high security for the network .By c programming Sbox2ANF.zip
• Sbox2ANF.py
2.4KB

#!/usr/bin/env python """ Translate sbox to ANF Boolean functions. The size of the input sbox should be \$2^n\$. """ import sys import math __author__ = 'Bo Zhu, http://cis.sjtu.edu.cn/index.php/Bo_Zhu' __copyright__ = 'Copyright 2009, Shanghai Jiao Tong University' __license__ = 'GPL, http://www.gnu.org/licenses/gpl.txt' class InputError(Exception): "Raise this exception when the size of sbox is not \$2^n\$." def __str__(self): return repr('Invalid size of sbox!') def components(x): """ A little tricky here. Find out which entries of the sbox should be considered. Return a list containing the indices of such entries. """ return [i for i in range(x + 1) if x & i == i] def sbox2anf(sbox): """ The core function of Sbox2ANF module. Calculate every coefficient of the ANF Boolean functions. Return a nested list containing the computed coefficients. """ num = len(sbox) dim = int(math.log(num, 2)) if 2 ** dim != num: raise InputError ls = [] for d in range(dim): dc = [] for n in range(num): sign = 0 for i in components(n): sign = sign ^ ((sbox[i] >> d) & 0x1) dc.append(sign) ls.append(dc) return ls def print_anf(sbox): "Print out the ANF equations." anf = sbox2anf(sbox) for i in range(len(anf)): sys.stdout.write('y%u = ' % i) first_time = True ls = anf[i] for j in range(len(ls)): if ls[j] == 1: if first_time: first_time = False else: sys.stdout.write(' + ') if j == 0: sys.stdout.write('1') else: mask = 0x1 while mask <= j: if mask & j > 0 : sys.stdout.write('x%u' % int(math.log(mask, 2))) mask = mask << 1 if first_time: # if still be True sys.stdout.write('0') sys.stdout.write('\n') if __name__ == '__main__': print 'The sample sbox' sample_sbox = (0x0, 0x2, 0x4, 0x6, 0x7, 0xA, 0xC, 0xE, 0x1, 0x3, 0x5, 0x7, 0x9, 0xB, 0xD, 0xF) print 'y = sbox(x) =', sample_sbox print 'has been translated to ANF Boolean functions' print_anf(sample_sbox) 相关推荐
• sbox.zip
Matlab tool for S,Z,H,Y parameter transfer
• sbox-milp.zip
描述AES算法的CPLEX算法的生成代码。
• DEC_code.rar
DEC编解码,采用面向对象实现，包含编码及解码两部分，方便大家需要。
• code_matlab.zip
SM4加密算法matlab程序
• C语言的AES加密算法
C语言实现的AES加密解密算法，希望对大家有所帮助...分不多了，多要点，哈哈
• des c/c++source code
标准的DES C语言实现和命令行演示，非常方便使用DES集成到其它系统中去
• DES加密程序 C语言
很简短的用C语言编写的DES加密算法 有助于为初学者理清思路。
• matlab code for 3des
利用DES算法（包括ECB和CBC模式）加解密BMP图像 George Marsaglia的“The mother”随机数生成代码，称循环周期达2^250，可以通过ts检验，适用于大规模仿真。 源码已进行类封装。测试程序直接产生可用于matlab的m...
• Sbox.rar
sbox implimanation in the aes verilog code
• sendmail.8.10.0.Beta10.tar.Z
被广泛使用的发送邮件(SMTP)服务器