Cryptography Reference
In-Depth Information
[24, 5, 15, 23, 14, 32, 19, 18, 26, 17, 6, 12, 34, 9, 8, 20, 28, 0, 2,
21, 29,
11, 33, 22, 30, 31, 1, 25, 3, 35, 16, 13, 27, 7, 10, 4]
Our goal with EASY1 is that it should be easy to understand and fast to derive keys without the use of crypt-
analysis (so answers can be verified).
I'll provide some quick code to perform EASY1.
4.4.1.1 Python Implementation
Here,IshowasimpleEASY1implementation inPython.Forsimplicity,Iwillmaketheimplementation generic
so that different values can be easily put in and tested.
Assume that the S-box is input as a simple array in a variable called s, and that the P-box is also stored as an
array in s.
WecanmakegenericS-boxandP-boxfunctions.TheS-boxfunctionissimple:Usetheargumentasanindex
into the array, which will return the appropriate value. The P-box implementation is a bit trickier, as shown in
Listing 4-1 .
Listing 4-1 Python code for the EASY1 S-box and P-box.
##########################################
# S-box function
##########################################
def sbox(x):
return s[x]
##########################################
# P-box function
##########################################
def pbox(x):
# if the texts are more than 32 bits,
# then we have to use longs
y = 0l
# For each bit to be shuffled
for i in range(len(p)):
# If the original bit position
# is a 1, then make the result
# bit position have a 1
if (x & (1l << i)) != 0:
y = y ^ (1l << p[i])
return y
In Listing 4-1 , we first have to introduce some cumbersome notation: The "l" (or "L" ) modifier specifies
that the number may grow to become more than 32 bits (which is the size of a normal Python integer). Although
it can automatically grow, it gives a lot of warnings if we don't tell Python we are expecting this, by specifying
that we want a long integer, meaning that it can be much bigger. (The values of the bits of the output that are
not copied are all zeros.)
 
 
Search WWH ::




Custom Search