-
Notifications
You must be signed in to change notification settings - Fork 3
/
DES.cpp
409 lines (387 loc) · 18.8 KB
/
DES.cpp
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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
// IP, FP´Â Á¦°Å
#include "DES.h"
const int SBOX[8][64] = {
{ 14, 0, 4, 15, 13, 7, 1, 4, 2, 14, 15, 2, 11, 13, 8, 1, 3, 10, 10, 6, 6, 12, 12, 11, 5, 9, 9, 5, 0, 3, 7, 8, 4, 15, 1, 12, 14, 8, 8, 2, 13, 4, 6, 9, 2, 1, 11, 7, 15, 5, 12, 11, 9, 3, 7, 14, 3, 10, 10, 0, 5, 6, 0, 13, },
{ 15, 3, 1, 13, 8, 4, 14, 7, 6, 15, 11, 2, 3, 8, 4, 14, 9, 12, 7, 0, 2, 1, 13, 10, 12, 6, 0, 9, 5, 11, 10, 5, 0, 13, 14, 8, 7, 10, 11, 1, 10, 3, 4, 15, 13, 4, 1, 2, 5, 11, 8, 6, 12, 7, 6, 12, 9, 0, 3, 5, 2, 14, 15, 9, },
{ 10, 13, 0, 7, 9, 0, 14, 9, 6, 3, 3, 4, 15, 6, 5, 10, 1, 2, 13, 8, 12, 5, 7, 14, 11, 12, 4, 11, 2, 15, 8, 1, 13, 1, 6, 10, 4, 13, 9, 0, 8, 6, 15, 9, 3, 8, 0, 7, 11, 4, 1, 15, 2, 14, 12, 3, 5, 11, 10, 5, 14, 2, 7, 12, },
{ 7, 13, 13, 8, 14, 11, 3, 5, 0, 6, 6, 15, 9, 0, 10, 3, 1, 4, 2, 7, 8, 2, 5, 12, 11, 1, 12, 10, 4, 14, 15, 9, 10, 3, 6, 15, 9, 0, 0, 6, 12, 10, 11, 1, 7, 13, 13, 8, 15, 9, 1, 4, 3, 5, 14, 11, 5, 12, 2, 7, 8, 2, 4, 14, },
{ 2, 14, 12, 11, 4, 2, 1, 12, 7, 4, 10, 7, 11, 13, 6, 1, 8, 5, 5, 0, 3, 15, 15, 10, 13, 3, 0, 9, 14, 8, 9, 6, 4, 11, 2, 8, 1, 12, 11, 7, 10, 1, 13, 14, 7, 2, 8, 13, 15, 6, 9, 15, 12, 0, 5, 9, 6, 10, 3, 4, 0, 5, 14, 3, },
{ 12, 10, 1, 15, 10, 4, 15, 2, 9, 7, 2, 12, 6, 9, 8, 5, 0, 6, 13, 1, 3, 13, 4, 14, 14, 0, 7, 11, 5, 3, 11, 8, 9, 4, 14, 3, 15, 2, 5, 12, 2, 9, 8, 5, 12, 15, 3, 10, 7, 11, 0, 14, 4, 1, 10, 7, 1, 6, 13, 0, 11, 8, 6, 13, },
{ 4, 13, 11, 0, 2, 11, 14, 7, 15, 4, 0, 9, 8, 1, 13, 10, 3, 14, 12, 3, 9, 5, 7, 12, 5, 2, 10, 15, 6, 8, 1, 6, 1, 6, 4, 11, 11, 13, 13, 8, 12, 1, 3, 4, 7, 10, 14, 7, 10, 9, 15, 5, 6, 0, 8, 15, 0, 14, 5, 2, 9, 3, 2, 12, },
{ 13, 1, 2, 15, 8, 13, 4, 8, 6, 10, 15, 3, 11, 7, 1, 4, 10, 12, 9, 5, 3, 6, 14, 11, 5, 0, 0, 14, 12, 9, 7, 2, 7, 2, 11, 1, 4, 14, 1, 7, 9, 4, 12, 10, 14, 8, 2, 13, 0, 15, 6, 12, 10, 9, 13, 0, 15, 3, 3, 5, 5, 6, 8, 11, } };
static int keysh[] =
{
1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1,
};
const unsigned int SB1[64] = { 0x00808200,0x00000000,0x00008000,0x00808202,0x00808002,0x00008202,0x00000002,0x00008000,
0x00000200,0x00808200,0x00808202,0x00000200,0x00800202,0x00808002,0x00800000,0x00000002,
0x00000202,0x00800200,0x00800200,0x00008200,0x00008200,0x00808000,0x00808000,0x00800202,
0x00008002,0x00800002,0x00800002,0x00008002,0x00000000,0x00000202,0x00008202,0x00800000,
0x00008000,0x00808202,0x00000002,0x00808000,0x00808200,0x00800000,0x00800000,0x00000200,
0x00808002,0x00008000,0x00008200,0x00800002,0x00000200,0x00000002,0x00800202,0x00008202,
0x00808202,0x00008002,0x00808000,0x00800202,0x00800002,0x00000202,0x00008202,0x00808200,
0x00000202,0x00800200,0x00800200,0x00000000,0x00008002,0x00008200,0x00000000,0x00808002 };
const unsigned int SB2[64] = { 0x40084010,0x40004000,0x00004000,0x00084010,0x00080000,0x00000010,0x40080010,0x40004010,
0x40000010,0x40084010,0x40084000,0x40000000,0x40004000,0x00080000,0x00000010,0x40080010,
0x00084000,0x00080010,0x40004010,0x00000000,0x40000000,0x00004000,0x00084010,0x40080000,
0x00080010,0x40000010,0x00000000,0x00084000,0x00004010,0x40084000,0x40080000,0x00004010,
0x00000000,0x00084010,0x40080010,0x00080000,0x40004010,0x40080000,0x40084000,0x00004000,
0x40080000,0x40004000,0x00000010,0x40084010,0x00084010,0x00000010,0x00004000,0x40000000,
0x00004010,0x40084000,0x00080000,0x40000010,0x00080010,0x40004010,0x40000010,0x00080010,
0x00084000,0x00000000,0x40004000,0x00004010,0x40000000,0x40080010,0x40084010,0x00084000 };
const unsigned int SB3[64] = { 0x00000104,0x04010100,0x00000000,0x04010004,0x04000100,0x00000000,0x00010104,0x04000100,
0x00010004,0x04000004,0x04000004,0x00010000,0x04010104,0x00010004,0x04010000,0x00000104,
0x04000000,0x00000004,0x04010100,0x00000100,0x00010100,0x04010000,0x04010004,0x00010104,
0x04000104,0x00010100,0x00010000,0x04000104,0x00000004,0x04010104,0x00000100,0x04000000,
0x04010100,0x04000000,0x00010004,0x00000104,0x00010000,0x04010100,0x04000100,0x00000000,
0x00000100,0x00010004,0x04010104,0x04000100,0x04000004,0x00000100,0x00000000,0x04010004,
0x04000104,0x00010000,0x04000000,0x04010104,0x00000004,0x00010104,0x00010100,0x04000004,
0x04010000,0x04000104,0x00000104,0x04010000,0x00010104,0x00000004,0x04010004,0x00010100 };
const unsigned int SB4[64] = { 0x80401000,0x80001040,0x80001040,0x00000040,0x00401040,0x80400040,0x80400000,0x80001000,
0x00000000,0x00401000,0x00401000,0x80401040,0x80000040,0x00000000,0x00400040,0x80400000,
0x80000000,0x00001000,0x00400000,0x80401000,0x00000040,0x00400000,0x80001000,0x00001040,
0x80400040,0x80000000,0x00001040,0x00400040,0x00001000,0x00401040,0x80401040,0x80000040,
0x00400040,0x80400000,0x00401000,0x80401040,0x80000040,0x00000000,0x00000000,0x00401000,
0x00001040,0x00400040,0x80400040,0x80000000,0x80401000,0x80001040,0x80001040,0x00000040,
0x80401040,0x80000040,0x80000000,0x00001000,0x80400000,0x80001000,0x00401040,0x80400040,
0x80001000,0x00001040,0x00400000,0x80401000,0x00000040,0x00400000,0x00001000,0x00401040 };
const unsigned int SB5[64] = { 0x00000080,0x01040080,0x01040000,0x21000080,0x00040000,0x00000080,0x20000000,0x01040000,
0x20040080,0x00040000,0x01000080,0x20040080,0x21000080,0x21040000,0x00040080,0x20000000,
0x01000000,0x20040000,0x20040000,0x00000000,0x20000080,0x21040080,0x21040080,0x01000080,
0x21040000,0x20000080,0x00000000,0x21000000,0x01040080,0x01000000,0x21000000,0x00040080,
0x00040000,0x21000080,0x00000080,0x01000000,0x20000000,0x01040000,0x21000080,0x20040080,
0x01000080,0x20000000,0x21040000,0x01040080,0x20040080,0x00000080,0x01000000,0x21040000,
0x21040080,0x00040080,0x21000000,0x21040080,0x01040000,0x00000000,0x20040000,0x21000000,
0x00040080,0x01000080,0x20000080,0x00040000,0x00000000,0x20040000,0x01040080,0x20000080 };
const unsigned int SB6[64] = { 0x10000008,0x10200000,0x00002000,0x10202008,0x10200000,0x00000008,0x10202008,0x00200000,
0x10002000,0x00202008,0x00200000,0x10000008,0x00200008,0x10002000,0x10000000,0x00002008,
0x00000000,0x00200008,0x10002008,0x00002000,0x00202000,0x10002008,0x00000008,0x10200008,
0x10200008,0x00000000,0x00202008,0x10202000,0x00002008,0x00202000,0x10202000,0x10000000,
0x10002000,0x00000008,0x10200008,0x00202000,0x10202008,0x00200000,0x00002008,0x10000008,
0x00200000,0x10002000,0x10000000,0x00002008,0x10000008,0x10202008,0x00202000,0x10200000,
0x00202008,0x10202000,0x00000000,0x10200008,0x00000008,0x00002000,0x10200000,0x00202008,
0x00002000,0x00200008,0x10002008,0x00000000,0x10202000,0x10000000,0x00200008,0x10002008 };
const unsigned int SB7[64] = { 0x00100000,0x02100001,0x02000401,0x00000000,0x00000400,0x02000401,0x00100401,0x02100400,
0x02100401,0x00100000,0x00000000,0x02000001,0x00000001,0x02000000,0x02100001,0x00000401,
0x02000400,0x00100401,0x00100001,0x02000400,0x02000001,0x02100000,0x02100400,0x00100001,
0x02100000,0x00000400,0x00000401,0x02100401,0x00100400,0x00000001,0x02000000,0x00100400,
0x02000000,0x00100400,0x00100000,0x02000401,0x02000401,0x02100001,0x02100001,0x00000001,
0x00100001,0x02000000,0x02000400,0x00100000,0x02100400,0x00000401,0x00100401,0x02100400,
0x00000401,0x02000001,0x02100401,0x02100000,0x00100400,0x00000000,0x00000001,0x02100401,
0x00000000,0x00100401,0x02100000,0x00000400,0x02000001,0x02000400,0x00000400,0x00100001 };
const unsigned int SB8[64] = { 0x08000820,0x00000800,0x00020000,0x08020820,0x08000000,0x08000820,0x00000020,0x08000000,
0x00020020,0x08020000,0x08020820,0x00020800,0x08020800,0x00020820,0x00000800,0x00000020,
0x08020000,0x08000020,0x08000800,0x00000820,0x00020800,0x00020020,0x08020020,0x08020800,
0x00000820,0x00000000,0x00000000,0x08020020,0x08000020,0x08000800,0x00020820,0x00020000,
0x00020820,0x00020000,0x08020800,0x00000800,0x00000020,0x08020020,0x00000800,0x00020820,
0x08000800,0x00000020,0x08000020,0x08020000,0x08020020,0x08000000,0x00020000,0x08000820,
0x00000000,0x08020820,0x00020020,0x08000020,0x08020000,0x08000800,0x08000820,0x00000000,
0x08020820,0x00020800,0x00020800,0x00000820,0x00000820,0x00020020,0x08000000,0x08020800 };
static unsigned int comptab[] = {
0x000000,0x010000,0x000008,0x010008,0x000080,0x010080,0x000088,0x010088,
0x000000,0x010000,0x000008,0x010008,0x000080,0x010080,0x000088,0x010088,
0x000000,0x100000,0x000800,0x100800,0x000000,0x100000,0x000800,0x100800,
0x002000,0x102000,0x002800,0x102800,0x002000,0x102000,0x002800,0x102800,
0x000000,0x000004,0x000400,0x000404,0x000000,0x000004,0x000400,0x000404,
0x400000,0x400004,0x400400,0x400404,0x400000,0x400004,0x400400,0x400404,
0x000000,0x000020,0x008000,0x008020,0x800000,0x800020,0x808000,0x808020,
0x000002,0x000022,0x008002,0x008022,0x800002,0x800022,0x808002,0x808022,
0x000000,0x000200,0x200000,0x200200,0x001000,0x001200,0x201000,0x201200,
0x000000,0x000200,0x200000,0x200200,0x001000,0x001200,0x201000,0x201200,
0x000000,0x000040,0x000010,0x000050,0x004000,0x004040,0x004010,0x004050,
0x040000,0x040040,0x040010,0x040050,0x044000,0x044040,0x044010,0x044050,
0x000000,0x000100,0x020000,0x020100,0x000001,0x000101,0x020001,0x020101,
0x080000,0x080100,0x0a0000,0x0a0100,0x080001,0x080101,0x0a0001,0x0a0101,
0x000000,0x000100,0x040000,0x040100,0x000000,0x000100,0x040000,0x040100,
0x000040,0x000140,0x040040,0x040140,0x000040,0x000140,0x040040,0x040140,
0x000000,0x400000,0x008000,0x408000,0x000008,0x400008,0x008008,0x408008,
0x000400,0x400400,0x008400,0x408400,0x000408,0x400408,0x008408,0x408408,
0x000000,0x001000,0x080000,0x081000,0x000020,0x001020,0x080020,0x081020,
0x004000,0x005000,0x084000,0x085000,0x004020,0x005020,0x084020,0x085020,
0x000000,0x000800,0x000000,0x000800,0x000010,0x000810,0x000010,0x000810,
0x800000,0x800800,0x800000,0x800800,0x800010,0x800810,0x800010,0x800810,
0x000000,0x010000,0x000200,0x010200,0x000000,0x010000,0x000200,0x010200,
0x100000,0x110000,0x100200,0x110200,0x100000,0x110000,0x100200,0x110200,
0x000000,0x000004,0x000000,0x000004,0x000080,0x000084,0x000080,0x000084,
0x002000,0x002004,0x002000,0x002004,0x002080,0x002084,0x002080,0x002084,
0x000000,0x000001,0x200000,0x200001,0x020000,0x020001,0x220000,0x220001,
0x000002,0x000003,0x200002,0x200003,0x020002,0x020003,0x220002,0x220003,
};
static void
keycompperm(unsigned int left, unsigned int right, unsigned int *ek)
{
unsigned int v0, v1;
int i;
for (i = 0; i < 16; i++) {
left = (left << keysh[i]) | (left >> (28 - keysh[i]));
left &= 0xfffffff0;
right = (right << keysh[i]) | (right >> (28 - keysh[i]));
right &= 0xfffffff0;
v0 = comptab[6 * (1 << 4) + ((left >> (32 - 4)) & 0xf)]
| comptab[5 * (1 << 4) + ((left >> (32 - 8)) & 0xf)]
| comptab[4 * (1 << 4) + ((left >> (32 - 12)) & 0xf)]
| comptab[3 * (1 << 4) + ((left >> (32 - 16)) & 0xf)]
| comptab[2 * (1 << 4) + ((left >> (32 - 20)) & 0xf)]
| comptab[1 * (1 << 4) + ((left >> (32 - 24)) & 0xf)]
| comptab[0 * (1 << 4) + ((left >> (32 - 28)) & 0xf)];
v1 = comptab[13 * (1 << 4) + ((right >> (32 - 4)) & 0xf)]
| comptab[12 * (1 << 4) + ((right >> (32 - 8)) & 0xf)]
| comptab[11 * (1 << 4) + ((right >> (32 - 12)) & 0xf)]
| comptab[10 * (1 << 4) + ((right >> (32 - 16)) & 0xf)]
| comptab[9 * (1 << 4) + ((right >> (32 - 20)) & 0xf)]
| comptab[8 * (1 << 4) + ((right >> (32 - 24)) & 0xf)]
| comptab[7 * (1 << 4) + ((right >> (32 - 28)) & 0xf)];
ek[0] = (((v0 >> (24 - 6)) & 0x3f) << 26)
| (((v0 >> (24 - 18)) & 0x3f) << 18)
| (((v1 >> (24 - 6)) & 0x3f) << 10)
| (((v1 >> (24 - 18)) & 0x3f) << 2);
ek[1] = (((v0 >> (24 - 12)) & 0x3f) << 26)
| (((v0 >> (24 - 24)) & 0x3f) << 18)
| (((v1 >> (24 - 12)) & 0x3f) << 10)
| (((v1 >> (24 - 24)) & 0x3f) << 2);
ek += 2;
}
}
void des_key_setup(byte key[8], unsigned int *ek)
{
unsigned int left, right, v0, v1;
v0 = key[0] | ((unsigned int)key[2] << 8) | ((unsigned int)key[4] << 16) | ((unsigned int)key[6] << 24);
v1 = key[1] | ((unsigned int)key[3] << 8) | ((unsigned int)key[5] << 16) | ((unsigned int)key[7] << 24);
left = ((v0 >> 1) & 0x40404040)
| ((v0 >> 2) & 0x10101010)
| ((v0 >> 3) & 0x04040404)
| ((v0 >> 4) & 0x01010101)
| ((v1 >> 0) & 0x80808080)
| ((v1 >> 1) & 0x20202020)
| ((v1 >> 2) & 0x08080808)
| ((v1 >> 3) & 0x02020202);
right = ((v0 >> 1) & 0x04040404)
| ((v0 << 2) & 0x10101010)
| ((v0 << 5) & 0x40404040)
| ((v1 << 0) & 0x08080808)
| ((v1 << 3) & 0x20202020)
| ((v1 << 6) & 0x80808080);
left = ((left << 6) & 0x33003300)
| (left & 0xcc33cc33)
| ((left >> 6) & 0x00cc00cc);
v0 = ((left << 12) & 0x0f0f0000)
| (left & 0xf0f00f0f)
| ((left >> 12) & 0x0000f0f0);
right = ((right << 6) & 0x33003300)
| (right & 0xcc33cc33)
| ((right >> 6) & 0x00cc00cc);
v1 = ((right << 12) & 0x0f0f0000)
| (right & 0xf0f00f0f)
| ((right >> 12) & 0x0000f0f0);
left = v0 & 0xfffffff0;
right = (v1 & 0xffffff00) | ((v0 << 4) & 0xf0);
keycompperm(left, right, ek);
}
void DES(unsigned int* key, byte* text, byte* C)
{
unsigned int right, left, v0, v1;
left = text[3] | ((unsigned int)text[2] << 8) | ((unsigned int)text[1] << 16) | ((unsigned int)text[0] << 24);
right = text[7] | ((unsigned int)text[6] << 8) | ((unsigned int)text[5] << 16) | ((unsigned int)text[4] << 24);
v0 = key[0];
v0 ^= (right >> 1) | (right << 31);
left ^= SB1[(v0 >> 26) & 0x3f]
^ SB3[(v0 >> 18) & 0x3f]
^ SB5[(v0 >> 10) & 0x3f]
^ SB7[(v0 >> 2) & 0x3f];
v1 = key[1];
v1 ^= (right << 3) | (right >> 29);
left ^= SB2[(v1 >> 26) & 0x3f]
^ SB4[(v1 >> 18) & 0x3f]
^ SB6[(v1 >> 10) & 0x3f]
^ SB8[(v1 >> 2) & 0x3f];
v0 = key[2];
v0 ^= (left >> 1) | (left << 31);
right ^= SB1[(v0 >> 26) & 0x3f]
^ SB3[(v0 >> 18) & 0x3f]
^ SB5[(v0 >> 10) & 0x3f]
^ SB7[(v0 >> 2) & 0x3f];
v1 = key[3];
v1 ^= (left << 3) | (left >> 29);
right ^= SB2[(v1 >> 26) & 0x3f]
^ SB4[(v1 >> 18) & 0x3f]
^ SB6[(v1 >> 10) & 0x3f]
^ SB8[(v1 >> 2) & 0x3f];
v0 = key[4];
v0 ^= (right >> 1) | (right << 31);
left ^= SB1[(v0 >> 26) & 0x3f]
^ SB3[(v0 >> 18) & 0x3f]
^ SB5[(v0 >> 10) & 0x3f]
^ SB7[(v0 >> 2) & 0x3f];
v1 = key[5];
v1 ^= (right << 3) | (right >> 29);
left ^= SB2[(v1 >> 26) & 0x3f]
^ SB4[(v1 >> 18) & 0x3f]
^ SB6[(v1 >> 10) & 0x3f]
^ SB8[(v1 >> 2) & 0x3f];
v0 = key[6];
v0 ^= (left >> 1) | (left << 31);
right ^= SB1[(v0 >> 26) & 0x3f]
^ SB3[(v0 >> 18) & 0x3f]
^ SB5[(v0 >> 10) & 0x3f]
^ SB7[(v0 >> 2) & 0x3f];
v1 = key[7];
v1 ^= (left << 3) | (left >> 29);
right ^= SB2[(v1 >> 26) & 0x3f]
^ SB4[(v1 >> 18) & 0x3f]
^ SB6[(v1 >> 10) & 0x3f]
^ SB8[(v1 >> 2) & 0x3f];
v0 = key[8];
v0 ^= (right >> 1) | (right << 31);
left ^= SB1[(v0 >> 26) & 0x3f]
^ SB3[(v0 >> 18) & 0x3f]
^ SB5[(v0 >> 10) & 0x3f]
^ SB7[(v0 >> 2) & 0x3f];
v1 = key[9];
v1 ^= (right << 3) | (right >> 29);
left ^= SB2[(v1 >> 26) & 0x3f]
^ SB4[(v1 >> 18) & 0x3f]
^ SB6[(v1 >> 10) & 0x3f]
^ SB8[(v1 >> 2) & 0x3f];
v0 = key[10];
v0 ^= (left >> 1) | (left << 31);
right ^= SB1[(v0 >> 26) & 0x3f]
^ SB3[(v0 >> 18) & 0x3f]
^ SB5[(v0 >> 10) & 0x3f]
^ SB7[(v0 >> 2) & 0x3f];
v1 = key[11];
v1 ^= (left << 3) | (left >> 29);
right ^= SB2[(v1 >> 26) & 0x3f]
^ SB4[(v1 >> 18) & 0x3f]
^ SB6[(v1 >> 10) & 0x3f]
^ SB8[(v1 >> 2) & 0x3f];
v0 = key[12];
v0 ^= (right >> 1) | (right << 31);
left ^= SB1[(v0 >> 26) & 0x3f]
^ SB3[(v0 >> 18) & 0x3f]
^ SB5[(v0 >> 10) & 0x3f]
^ SB7[(v0 >> 2) & 0x3f];
v1 = key[13];
v1 ^= (right << 3) | (right >> 29);
left ^= SB2[(v1 >> 26) & 0x3f]
^ SB4[(v1 >> 18) & 0x3f]
^ SB6[(v1 >> 10) & 0x3f]
^ SB8[(v1 >> 2) & 0x3f];
v0 = key[14];
v0 ^= (left >> 1) | (left << 31);
right ^= SB1[(v0 >> 26) & 0x3f]
^ SB3[(v0 >> 18) & 0x3f]
^ SB5[(v0 >> 10) & 0x3f]
^ SB7[(v0 >> 2) & 0x3f];
v1 = key[15];
v1 ^= (left << 3) | (left >> 29);
right ^= SB2[(v1 >> 26) & 0x3f]
^ SB4[(v1 >> 18) & 0x3f]
^ SB6[(v1 >> 10) & 0x3f]
^ SB8[(v1 >> 2) & 0x3f];
v0 = key[16];
v0 ^= (right >> 1) | (right << 31);
left ^= SB1[(v0 >> 26) & 0x3f]
^ SB3[(v0 >> 18) & 0x3f]
^ SB5[(v0 >> 10) & 0x3f]
^ SB7[(v0 >> 2) & 0x3f];
v1 = key[17];
v1 ^= (right << 3) | (right >> 29);
left ^= SB2[(v1 >> 26) & 0x3f]
^ SB4[(v1 >> 18) & 0x3f]
^ SB6[(v1 >> 10) & 0x3f]
^ SB8[(v1 >> 2) & 0x3f];
v0 = key[18];
v0 ^= (left >> 1) | (left << 31);
right ^= SB1[(v0 >> 26) & 0x3f]
^ SB3[(v0 >> 18) & 0x3f]
^ SB5[(v0 >> 10) & 0x3f]
^ SB7[(v0 >> 2) & 0x3f];
v1 = key[19];
v1 ^= (left << 3) | (left >> 29);
right ^= SB2[(v1 >> 26) & 0x3f]
^ SB4[(v1 >> 18) & 0x3f]
^ SB6[(v1 >> 10) & 0x3f]
^ SB8[(v1 >> 2) & 0x3f];
v0 = key[20];
v0 ^= (right >> 1) | (right << 31);
left ^= SB1[(v0 >> 26) & 0x3f]
^ SB3[(v0 >> 18) & 0x3f]
^ SB5[(v0 >> 10) & 0x3f]
^ SB7[(v0 >> 2) & 0x3f];
v1 = key[21];
v1 ^= (right << 3) | (right >> 29);
left ^= SB2[(v1 >> 26) & 0x3f]
^ SB4[(v1 >> 18) & 0x3f]
^ SB6[(v1 >> 10) & 0x3f]
^ SB8[(v1 >> 2) & 0x3f];
v0 = key[22];
v0 ^= (left >> 1) | (left << 31);
right ^= SB1[(v0 >> 26) & 0x3f]
^ SB3[(v0 >> 18) & 0x3f]
^ SB5[(v0 >> 10) & 0x3f]
^ SB7[(v0 >> 2) & 0x3f];
v1 = key[23];
v1 ^= (left << 3) | (left >> 29);
right ^= SB2[(v1 >> 26) & 0x3f]
^ SB4[(v1 >> 18) & 0x3f]
^ SB6[(v1 >> 10) & 0x3f]
^ SB8[(v1 >> 2) & 0x3f];
/*v0 = key[24];
v0 ^= (right >> 1) | (right << 31);
left ^= SB1[(v0 >> 26) & 0x3f]
^ SB3[(v0 >> 18) & 0x3f]
^ SB5[(v0 >> 10) & 0x3f]
^ SB7[(v0 >> 2) & 0x3f];
v1 = key[25];
v1 ^= (right << 3) | (right >> 29);
left ^= SB2[(v1 >> 26) & 0x3f]
^ SB4[(v1 >> 18) & 0x3f]
^ SB6[(v1 >> 10) & 0x3f]
^ SB8[(v1 >> 2) & 0x3f];
v0 = key[26];
v0 ^= (left >> 1) | (left << 31);
right ^= SB1[(v0 >> 26) & 0x3f]
^ SB3[(v0 >> 18) & 0x3f]
^ SB5[(v0 >> 10) & 0x3f]
^ SB7[(v0 >> 2) & 0x3f];
v1 = key[27];
v1 ^= (left << 3) | (left >> 29);
right ^= SB2[(v1 >> 26) & 0x3f]
^ SB4[(v1 >> 18) & 0x3f]
^ SB6[(v1 >> 10) & 0x3f]
^ SB8[(v1 >> 2) & 0x3f];
v0 = key[28];
v0 ^= (right >> 1) | (right << 31);
left ^= SB1[(v0 >> 26) & 0x3f]
^ SB3[(v0 >> 18) & 0x3f]
^ SB5[(v0 >> 10) & 0x3f]
^ SB7[(v0 >> 2) & 0x3f];
v1 = key[29];
v1 ^= (right << 3) | (right >> 29);
left ^= SB2[(v1 >> 26) & 0x3f]
^ SB4[(v1 >> 18) & 0x3f]
^ SB6[(v1 >> 10) & 0x3f]
^ SB8[(v1 >> 2) & 0x3f];
v0 = key[30];
v0 ^= (left >> 1) | (left << 31);
right ^= SB1[(v0 >> 26) & 0x3f]
^ SB3[(v0 >> 18) & 0x3f]
^ SB5[(v0 >> 10) & 0x3f]
^ SB7[(v0 >> 2) & 0x3f];
v1 = key[31];
v1 ^= (left << 3) | (left >> 29);
right ^= SB2[(v1 >> 26) & 0x3f]
^ SB4[(v1 >> 18) & 0x3f]
^ SB6[(v1 >> 10) & 0x3f]
^ SB8[(v1 >> 2) & 0x3f];*/
v0 = left;
v1 = right;
C[7] = v0;
C[6] = v0 >> 8;
C[5] = v0 >> 16;
C[4] = v0 >> 24;
C[3] = v1;
C[2] = v1 >> 8;
C[1] = v1 >> 16;
C[0] = v1 >> 24;
}