Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 7

Assignment # 3

Subject: Cryptography

Topic: DES

Submitted to: Dr. Aqeel-ur-Rehman

Submitted by: M. Faiqe


SP18-BCS-096

Dated: 09-12-2021

Comsats University Islamabad,


Vehari Campus.

Plaintext: ayyaz114
Key: REHMAN1

Plaintext f a i q e 0 9 6
ascii 102 97 105 113 102 48 57 54
Binary 01100110 01100001 01101001 01110001 0110101 00110000 00111000 00110110

Initial Permutation:

Initial Permutation Table


53 50 42 34 26 18 10 02
60 52 44 36 28 20 12 04
62 54 46 38 30 22 14 06
64 56 48 40 32 24 16 08
57 49 41 33 25 17 09 01
59 51 43 35 27 19 11 03
61 53 45 37 29 21 13 05
63 55 47 39 31 23 15 07

Initially Permuted Plaintext values 8-bit sets


1 1 1 1 1 1 1 1 00011111
0 0 0 0 0 0 0 0 11111101
1 0 1 0 0 0 1 0 10000000
0 1 1 0 1 1 0 1 01101111
0 0 0 0 0 0 0 0 00000000
1 1 1 1 1 1 1 1 11111111
0 0 1 1 0 1 1 0 00010110
0 0 0 0 0 0 0 0 00010001

Permuted 64-bit divided into Left(LI-1) 32-bits & Right(RI-1) 32-bits


Left 32-bits 00011111 11101000 10010000 01001110
Right 32-bits 00000000 11111111 01010100 10010001

Permuted Right(RI-1) 32-bits


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 1 0 1 1 0 0 0 0 1 0 0 0 0

f (RI-1, K1):

Expansion D-Box Table


32 01 02 03 04 05
4 5 6 7 8 9
8 9 10 11 12 13
12 13 14 15 16 17
16 17 18 19 20 21
20 21 22 23 24 25
24 25 26 27 28 29
28 29 30 31 32 01

Expanded Right(RI-1) 32-bits using Expansion D-Box 6-bit sets


1 0 0 0 0 0 100000
0 0 0 0 0 1 000001
0 1 1 1 1 1 011111
1 0 1 0 1 0 111110
1 0 1 0 0 1 100010
0 1 0 0 0 1 101100
0 0 0 0 1 0 000010
1 0 0 0 1 0 100000

Key Generation:

Key R E H M A N 1
ascii 52 45 48 4D 41 4E 31
Binary 01010010 01000101 01001000 01001101 01000001 01001110 00110001

56-bit Key divided into Left 28-bits & Right 28-bits


Left 28-bits 01010010 01000101 01001000 0100
Right 28-bits 11010100 00010100 11100011 0001

Circular Left Shift to Left 28-bits & Right 28-bits


Left 28-bits 10100100 10001010 10010000 1000
Right 28-bits 10101000 00101001 11000110 0011
Left 28-bits of Key after Circular Left Shift
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
1 0 1 0 0 1 0 0 1 0 0 0 1 0 1 0 1 0 0 1 0 0 0 0 1 0 0 0

Right 28-bits of Key after Circular Left Shift


29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
1 0 1 0 1 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 0 1 1 0 0 0 1 1

Key-compression Table
14 17 11 24 01 05 03 28
15 06 21 10 23 19 12 04
26 08 16 07 27 20 13 02
41 52 31 37 47 55 30 40
51 45 33 48 44 49 39 56
34 53 46 42 50 36 29 32

Passing the both Circular Left Shifted Right & Left bits through the Key Compression Table:

Compressed 48-bit Key value using Key-compression Table 8-bit sets


0 1 0 0 1 0 1 0 01001010
1 1 0 0 0 0 0 0 11000000
0 0 0 0 0 1 1 0 00000110
1 0 1 0 0 1 0 0 10100100
1 1 1 0 1 0 1 1 11101011
0 0 1 0 1 0 1 0 00101010

Dividing the above 8-bit sets in 6-bit sets for convenience during XOR:

48-bit Key divided into 6-bit sets


000000 000000 011001 001111
111000 010100 010100 010001

XOR of the Expansion D-box output and compressed Key:

Expansion D-box output Key Compression Output XOR


000010 010010 010010
011101 101100 101101
011111 000000 011111
001111 000110 111000
100010 101001 001011
101100 001110 100010
010000 101100 111100
100000 101010 001010

Now passing each of these outputs to the corresponding S-box:

S-box Value to pass Row Column Output


S-box 1 000000 0 9 10 = 1110
S-box 2 000000 3 6 4 = 1111
S-box 3 011001 1 15 1 = 1100
S-box 4 001111 2 12 5 = 0011
S-box 5 111000 1 5 7 = 0110
S-box 6 010100 2 1 14 = 0110
S-box 7 010100 2 7 14 = 1110
S-box 8 110001 0 5 16 = 1101

Output of all S-boxes


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
1 01 0 0 1 0 0 0 0 0 1 0 1 0 1 0 1 1 1 1 1 1 0 1 1 1 0 1 1 1 1

Straight Permutation Table


16 07 20 21 29 12 28 17
01 15 23 26 05 18 31 10
02 08 24 14 32 27 03 09
19 13 30 06 22 11 04 25

Passing Output of all S-boxes to Straight Permutation Table / Straight D-box:

Straight Permutation Table / Straight D-box Output f (RI-1, K1)


1 0 1 1 1 1 0 0 10111100
1 0 1 1 0 1 1 0 10110110
0 0 0 1 1 1 1 0 00011110
1 0 1 1 1 0 0 1 10011001

Permuted Left(LI-1) 32-bits


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
0 0 0 1 1 1 1 1 1 1 1 1 0 1 1 0 1 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1

Mixer:

f (RI-1, K1) Permuted Left(LI-1) 32-bits XOR = Mixer Output


10111100 00011111 10100001
10110110 11110110 01000000
10111000 00010001 10011110
00011001 01101111 11010110

Swapper (swaps the original Right 32-bits with the Mixer output):

LI (32-bits) Mixer Output Original RI (32-bits)


10100011 01000000 10011110 11010110 00000000 11111111 00010110 00010000

LI (32-bits) [Original RI] RI (32-bits) [Mixer Output]


00000000 11111111 00010110 00010000 10100011 01000000 10011110 11010110

Now performing the Final Permutation:

Final Permutation Table


40 08 48 16 56 24 64 32
39 07 47 15 55 23 63 31
38 06 46 14 54 22 62 30
37 05 45 13 53 21 61 29
36 04 44 12 52 20 60 28
35 03 43 11 51 19 59 27
34 02 42 10 50 18 58 26
33 01 41 09 49 17 57 25

Left 32-bits of Round-1 Output


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 1 0 1 1 0 0 0 0 1 0 0 0 0

Right 32-bits of Round-1 Output


33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
1 0 1 0 0 0 1 1 0 1 0 0 0 0 0 0 1 0 0 1 1 1 1 0 1 1 0 1 0 1 1 0

Finally Permuted values 8-bit sets


1 0 0 1 0 0 0 0 10111001
1 0 0 1 1 1 1 0 00010010
0 0 0 1 1 1 1 0 00010010
0 0 0 1 1 0 0 0 00011000
0 0 0 1 1 1 1 1 10010010
1 0 1 1 0 0 0 0 00111010
0 0 1 1 0 0 1 0 00110010
1 0 0 1 1 0 1 0 10011001

Binary 10010000 10011110 00011110 00011000 00011111 10010000 00110010 10011010


ascii 90 9E 1E 18 1F 90 32 9A
Cipher- Record Unit
É × Cancel É 2 Ü
text separator Separator

You might also like