Professional Documents
Culture Documents
Des
Des
Des
restart:
This worksheet walks through the example of using DES that is on the handouts we have been looking at. This worksheet assumes that you understand key expansion. In this worksheet it is done with a single command that suppresses all the intermediate steps. It is done in full detail in the DES key expansion worksheet. This worksheet also assume that you have been through the worksheets on DES constants and DES functions and have created the DES.m file that contains those functions and constants. (If this is not true you should run those worksheets now.)
>
read `DES.m`:
Initial setup
We start with a key in hex which we expand into a list of round keys.
>
bin2 := InitPerm(bin1);
R0 := substring(bin2,33..64); L0 := substring(bin2,1..32);
Next we want to take the 48 bit result and break it into a vector of 8 6 bit words. Each word is then used to get an s-box value.
>
Next we want to convert the values in vec2 into 4 bit binary words and concatenate them together.
>
bin4 := cat(seq(vec2[i],i=1..8));
The result of the concatenation is then acted on by the permutation P to give the f-value.
>
f1 := PPerm(bin4);
R1 := xor32(f1,L0); L1 := R0;
>
fcomb := proc(ri, ki) local t1,t2, t3, vec1, vec2, i: t1 := xor48(ki,expander(ri)): vec1 := prodbs(t1): vec2 := linalg[vector](8,[seq(SBox[i][vec1[i]],i=1..8)]): t2 := cat(seq(vec2[i],i=1..8)): t3 := PPerm(t2): end: > for i from 2 to 16 do L[i] := R[i-1]; R[i] := xor32(L[i-1],fcomb(R[i-1],key[i])); od;
Now we put the left and right halves together in reverse order, invert the initial permutation, and convert to hex.
>
Decrypting
Now we try decrypting. We will essentially go backward through the procedure.
>
>
Now that we have done the 16 rounds, we need to put the two halves of the string together, unscramble it, make it a number and convert it back to ASCII
>
Now we decrypt:
>
E xercises - Key expansion 1) Start with the key "iamhappy" and converts to the hex string "69616D6861707079". Convert the key to binary and apply PC1.
>
2) Break the key into 2 halves and create arrays of the halves shifted 16 times according to the given formula.
>
3) Put the halves back together and apply PC2 to produce the 16 keys in the key vector.
>
4) Use keyexpander to do the same thing in a single command. Make sure that your answer agrees with your answer to exercise 3.
>
E xercises - Encryption 5) The message "Be Happy" converts to the hex string "4265204861707079". Convert this to binary and apply the initial permutation,
>
6) Create 2 arrays of length 16 entitled R and L. Define R0 and L0 as the appropriate halves of your previous answer. Use these numbers and your key to define R[1] and L[1]. Inductively define R[i] and L[i] for i from 2 through 16.
>
7) Put the 2 halves back together in reverse order and use IPI to get the coded message.
>
9) Use DES and the "iamhappy" key to encrypt the first 8 letters of your name. Put the results to the bulletin board. Decrypt someone else's message.
>