本文整理汇总了Python中BitVector.gf_MI方法的典型用法代码示例。如果您正苦于以下问题:Python BitVector.gf_MI方法的具体用法?Python BitVector.gf_MI怎么用?Python BitVector.gf_MI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitVector
的用法示例。
在下文中一共展示了BitVector.gf_MI方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_s_box
# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import gf_MI [as 别名]
def build_s_box(encrypt_or_decrypt):
AES_modulus = BitVector(bitstring='100011011')
c = BitVector(bitstring='01100011')
d = BitVector(bitstring='00000101')
new_sub_bytes = []
if (encrypt_or_decrypt == 'e'):
for i in range(0, 256):
# Build lookup table
a = BitVector(intVal = i, size=8).gf_MI(AES_modulus, 8) if i != 0 else BitVector(intVal=0)
# Byte scrambling
a1,a2,a3,a4 = [a.deep_copy() for x in range(4)]
a ^= (a1 >> 4) ^ (a2 >> 5) ^ (a3 >> 6) ^ (a4 >> 7) ^ c
new_sub_bytes.append(int(a))
else:
for i in range(0, 256):
b = BitVector(intVal = i, size=8)
# byte scrambling
b1,b2,b3 = [b.deep_copy() for x in range(3)]
b = (b1 >> 2) ^ (b2 >> 5) ^ (b3 >> 7) ^ d
check = b.gf_MI(AES_modulus, 8)
b = check if isinstance(check, BitVector) else 0
new_sub_bytes.append(int(b))
sub_byte_table = []
for i in range(16):
sub_byte_table.append([])
for j in range(16):
sub_byte_table[i].append(new_sub_bytes[(i * 16) + j])
return sub_byte_table
示例2: GenerateSubTable
# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import gf_MI [as 别名]
def GenerateSubTable(modeChar):
#Table Generation Variables
modulus_poly = BitVector(bitstring = '100011011') #irreducible polynomial used in AES --> (x^8 + x^4 + x^3 + x + 1)
byte_c = BitVector(bitstring = '01100011') #Encryption Mangle-Byte
byte_d = BitVector(bitstring = '00000101') #Decryption Mangle-Byte
scrambledBV = BitVector(size = 8)
#Initialize 16x16 Sub-Table with all 0 Bit-Vectors
zeroBV = BitVector(size = 8)
LookUpTable = [[zeroBV.deep_copy() for x in range(16)] for y in range(16)]
#Set Each Table Entry to Multiplicative Inverse (in GF(2^8)) of Bit-Vector Concatenation of Row and Column 4-bit Bit-Vectors
for x in range(16):
for y in range(16):
rowBV = BitVector(intVal=x, size=4) #Creat Bit Vector for Row Value
colBV = BitVector(intVal=y, size=4) #Creat Bit Vector for Column Value
tableBV_entry = rowBV + colBV
#Perform MI & Bit-Mangling on Table Entries
#If Mode is Encryption...
if modeChar == 'E':
#Only find MI of all bit-vectors except 0
if (x != 0) or (y != 0):
tableBV_entry = tableBV_entry.gf_MI(modulus_poly, 8) #Determine MI of table entry Bit-Vector
for bit_ind in range(0, 8):
newBit = tableBV_entry[bit_ind]^tableBV_entry[(bit_ind+1)%8]^tableBV_entry[(bit_ind+2)%8]^tableBV_entry[(bit_ind+3)%8]^tableBV_entry[(bit_ind+4)%8]^byte_c[bit_ind]
scrambledBV[bit_ind] = newBit
#If Mode is Decryption...
else:
for bit_ind in range(0, 8):
newBit = tableBV_entry[(bit_ind+6)%8]^tableBV_entry[(bit_ind+3)%8]^tableBV_entry[(bit_ind+1)%8]^byte_d[bit_ind]
scrambledBV[bit_ind] = newBit
#Only find MI of all bit-vectors except 0
if int(scrambledBV) != 0:
scrambledBV = scrambledBV.gf_MI(modulus_poly, 8) #Determine MI of table entry Bit-Vector
LookUpTable[x][y] = copy.deepcopy(scrambledBV)
return LookUpTable
示例3: generateTableDecrypt
# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import gf_MI [as 别名]
def generateTableDecrypt():
table = [[0 for n in range(16)] for m in range(16)]
temp = BitVector(size=8)
for i in range(16):
for j in range(16):
temp[0:4] = BitVector(intVal=i,size=4)
temp[4:8] = BitVector(intVal=j,size=4)
tempp = BitVector(size=8)
for k in range(8):
tempp[k] = temp[(k-2)%8] ^ temp[(k-5)%8] ^ temp[(k-7)%8] ^ d[k]
if tempp == zero:
inverse = BitVector(size=8)
else:
inverse = tempp.gf_MI(modulus, 8)
table[i][j] = inverse
return table
示例4: generateTableEncrypt
# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import gf_MI [as 别名]
def generateTableEncrypt():
table = [[0 for n in range(16)] for m in range(16)]
temp = BitVector(size=8)
for i in range(16):
for j in range(16):
temp[0:4] = BitVector(intVal=i,size=4)
temp[4:8] = BitVector(intVal=j,size=4)
if temp == zero:
inverse = temp
else:
inverse = temp.gf_MI(modulus, 8)
tempp = BitVector(size=8)
for k in range(8):
tempp[k] = inverse[k] ^ inverse[(k-4)%8] ^ inverse[(k-5)%8] ^ inverse[(k-6)%8] ^ inverse[(k-7)%8] ^ c[k]
table[i][j] = tempp
return table
示例5: genTables
# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import gf_MI [as 别名]
def genTables():
c = BitVector(bitstring='01100011')
d = BitVector(bitstring='00000101')
for i in range(0, 256):
a = BitVector(intVal = i, size=8).gf_MI(AES_modulus,8) if i != 0 else BitVector(intVal=0)
a1,a2,a3,a4 = [a.deep_copy() for x in range(4)]
a ^= (a1 >> 4) ^ (a2 >> 5) ^ (a3 >> 6) ^ (a4 >> 7) ^ c
subBytesTable.append(int(a))
b = BitVector(intVal = i, size=8)
b1,b2,b3 = [b.deep_copy() for x in range(3)]
b = (b1 >> 2) ^ (b2 >> 5) ^ (b3 >> 7) ^ d
check = b.gf_MI(AES_modulus, 8)
b = check if isinstance(check, BitVector) else 0
invSubBytesTable.append(int(b))
示例6: genTables
# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import gf_MI [as 别名]
def genTables():
c = BitVector(bitstring="01100011")
d = BitVector(bitstring="00000101")
for i in range(0, 256):
# For the encryption SBox
a = BitVector(intVal=i, size=8).gf_MI(AES_modulus, 8) if i != 0 else BitVector(intVal=0)
# For byte scrambling for the encryption SBox entries:
a1, a2, a3, a4 = [a.deep_copy() for x in range(4)]
a ^= (a1 >> 4) ^ (a2 >> 5) ^ (a3 >> 6) ^ (a4 >> 7) ^ c
subBytesTable.append(int(a))
# For the decryption Sbox:
b = BitVector(intVal=i, size=8)
# For byte scrambling for the decryption SBox entries:
b1, b2, b3 = [b.deep_copy() for x in range(3)]
b = (b1 >> 2) ^ (b2 >> 5) ^ (b3 >> 7) ^ d
check = b.gf_MI(AES_modulus, 8)
b = check if isinstance(check, BitVector) else 0
invSubBytesTable.append(int(b))
示例7: BitVector
# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import gf_MI [as 别名]
modulus = BitVector(bitstring='100011011') # AES modulus
n = 8
a = BitVector(bitstring='0110001')
b = BitVector(bitstring='0110')
c = a.gf_multiply_modular(b, modulus, n)
print("Modular product of a=" + str(a) + " b=" +
str(b) + " in GF(2^8) is " + str(c))
# 10100110
print("\nTest multiplicative inverses in GF(2^3) with " +
"modulus polynomial = x^3 + x + 1:")
print("Find multiplicative inverse of a single bit array")
modulus = BitVector(bitstring='100011011') # AES modulus
n = 8
a = BitVector(bitstring='00110011')
mi = a.gf_MI(modulus, n)
print("Multiplicative inverse of " + str(a) + " in GF(2^8) is " + str(mi))
print("\nIn the following three rows shown, the first row shows the " +
"\nbinary code words, the second the multiplicative inverses," +
"\nand the third the product of a binary word with its" +
"\nmultiplicative inverse:\n")
mod = BitVector(bitstring='1011')
n = 3
bitarrays = [BitVector(intVal=x, size=n) for x in range(1, 2 ** 3)]
mi_list = [x.gf_MI(mod, n) for x in bitarrays]
mi_str_list = [str(x.gf_MI(mod, n)) for x in bitarrays]
print("bit arrays in GF(2^3): " + str([str(x) for x in bitarrays]))
print("multiplicati_inverses: " + str(mi_str_list))
products = [str(bitarrays[i].gf_multiply_modular(mi_list[i], mod, n))