DES Key expansion
© Mike May, S. J., 2002
maymk@slu.edu
This expands the key for the example from class.
| > |
This worksheet assumes that you have already executed the DES constants and DES functions worksheets in this Maple session. At the end of the DES functions worksheet, the variables and functions are stored in the DES.m file.
| > | read `DES.m`: |
We want to start with a key in hex and expand it out to the string of 16 keys used for DES.
| > | keytest := "133457799BBCDFF1"; keybin:= convert(convert(keytest,decimal,hex),binary); binlength := length(keybin); |
We convert the key to binary and add leading zeroes as needed
| > | keybin64 := cat(seq("0",i=1..(64-binlength)),keybin); |
We can see what we have if we remove parity checkbits
| > | keybin56 :=cat(seq(substring(keybin64,i*8-7..i*8-1),i=1..8)); |
But we apply permutation PC1 to the key
| > | PC1key := PC1onKey(keybin64); |
This gets broken into 2 halves
| > | c0 := substring(PC1key,1..28): d0:=substring(PC1key,29..56): |
The halves are permuted by leftshifts according to the formula
| > | c := linalg[vector](16): d := linalg[vector](16): key := linalg[vector](16): c[1] := cat(substring(c0,2..28),substring(c0,1)): d[1] := cat(substring(d0,2..28),substring(d0,1)): for i from 2 to 16 do c[i] := cat(substring(c[i-1],keyshifts[i]+1..28), substring(c[i-1],1..keyshifts[i])): d[i] := cat(substring(d[i-1],keyshifts[i]+1..28), substring(d[i-1],1..keyshifts[i])): od: |
The keys are then produced by acting PC2 on the halves put back together
| > | for i from 1 to 16 do key[i] := convert(PC2onKey(cat(c[i],d[i])),string); od; |
| > |
You are now ready to go to worksheets with DES properly done, either DES example or DES modes.
| > |