Beispiel #1
0

s = ['s{}'.format(i) for i in range(128)]
t = ['t{}'.format(i) for i in range(128)]

d = s[:n]
c = s[n:2 * n]
b = s[2 * n:3 * n]
a = s[3 * n:]

#Step 1
for i in range(n):
    BelT.apply_mov(d[i], t[i])
    BelT.apply_mov(a[i], t[3 * n + i])

BelT.addconstant_mod(t[:n], t[:n], n, 4 * n)
BelT.addconstant_mod(t[3 * n:], t[3 * n:], n, 8 * n)
t[:n] = G(t[:n], 21)
t[3 * n:] = G(t[3 * n:], 5)
for i in range(n):
    BelT.apply_xor(c[i], t[i], c[i])
    BelT.apply_xor(b[i], t[3 * n + i], b[i])

#Step 2
for i in range(n):
    BelT.apply_mov(b[i], t[2 * n + i])

BelT.addconstant_mod(t[2 * n:3 * n], t[2 * n:3 * n], n, 12 * n)
t[2 * n:3 * n] = G(t[2 * n:3 * n], 13)
BelT.addconstant_mod(a, a, n, 16 * n)
BelT.add_mod(a, t[2 * n:3 * n], a, n, 20 * n)
Beispiel #2
0
n = 8

s = ['s{}'.format(i) for i in range(64)]
t = ['t{}'.format(i) for i in range(64)]

for i in range(n):
    HIGHT.apply_xor(s[(i+3)%n],s[(i+4)%n],'t{}'.format(i))
    HIGHT.apply_xor(s[(i+6)%n],'t{}'.format(i),'t{}'.format(i))
    
    HIGHT.apply_xor(s[16+(i+1)%n],s[16+(i+2)%n],'t{}'.format(16+i))
    HIGHT.apply_xor(s[16+(i+7)%n],'t{}'.format(16+i),'t{}'.format(16+i))
    
    HIGHT.apply_xor(s[32+(i+3)%n],s[32+(i+4)%n],'t{}'.format(32+i))
    HIGHT.apply_xor(s[32+(i+6)%n],'t{}'.format(32+i),'t{}'.format(32+i))
    
    HIGHT.apply_xor(s[48+(i+1)%n],s[48+(i+2)%n],'t{}'.format(48+i))
    HIGHT.apply_xor(s[48+(i+7)%n],'t{}'.format(48+i),'t{}'.format(48+i))

HIGHT.add_mod(t[:8],s[8:16],s[8:16],n,64)
HIGHT.add_mod(t[32:40],s[40:48],s[40:48],n,128)

HIGHT.addconstant_mod(t[16:24],t[16:24],n,192)
HIGHT.addconstant_mod(t[48:56],t[48:56],n,256)

for i in range(n):
    HIGHT.apply_xor(t[16+i],s[24+i],s[24+i])
    HIGHT.apply_xor(t[48+i],s[56+i],s[56+i])
    
shuffle = [7] + range(7)
HIGHT.shufflewords(shuffle,n,1)