Cryptography Reference
In-Depth Information
Listing 6-2 Python code for generating known plaintext-ciphertext pairs for use in EASY1 linear cryptanalys-
is.
# Set the number of known plaintext--ciphertext pairs
# 1800 is sufficient for our simple expression
numplaintexts = 1800
# Here we set a simple key
key = mux([0x12, 0x12, 0x12, 0x12, 0x12, 0x12])
# The encryption function, with no key schedule
def encrypt(p, rounds):
x = p
for i in range(rounds):
x = round(x, key)
return x
# Import the random package
import random
# Use a fixed seed, so that we get reproducibility
random.seed(12345)
# Create lists for the plaintext and ciphertext
plaintext = []
ciphertext = []
# Generate the texts
for i in range(0,numplaintexts):
# Generate a random plaintext
r = long(random.randint(0,2**36))
plaintext.append(r)
# Also store the corresponding ciphertext
c = encrypt(r,3)
ciphertext.append(c)
Finally, we get to the Python code for doing the actual cryptanalysis in Listing 6-3 . In this code, we set all of
the counts to zero, and then, for each possible subkey, take every plaintext-ciphertext pair and see if the linear
expression is true, and if so, increment the count of the key.
 
 
Search WWH ::




Custom Search