global r2
sbox = [[0 for col in range(16)] for row in range(16)]
def msb(num):
for i in range(0,8):
if not(num >> (i + 1)):
return i
def divide(a, b, r2):
a_msb = msb(a)
b_msb = msb(b)
if(a < b):
r = a
return 0;
bit = a_msb - b_msb
temp = b
temp = temp << bit
a = a ^ temp
return (1 << bit) | divide(a, b, r2)
def multiply(a, b): #GF(2^8)乘法
res = 0
if(b & 0x01):
res = a
for i in range(0,8):
if(b & (0x01 << i)):
temp = a
for j in range(0,i):
if not(temp & 0x80):
temp <<= 1
sbox = [[0 for col in range(16)] for row in range(16)]
def msb(num):
for i in range(0,8):
if not(num >> (i + 1)):
return i
def divide(a, b, r2):
a_msb = msb(a)
b_msb = msb(b)
if(a < b):
r = a
return 0;
bit = a_msb - b_msb
temp = b
temp = temp << bit
a = a ^ temp
return (1 << bit) | divide(a, b, r2)
def multiply(a, b): #GF(2^8)乘法
res = 0
if(b & 0x01):
res = a
for i in range(0,8):
if(b & (0x01 << i)):
temp = a
for j in range(0,i):
if not(temp & 0x80):
temp <<= 1