Data Encryption Standard [How DES encryption works with examples]

Data encryption standard example

  Message = 0123456789ABCDEF
 M = 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
  Key = 133457799BBCDFF1
  K = 00010011 00110100 01010111 01111001 10011011 10111100 11011111 11110001

Step 1: Create 16 sub keys, each of which is 48-bits long.
In the general scheme of DES is shown that a 64-bit key is used –the bits of the key are numbered from 1 to 64. ô€‚„





     The algorithm ignores every 8, 16, 24, 32, 40, 48, 56, and 64 bit –thus, the key for DES is                   effectively 56-bit long.
des



         Example: From the original 64-bit key
 K = 00010011 00110100 01010111 01111001 10011011 10111100 11011111 11110001
        we get the 56-bit permutation
         K+ = 1111000 0110011 0010101 0101111 0101010 1011001 1001111 0001111

         Next, split this key into left and right halves, C0 and D0, where each half has 28 bits.

Example: From the permuted key K+, we get
C0 = 1111000 0110011 0010101 0101111
D0 = 0101010 1011001 1001111 0001111

C1 = 1110000110011001010101011111
D1 = 1010101011001100111100011110
C2
= 1100001100110010101010111111
D2 = 0101010110011001111000111101
C3
= 0000110011001010101011111111
D3 = 0101011001100111100011110101
C4
= 0011001100101010101111111100
D4 = 0101100110011110001111010101
C5
= 1100110010101010111111110000
D5 = 0110011001111000111101010101
C6 = 0011001010101011111111000011
D6 = 1001100111100011110101010101
C7
= 1100101010101111111100001100
D7 = 0110011110001111010101010110
……

des

         We now form the keys Kn, for 1<=n<=16, by applying the following permutation table to each of the concatenated pairs CnDn. Each pair has 56 bits, but PC-2 only uses 48 of these .
         Example: For the first key we have C1D1 = 1110000 1100110 0101010 1011111 1010101 0110011 0011110 0011110
         which, after we apply the permutation PC-2, becomes
        K1 = 000110 110000 001011 101111 111111 000111 000001 110010 

Sub key generated:
         For the other keys we have

K2 = 011110 011010 111011 011001 110110 111100 100111 100101
K3 = 010101 011111 110010 001010 010000 101100 111110 011001
K4 = 011100 101010 110111 010110 110110 110011 010100 011101
K5 = 011111 001110 110000 000111 111010 110101 001110 101000
K6 = 011000 111010 010100 111110 010100 000111 101100 101111
K7 = 111011 001000 010010 110111 111101 100001 100010 111100
K8 = 111101 111000 101000 111010 110000 010011 101111 111011
K9 = 111000 001101 101111 101011 111011 011110 011110 000001
K10 = 101100 011111 001101 000111 101110 100100 011001 001111
K11 = 001000 010101 111111 010011 110111 101101 001110 000110
K12 = 011101 010111 000111 110101 100101 000110 011111 101001
K13 = 100101 111100 010111 010001 111110 101011 101001 000001
K14 = 010111 110100 001110 110111 111100 101110 011100 111010
K15 = 101111 111001 000110 001101 001111 010011 111100 001010
K16 = 110010 110011 110110 001011 000011 100001 011111 110101

Step 2: Encode each 64-bit block of data.
M = 0123456789ABCDEF
M = 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

There is an initial permutation IP of the 64 bits of the message data M. This rearranges the bits according to the following table
Example: Applying the initial permutation to the block of text M, given previously, we get
M = 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
IP = 1100 1100 0000 0000 1100 1100 1111 1111 1111 0000 1010 1010 1111 0000 1010 1010 


         Next divide the permuted block IP into a left half L0 of 32 bits, and a right half R0 of 32 bits.
         Example: From IP, we get L0 and R0
         L0 = 1100 1100 0000 0000 1100 1100 1111 1111
R0 = 1111 0000 1010 1010 1111 0000 1010 1010
         for 1<=n<=16, using a function f which operates on two blocks--a data block of 32 bits and a key Kn of 48 bits--to produce a block of 32 bits. Let + denote XOR addition, Then for n going from 1 to 16 we calculate
         Ln=Rn-1
Rn = Ln-1 
 f(Rn-1,Kn)
         Example: For n = 1, we have
        K1 = 000110 110000 001011 101111 111111 000111 000001 110010
L1 = R0 = 1111 0000 1010 1010 1111 0000 1010 1010
R1 = L0 
⊕ f(R0,K1)

         To calculate f, we first expand each block Rn-1 from 32 bits to 48 bits. This is done by using a selection table
         Example: We calculate E(R0) from R0 as follows:
         R0 = 1111 0000 1010 1010 1111 0000 1010 1010
E(R0) = 011110 100001 010101 010101 011110 100001 010101 010101
         Note that each block of 4 original bits has been expanded to a block of 6 output bits. 

         Next in the f calculation, we XOR the output E(Rn-1) with the key Kn:
         Kn + E(Rn-1).
         Example: For K1 , E(R0), we have
         K1 = 000110 110000 001011 101111 111111 000111 000001 110010
E(R0) = 011110 100001 010101 010101 011110 100001 010101 010101
K1+E(R0) = 011000 010001 011110 111010 100001 100110 010100 100111
         We have not yet finished calculating the function f . To this point we have expanded Rn-1 from 32 bits to 48 bits, using the selection table, and XORed the result with the key Kn . We now have 48 bits, or eight groups of six bits.
         with each group of six bits: we use them as addresses in tables called "S boxes"
         Write the previous result, which is 48 bits, in the form:
         Kn + E(Rn-1) =B1B2B3B4B5B6B7B8,
         where each Bi is a group of six bits. We now calculate
         S1(B1)S2(B2)S3(B3)S4(B4)S5(B5)S6(B6)S7(B7)S8(B8)

S-boxes:
         Example: consider the input 011001 to S-box S1ô€‚„
         The row is 011001:01(i.e. 1)ô€‚„
         The column is 011001: 1100 (i.e. 12)ô€‚„
         The value in the selected cell is 9ô€‚„Output is 1001
         Example: For the first round, we obtain as the output of the eight S boxes:
         K1 + E(R0) = 011000 010001 011110 111010 100001 100110 010100 100111.
         S1(B1)S2(B2)S3(B3)S4(B4)S5(B5)S6(B6)S7(B7)S8(B8) = 0101 1100 1000 0010 1011 0101 1001 0111 

         The final stage in the calculation of f is to do a permutation P of the S-box output to obtain the final value of f:
         f = P(S1(B1)S2(B2)...S8(B8))
         P yields a 32-bit output from a 32-bit input by permuting the bits of the input block
         Example: From the output of the eight S boxes:
         S1(B1)S2(B2)S3(B3)S4(B4)S5(B5)S6(B6)S7(B7)S8(B8) = 0101 1100 1000 0010 1011 0101 1001 0111 we get f = 0010 0011 0100 1010 1010 1001 1011 1011

         R1 = L0  f(R0 , K1 )= 1100 1100 0000 0000 1100 1100 1111 1111 
 0010 0011 0100 1010 1010 1001 1011 1011
= 1110 1111 0100 1010 0110 0101 0100 0100 

         We then reverse the order of the two blocks into the 64-bit block R16L16
         and apply a final permutation IP-1 as defined by the following table:
         Example: If we process all 16 blocks using the method defined previously, we get, on the 16th round,
         L16 = 0100 0011 0100 0010 0011 0010 0011 0100
R16 = 0000 1010 0100 1100 1101 1001 1001 0101
         We reverse the order of these two blocks and apply the final permutation to
         R16L16 = 00001010 01001100 11011001 10010101 01000011 01000010 00110010 00110100
         IP-1 = 10000101 11101000 00010011 01010100 00001111 00001010 10110100 00000101
         which in hexadecimal format is
        85E813540F0AB405.