-
Notifications
You must be signed in to change notification settings - Fork 4
/
分析.txt
357 lines (246 loc) · 11.5 KB
/
分析.txt
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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
------------------------------
密钥64位:133457799BBCDFF1
K(64位):
0001001 1(奇偶校验位)
0011010 0
0101011 1
0111100 1
1001101 1
1011110 0
1101111 1
1111000 1
明文64位 = 0123456789ABCDEF
M(64位):
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
L(32位) = 0000 0001 0010 0011 0100 0101 0110 0111
R(32位) = 1000 1001 1010 1011 1100 1101 1110 1111
------------------------
------------------------
求子钥K1--K6
K --> 置换得K+ --> 得C0,D0 --> 左移求C1D1--C16D16 --> 置换得K1--K16
求Ln Rn
Rn拓展置换(32->48)--> 结果异或Kn+1 --> 异或后结果进入S盒(48->32)-->
S盒输出进行P置换 --> 结果异或Ln --> 结果赋给Rn+1,Ln+1 = Rn -->得到L1R1--L16R16
生成密文
L1R1--L16R16 --> R1L1--R16L16 -->位置交换表置换得密文
DES的解密过程在原理上是与加密过程一样的,只有极少的地方不一样:
(1)如果加密的时候子密钥的使用顺序是K1,K2……K16,那么解密的时候子密钥 的使用顺序是K16,K15……K1;
(2)输入是64位密文,输出是64位明文;
(3)在生成密钥的时候加密算法是向左循环移动,但是解密算法是向右循环移动。
------------------------
-------------------------
57 % 7 = 1
57 /7 = 8
--------------------------
k+(8*7位) = 交换规则表1(K(8*7))
交换规则表1:8*7
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
C0(28位): 1111000 0110011 0010101 0101111
D0(28位): 0101010 1011001 1001111 0001111
--------------------------------------------
求Cn Dn
左移:
轮数: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
位数: 1 1 2 2 2 2 2 2 1 2 2 2 2 2 2 1
1位
C1: 1110000 1100110 0101010 101111 1
D1: 101010101100110011110001111 0
1位
C2: 110000110011001010101011111 1
D2: 010101011001100111100011110 1
2位:
c3: 00001100110010101010111111 11
D3: 01010110011001111000111101 01
2位:
c4: 00110011001010101011111111 00
D4: 01011001100111100011110101 01
2位:
c5: 11001100101010101111111100 00
D5: 01100110011110001111010101 01
2位:
c6: 00110010101010111111110000 11
D6: 10011001111000111101010101 01
2位:
c7: 11001010101011111111000011 00
D7: 01100111100011110101010101 10
2位:
c8: 00101010101111111100001100 11
D8: 10011110001111010101010110 01
1位:
c9: 010101010111111110000110011 0
D9: 001111000111101010101011001 1
2位:
c10: 01010101111111100001100110 01
D10: 11110001111010101010110011 00
2位:
c11: 01010111111110000110011001 01
D11: 11000111101010101011001100 11
2位:
c12: 01011111111000011001100101 01
D12: 00011110101010101100110011 11
2位:
c13: 01111111100001100110010101 01
D13: 01111010101010110011001111 00
2位:
c14: 11111110000110011001010101 01
D14: 11101010101011001100111100 01
2位:
c15: 11111000011001100101010101 11
D15: 10101010101100110011110001 11
1位:
c16: 111100001100110010101010111 1
D16: 010101010110011001111000111 1
-------------------------------------
求子钥Kn
Kn(8*6) = 交换规则表2(CnDn(8*7位)) CnDn 每7位一组,每组最后一位是奇偶校验位
交换规则表2(8*6):
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
---------------------
作者:m0_37962600
来源:CSDN
原文:https://blog.csdn.net/m0_37962600/article/details/79912654
版权声明:本文为博主原创文章,转载请附上博文链接!
48位
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
---------------------------------------------------------------
M(64位) = 0123456789ABCDEF
M(64位) = 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
s
L(32位) = 0000 0001 0010 0011 0100 0101 0110 0111
R(32位) = 1000 1001 1010 1011 1100 1101 1110 1111
IP = 交换规则表3(M)
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(64位) = 1100 1100 0000 0000 1100 1100 1111 1111 1111 0000 1010 1010 1111 0000 1010 1010
L0(32位) = 1100 1100 0000 0000 1100 1100 1111 1111
R0(32位) = 1111 0000 1010 1010 1111 0000 1010 1010;
------------------------------------------------------------------
------------------------------------------------------------------
求Ln Rn
Rn拓展置换(32->48)--> 结果异或Kn+1 --> 异或后结果进入S盒(48->32)-->
S盒输出进行P置换 --> 结果异或Ln --> 结果赋给Rn+1,Ln+1 = Rn -->得到L1R1--L16R16
-----------------------------------------------------------------
-----------------------------------------------------------------
Rn+(4*8) = 交换规则表E(Rn(6*8))
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
R0+ = 011110 100001 010101 010101 011110 100001 010101 010101
Rn+ 异或 Kn+1
R0+ 异或 K1 = 011000 010001 011110 111010 100001 100110 010100 100111
--------------------------------------------------------------------
进入S盒8个转换
int S1[] = {14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13};
int S2[] = {15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9};
int S3[] = {10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,
13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,
13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,
1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12};
int S4[] = { 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,
13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,
10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,
3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14};
int S5[] = { 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,
14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,
4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,
11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3};
int S6[] = {12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,
10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,
9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,
4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13};
int S7[] = { 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,
1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,
6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12};
int S8[] = {13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11};
将结果(48位)分为8组,每组对应相应的S盒;
每组中第一位和最后一位组成的二进制代表S盒行数,中间4位组成的数代表列数,对应相应的S盒中的十进制数,转换为4位二进制数
这样8组六位数变为8组4位数 32位
0101 1010 0111 1010 1111 1000 0110 0010
-----------------------------------------------
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
0111 0101 0101 1111 1000 0100 1100 0110
--------------------------------------------------
与L0异或
1011 1001 1010 0000 0100 1000 0011 1001
L0 R0
L1 = R0 R1 = 结果
----------------------
生成密文
L1R1--L16R16 --> R1L1--R16L16 -->位置交换表置换得密文
位置交换表
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;