Cryptography Reference
In-Depth Information
Listing 4-4 Python code for EASY1 encryption.
##########################################
# Round function
##########################################
def round(p,k):
u = []
# Calculate the S-boxes
for x in demux(p):
u.append(sbox(x))
# Run through the P-box
v = demux(pbox(mux(u)))
# XOR in the key
w = mix(v,k)
# Glue back together, return
return mux(w)
##########################################
# Encryption
##########################################
def encrypt(p, rounds):
x = p
for i in range(rounds):
x = round(x, key)
return x
To complete this code roundup, we have the decryption code (shown in Listing 4-5 ) .
 
 
Search WWH ::




Custom Search