After converting to 64-bit
representation, key is permuted according to the PC-1 table.
Idea of discussed permutation is following: the first value in the table equals
"57". It means that the 57th bit of the given key K is
the first bit of the permuted key K+. The 41st bit of the original
key becomes the 3rd bit of the permuted key and so on. This rule is applied to
any further permutation. It's important to notice that only 56 bits of the
original key remains in the newly created permuted key. As written before,
every 8th bit of each byte is ignored.
Given Key (in hex):
13 34 57 79 9B BC DF F1
Givenkey K:
00010011 00110100 01010111 01111001 10011011 10111100 11011111 11110001
PC-1:
57
|
49
|
41
|
33
|
25
|
17
|
9
|
1
|
58
|
50
|
42
|
34
|
26
|
18
|
10
|
2
|
59
|
51
|
43
|
35
|
27
|
19
|
11
|
3
|
60
|
52
|
44
|
36
|
63
|
55
|
47
|
39
|
31
|
23
|
15
|
7
|
62
|
54
|
46
|
38
|
30
|
22
|
14
|
6
|
61
|
53
|
45
|
37
|
29
|
21
|
13
|
5
|
28
|
20
|
12
|
4
|
K+:
1111000 0110011 0010101 0101111 0101010 1011001 1001111 0001111
Step 2: K+ splitting
The next step is
splitting K+ into halves: C0 and D0.
Each half has 28 bits.
K+:
1111000 0110011 0010101 0101111 0101010 1011001 1001111 0001111
C0:
1111000 0110011 0010101 0101111
D0:
0101010 1011001 1001111 0001111
Step
3: Creating 16 subkeys using shiftingNext we
create sixteen pairs Cn and Dn for
1<=n<=16. Every pair Cn, Dn is
created from the previous pairCn-1, Dn-1 for
1<=n<=16 through certain number of "left shifts" of the
previous block of bits. To perform a left shit we need to move each bit of a
block of data one place to the left. The first bit goes to the end of the
block. The left shifts schedule and all pairs Cn, Dn are
depicted in the following table:
Iteration
number
|
Number
of
shifts
|
Created
pairs
|
|
|
C0: 1111000011001100101010101111
D0: 0101010101100110011110001111
|
1
|
1
|
C1: 1110000110011001010101011111
D1: 1010101011001100111100011110
|
2
|
1
|
C2: 1100001100110010101010111111
D2: 0101010110011001111000111101
|
3
|
2
|
C3: 0000110011001010101011111111
D3: 0101011001100111100011110101
|
4
|
2
|
C4: 0011001100101010101111111100
D4: 0101100110011110001111010101
|
5
|
2
|
C5: 1100110010101010111111110000
D5: 0110011001111000111101010101
|
6
|
2
|
C6: 0011001010101011111111000011
D6: 1001100111100011110101010101
|
7
|
2
|
C7: 1100101010101111111100001100
D7: 0110011110001111010101010110
|
8
|
2
|
C8: 0010101010111111110000110011
D8: 1001111000111101010101011001
|
9
|
1
|
C9: 0101010101111111100001100110
D9: 0011110001111010101010110011
|
10
|
2
|
C10: 0101010111111110000110011001
D10: 1111000111101010101011001100
|
11
|
2
|
C11: 0101011111111000011001100101
D11: 1100011110101010101100110011
|
12
|
2
|
C12: 0101111111100001100110010101
D12: 0001111010101010110011001111
|
13
|
2
|
C13: 0111111110000110011001010101
D13: 0111101010101011001100111100
|
14
|
2
|
C14: 1111111000011001100101010101
D14: 1110101010101100110011110001
|
15
|
2
|
C15: 1111100001100110010101010111
D15: 1010101010110011001111000111
|
16
|
1
|
C16: 1111000011001100101010101111
D16: 0101010101100110011110001111
|
Step 4: PC-2 permutation
Before the final
permutation we need to merge each pair of data. After that each block of
bits CnDn for 1<=n<=16 is
permuted according to the PC-2 table forming the keys Kn.
Only 48 bits of each concatenated pair remain in the permuted key.
PC-2:
14
|
17
|
11
|
24
|
1
|
5
|
3
|
28
|
15
|
6
|
21
|
10
|
23
|
19
|
12
|
4
|
26
|
8
|
16
|
7
|
27
|
20
|
13
|
2
|
41
|
52
|
31
|
37
|
47
|
55
|
30
|
40
|
51
|
45
|
33
|
48
|
44
|
49
|
39
|
56
|
34
|
53
|
46
|
42
|
50
|
36
|
29
|
32
|
C1D1:
1110000 1100110 0101010 1011111 1010101 0110011 0011110 0011110
K1 setelah permutation:
000110 110000 001011 101111 111111 000111 000001 110010
Semuasubkeys:
K1: 000110 110000 001011 101111
111111 000111 000001 110010
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
|
Message Encoding
Step 1: IP permutation
Initial permutation IP of the plaintext M is the first step of message
encrypting stage. It permutes bits ofM according
to the IP table creating rearranged block of
bits IP.
Given message (in hex):
0123456789ABCDEF
Given message M:
00000001 00100011 01000101 01100111 10001001 10101011 11001101
11101111
IP:
58
|
50
|
42
|
34
|
26
|
18
|
10
|
2
|
60
|
52
|
44
|
36
|
28
|
20
|
12
|
4
|
62
|
54
|
46
|
38
|
30
|
22
|
14
|
6
|
64
|
56
|
48
|
40
|
32
|
24
|
16
|
8
|
57
|
49
|
41
|
33
|
25
|
17
|
9
|
1
|
59
|
51
|
43
|
35
|
27
|
19
|
11
|
3
|
61
|
53
|
45
|
37
|
29
|
21
|
13
|
5
|
63
|
55
|
47
|
39
|
31
|
23
|
15
|
7
|
IP:
11001100 00000000 11001100 11111111 11110000 10101010 11110000 10101010
Step 2: IP splitting
The next step is
splitting IP into halves: L0 and R0.
Both halves have 32 bits.
IP:
11001100 00000000 11001100 11111111 11110000 10101010 11110000 10101010
L0:
11001100 00000000 11001100 11111111
R0:
11110000 10101010 11110000 10101010
Part 3: Iterations
Next step is 16 iterations.
For 1<=n<=16 we calculate:
Ln = Rn-1
Rn = Ln-1
f(Rn-1,Kn)
Function f operates on two
blocks of data: Rn-1 and Kn.
It produces 32-bit long block of data. Process of calculating f function
consists of 4 steps:
1. E permutation
2. XOR with a subkey
3. S box transformation
4. P permutation
f function executing - E
permutation
Let's start the first
iteration! In the beginning we expand block Rn-1 from
32 to 48 bits. It is made by permuting the input block according to the E table.
In this operation some of bits are repeated. Output block is marked E(R0).
R0:
1111 0000 1010 1010 1111 0000 1010 1010
E:
32
|
1
|
2
|
3
|
4
|
5
|
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
|
1
|
| | |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
E(R0):
011110 100001 010101 010101 011110 100001 010101 010101
f function executing - XOR
with the key
In this step we XOR E(Rn-1) with
the key Kn. In the first iteration it is K1
E(R0).
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
f function executing - S
box transformation
On this stage we have
48-bit long block of data to work with. We can present this also as eight
groups of six bits. The groups of six are used now as addresses in tables
called "S boxes". At the specific location is placed a 4-bit
number
S1:
|
|
0
|
1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
9
|
10
|
11
|
12
|
13
|
14
|
15
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0
|
|
14
|
4
|
13
|
1
|
2
|
15
|
11
|
8
|
3
|
10
|
6
|
12
|
5
|
9
|
0
|
7
|
1
|
|
0
|
15
|
7
|
4
|
14
|
2
|
13
|
1
|
10
|
6
|
12
|
11
|
9
|
5
|
3
|
8
|
2
|
|
4
|
1
|
14
|
8
|
13
|
6
|
2
|
11
|
15
|
12
|
9
|
7
|
3
|
10
|
5
|
0
|
3
|
|
15
|
12
|
8
|
2
|
4
|
9
|
1
|
7
|
5
|
11
|
3
|
14
|
10
|
0
|
6
|
13
|
S2:
|
|
0
|
1
|
2
|
3
|
4
|
5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
8
|
13
|
3
|
12
|
9
|
7
|
5
|
10
|
6
|
1
|
1
|
|
13
|
0
|
11
|
7
|
4
|
9
|
1
|
10
|
14
|
3
|
5
|
12
|
2
|
15
|
8
|
6
|
2
|
|
1
|
4
|
11
|
13
|
12
|
3
|
7
|
14
|
10
|
15
|
6
|
8
|
0
|
5
|
9
|
2
|
3
|
|
6
|
11
|
13
|
8
|
1
|
4
|
10
|
7
|
9
|
5
|
0
|
15
|
14
|
2
|
3
|
12
|
S8:
|
|
0
|
1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
9
|
10
|
11
|
12
|
13
|
14
|
15
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0
|
|
13
|
2
|
8
|
4
|
6
|
15
|
11
|
1
|
10
|
9
|
3
|
14
|
5
|
0
|
12
|
7
|
1
|
|
1
|
15
|
13
|
8
|
10
|
3
|
7
|
4
|
12
|
5
|
6
|
11
|
0
|
14
|
9
|
2
|
2
|
|
7
|
11
|
4
|
1
|
9
|
12
|
14
|
2
|
0
|
6
|
10
|
13
|
15
|
3
|
5
|
8
|
3
|
|
2
|
1
|
14
|
7
|
4
|
10
|
8
|
13
|
15
|
12
|
9
|
0
|
3
|
5
|
6
|
11
|
K1
E(R0)
= B1B2B3B4B5B6B7B8:
011000010001011110111010100001100110010100100111
S(B1)S(B2)S(B3)S(B4)S(B5)S(B6)S(B7)S(B8):
0101 1100 1000 0010 1011 0101 1001 0111
f function executing - P
permutation
The final step in f
function calculating is P permutation.
S(B1)S(B2)S(B3)S(B4)S(B5)S(B6)S(B7)S(B8):
0101 1100 1000 0010 1011 0101 1001 0111
P:
16
|
7
|
20
|
21
|
29
|
12
|
28
|
17
|
1
|
15
|
23
|
26
|
5
|
18
|
31
|
10
|
2
|
8
|
24
|
14
|
32
|
27
|
3
|
9
|
19
|
13
|
30
|
6
|
22
|
11
|
4
|
25
|
f = P[S(B1)S(B2)S(B3)S(B4)S(B5)S(B6)S(B7)S(B8)]:
0010 0011 0100 1010 1010
1001 1011 1011
The final result of the first iteration:
L0:
1100 1100 0000 0000 1100 1100 1111 1111
f(R0,K1):
0010 0011 0100 1010 1010 1001 1011 1011
R1 = L0
f(R0,K1):
1110 1111 0100 1010 0110
0101 0100 0100
and
L1 = R0:
1111 0000 1010 1010 1111
0000 1010 1010
After 16 iterations we
get L16 and R16:
L1:
1111 0000 1010 1010 1111 0000 1010 1010
R1:
1110 1111 0100 1010 0110 0101 0100 0100
L16:
0100 0011 0100 0010 0011 0010 0011 0100
R16:
0000 1010 0100 1100 1101 1001 1001 0101
Step 4: Reverse connecting
Next we reverse order of
the two blocks and merge them.
L16:
0100 0011 0100 0010 0011 0010 0011 0100
R16:
0000 1010 0100 1100 1101 1001 1001 0101
R16L16:
00001010 01001100 11011001 10010101 01000011 01000010 00110010 00110100
Step 5: IP-1 permutation
After the last step in
message encrypting, which is IP-1 permutation, we
obtain the output.
R16L16:
00001010 01001100 11011001 10010101 01000011 01000010 00110010 00110100
IP-1:
40
|
8
|
48
|
16
|
56
|
24
|
64
|
32
|
39
|
7
|
47
|
15
|
55
|
23
|
63
|
31
|
38
|
6
|
46
|
14
|
54
|
22
|
62
|
30
|
37
|
5
|
45
|
13
|
53
|
21
|
61
|
29
|
36
|
4
|
44
|
12
|
52
|
20
|
60
|
28
|
35
|
3
|
43
|
11
|
51
|
19
|
59
|
27
|
34
|
2
|
42
|
10
|
50
|
18
|
58
|
26
|
33
|
1
|
41
|
9
|
49
|
17
|
57
|
25
|
IP-1:
10000101 11101000 00010011 01010100 00001111 00001010 10110100 00000101
Output:
85E813540F0AB405
Decrypting process
Decoding algorithm is almost the same as
encoding. The only action we need to do is to reverse order during applying
subkeys. The last subkey becomes the first one, the last but one becomes the
second one and so on.
Given message:
0123456789ABCDEF
Given key:
133457799BBCDFF1
Output:
EE0F7C12E0B09338