In the DES algorithm and its implementation in the vc++6.0 (above), the main introduction of the DES algorithm basic principles, let us continue:
Two Generation of child keys
A 64-bit key generates 16 48-bit sub keys. The build process is shown in figure:
The child key generation process is explained in detail as follows:
64-bit key K, after PC-1, generate a 56-bit string. The subscript is as shown in the table:
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 |
21st |
13 |
5 |
28 |
20 |
12 |
4 |
The bit string is divided into equal length C0 and D0. Then the C0 and D0 were cycled to the left 1-bit respectively to get C1 and D1. C1 and D1 combine to generate C1D1. After PC-2 transformation, the C1D1 generates a 48-bit K1. The subscript list for K1 is:
PC-2 |
14 |
17 |
11 |
24 |
1 |
5 |
3 |
28 |
15 |
6 |
21st |
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 |
C1, D1 respectively cycle left LS2 bit, and then merged, after PC-2, the generation of sub-key K2 ... And so on until the child key K16 is generated.
Note: The number of Lsi (I =1,2,.... 16) is different. See the following table in detail:
Iteration Order |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
Left shift number |
1 |
1 |
2 |
2 |
2 |
2 |
2 |
2 |
1 |
2 |
2 |
2 |
2 |
2 |
2 |
1 |
The VC program source code to generate the sub key is as follows:
for(i=1;i<57;i++)//输入64位K,经过PC-1变为56位 k0[i]=k[PC_1[i-1]];
The 56-bit K0 are divided into 28-bit c0,d0. C0,D0 generates K1 and C1,D1. The following iteration methods are the same, with the example of generating K8 only.for(i=1;i<27;i++)//循环左移两位
{
C8[i]=C7[i+2];
D8[i]=D7[i+2];
}
C8[27]=C7[1];
D8[27]=D7[1];
C8[28]=C7[2];
D8[28]=D7[2];
for(i=1;i<=28;i++)
{
C[i]=C8[i];
C[i+28]=D8[i];
}
for(i=1;i<=48;i++)
K8[i]=C[PC_2[i-1]];//生成子密钥k8
Note: The generated subkey is different, and the number of digits to the left of the desired loop is different. In the source program, take the K8 key as an example, so the loop moves two bits to the left. However, in programming, the generation of different sub keys should be based on the LSI table.