des-PurePy 1.0.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
des_PurePy/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ """Package providing a DES implementation."""
2
+
3
+ from .des import DES # Import class DES from module (file) DES. Simplies user import
@@ -0,0 +1,499 @@
1
+ # Luna Perez-Herrera
2
+ # GNU AGPLv3
3
+
4
+ """Defines the various constants required for DES."""
5
+
6
+
7
+ @staticmethod
8
+ def des_pc1():
9
+ """Returns the permuted choice 1 table required for DES.
10
+
11
+ Returns
12
+ -------
13
+ pc1 : list[int]
14
+ A list of integers containing the contents of the PC1 table.
15
+ """
16
+ return [
17
+ 57,
18
+ 49,
19
+ 41,
20
+ 33,
21
+ 25,
22
+ 17,
23
+ 9,
24
+ 1,
25
+ 58,
26
+ 50,
27
+ 42,
28
+ 34,
29
+ 26,
30
+ 18,
31
+ 10,
32
+ 2,
33
+ 59,
34
+ 51,
35
+ 43,
36
+ 35,
37
+ 27,
38
+ 19,
39
+ 11,
40
+ 3,
41
+ 60,
42
+ 52,
43
+ 44,
44
+ 36,
45
+ 63,
46
+ 55,
47
+ 47,
48
+ 39,
49
+ 31,
50
+ 23,
51
+ 15,
52
+ 7,
53
+ 62,
54
+ 54,
55
+ 46,
56
+ 38,
57
+ 30,
58
+ 22,
59
+ 14,
60
+ 6,
61
+ 61,
62
+ 53,
63
+ 45,
64
+ 37,
65
+ 29,
66
+ 21,
67
+ 13,
68
+ 5,
69
+ 28,
70
+ 20,
71
+ 12,
72
+ 4,
73
+ ]
74
+
75
+
76
+ @staticmethod
77
+ def des_pc2():
78
+ """Returns the permuted choice 2 table required for DES.
79
+
80
+ Returns
81
+ -------
82
+ pc1 : list[int]
83
+ A list of integers containing the contents of the PC2 table.
84
+ """
85
+ return [
86
+ 14,
87
+ 17,
88
+ 11,
89
+ 24,
90
+ 1,
91
+ 5,
92
+ 3,
93
+ 28,
94
+ 15,
95
+ 6,
96
+ 21,
97
+ 10,
98
+ 23,
99
+ 19,
100
+ 12,
101
+ 4,
102
+ 26,
103
+ 8,
104
+ 16,
105
+ 7,
106
+ 27,
107
+ 20,
108
+ 13,
109
+ 2,
110
+ 41,
111
+ 52,
112
+ 31,
113
+ 37,
114
+ 47,
115
+ 55,
116
+ 30,
117
+ 40,
118
+ 51,
119
+ 45,
120
+ 33,
121
+ 48,
122
+ 44,
123
+ 49,
124
+ 39,
125
+ 56,
126
+ 34,
127
+ 53,
128
+ 46,
129
+ 42,
130
+ 50,
131
+ 36,
132
+ 29,
133
+ 32,
134
+ ]
135
+
136
+
137
+ @staticmethod
138
+ def des_shifts():
139
+ """Returns the left shifts schedule required for DES.
140
+
141
+ Returns
142
+ -------
143
+ left_shifts : list[int]
144
+ A list of integers containing the left shifts schedule.
145
+ """
146
+ return [1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1]
147
+
148
+
149
+ @staticmethod
150
+ def des_ip():
151
+ """Returns the initial permutation table required for DES.
152
+
153
+ Returns
154
+ -------
155
+ ip : list[int]
156
+ A list of integers containing the initial permutation table.
157
+ """
158
+ return [
159
+ 58,
160
+ 50,
161
+ 42,
162
+ 34,
163
+ 26,
164
+ 18,
165
+ 10,
166
+ 2,
167
+ 60,
168
+ 52,
169
+ 44,
170
+ 36,
171
+ 28,
172
+ 20,
173
+ 12,
174
+ 4,
175
+ 62,
176
+ 54,
177
+ 46,
178
+ 38,
179
+ 30,
180
+ 22,
181
+ 14,
182
+ 6,
183
+ 64,
184
+ 56,
185
+ 48,
186
+ 40,
187
+ 32,
188
+ 24,
189
+ 16,
190
+ 8,
191
+ 57,
192
+ 49,
193
+ 41,
194
+ 33,
195
+ 25,
196
+ 17,
197
+ 9,
198
+ 1,
199
+ 59,
200
+ 51,
201
+ 43,
202
+ 35,
203
+ 27,
204
+ 19,
205
+ 11,
206
+ 3,
207
+ 61,
208
+ 53,
209
+ 45,
210
+ 37,
211
+ 29,
212
+ 21,
213
+ 13,
214
+ 5,
215
+ 63,
216
+ 55,
217
+ 47,
218
+ 39,
219
+ 31,
220
+ 23,
221
+ 15,
222
+ 7,
223
+ ]
224
+
225
+
226
+ @staticmethod
227
+ def des_fp():
228
+ """Returns the inverse initial permutation table required for DES.
229
+
230
+ Returns
231
+ -------
232
+ fp : list[int]
233
+ A list of integers containing the inverse initial permutation table.
234
+ """
235
+ return [
236
+ 40,
237
+ 8,
238
+ 48,
239
+ 16,
240
+ 56,
241
+ 24,
242
+ 64,
243
+ 32,
244
+ 39,
245
+ 7,
246
+ 47,
247
+ 15,
248
+ 55,
249
+ 23,
250
+ 63,
251
+ 31,
252
+ 38,
253
+ 6,
254
+ 46,
255
+ 14,
256
+ 54,
257
+ 22,
258
+ 62,
259
+ 30,
260
+ 37,
261
+ 5,
262
+ 45,
263
+ 13,
264
+ 53,
265
+ 21,
266
+ 61,
267
+ 29,
268
+ 36,
269
+ 4,
270
+ 44,
271
+ 12,
272
+ 52,
273
+ 20,
274
+ 60,
275
+ 28,
276
+ 35,
277
+ 3,
278
+ 43,
279
+ 11,
280
+ 51,
281
+ 19,
282
+ 59,
283
+ 27,
284
+ 34,
285
+ 2,
286
+ 42,
287
+ 10,
288
+ 50,
289
+ 18,
290
+ 58,
291
+ 26,
292
+ 33,
293
+ 1,
294
+ 41,
295
+ 9,
296
+ 49,
297
+ 17,
298
+ 57,
299
+ 25,
300
+ ]
301
+
302
+
303
+ @staticmethod
304
+ def des_ep():
305
+ """Returns the expansion permutation table required for DES.
306
+
307
+ Returns
308
+ -------
309
+ ep : list[int]
310
+ A list of integers containing the expansion permutation table.
311
+ """
312
+ return [
313
+ 32,
314
+ 1,
315
+ 2,
316
+ 3,
317
+ 4,
318
+ 5,
319
+ 4,
320
+ 5,
321
+ 6,
322
+ 7,
323
+ 8,
324
+ 9,
325
+ 8,
326
+ 9,
327
+ 10,
328
+ 11,
329
+ 12,
330
+ 13,
331
+ 12,
332
+ 13,
333
+ 14,
334
+ 15,
335
+ 16,
336
+ 17,
337
+ 16,
338
+ 17,
339
+ 18,
340
+ 19,
341
+ 20,
342
+ 21,
343
+ 20,
344
+ 21,
345
+ 22,
346
+ 23,
347
+ 24,
348
+ 25,
349
+ 24,
350
+ 25,
351
+ 26,
352
+ 27,
353
+ 28,
354
+ 29,
355
+ 28,
356
+ 29,
357
+ 30,
358
+ 31,
359
+ 32,
360
+ 1,
361
+ ]
362
+
363
+
364
+ @staticmethod
365
+ def des_pf():
366
+ """Returns the permutation function table required for DES.
367
+
368
+ Returns
369
+ -------
370
+ pf : list[int]
371
+ A list of integers containing the permutation function table.
372
+ """
373
+ return [
374
+ 16,
375
+ 7,
376
+ 20,
377
+ 21,
378
+ 29,
379
+ 12,
380
+ 28,
381
+ 17,
382
+ 1,
383
+ 15,
384
+ 23,
385
+ 26,
386
+ 5,
387
+ 18,
388
+ 31,
389
+ 10,
390
+ 2,
391
+ 8,
392
+ 24,
393
+ 14,
394
+ 32,
395
+ 27,
396
+ 3,
397
+ 9,
398
+ 19,
399
+ 13,
400
+ 30,
401
+ 6,
402
+ 22,
403
+ 11,
404
+ 4,
405
+ 25,
406
+ ]
407
+
408
+
409
+ @staticmethod
410
+ def des_sboxes():
411
+ """Returns the s-boxes required for DES.
412
+
413
+ Returns
414
+ -------
415
+ sboxes : list[list[int]]
416
+ A list of list of integers containing the 8 s-boxes.
417
+ """
418
+ return [
419
+ # S1
420
+ [ # Row 0
421
+ [14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7],
422
+ # Row 1
423
+ [0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8],
424
+ # Row 2
425
+ [4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0],
426
+ # Row 3
427
+ [15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13],
428
+ ],
429
+ # S2
430
+ [ # Row 0
431
+ [15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10],
432
+ # Row 1
433
+ [3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5],
434
+ # Row 2
435
+ [0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15],
436
+ # Row 3
437
+ [13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9],
438
+ ],
439
+ # S3
440
+ [ # Row 0
441
+ [10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8],
442
+ # Row 1
443
+ [13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1],
444
+ # Row 2
445
+ [13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7],
446
+ # Row 3
447
+ [1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12],
448
+ ],
449
+ # S4
450
+ [ # Row 0
451
+ [7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15],
452
+ # Row 1
453
+ [13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9],
454
+ # Row 2
455
+ [10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4],
456
+ # Row 3
457
+ [3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14],
458
+ ],
459
+ # S5
460
+ [ # Row 0
461
+ [2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9],
462
+ # Row 1
463
+ [14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6],
464
+ # Row 2
465
+ [4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14],
466
+ # Row 3
467
+ [11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3],
468
+ ],
469
+ # S6
470
+ [ # Row 0
471
+ [12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11],
472
+ # Row 1
473
+ [10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8],
474
+ # Row 2
475
+ [9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6],
476
+ # Row 3
477
+ [4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13],
478
+ ],
479
+ # S7
480
+ [ # Row 0
481
+ [4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1],
482
+ # Row 1
483
+ [13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6],
484
+ # Row 2
485
+ [1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2],
486
+ # Row 3
487
+ [6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12],
488
+ ],
489
+ # S8
490
+ [ # Row 0
491
+ [13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7],
492
+ # Row 1
493
+ [1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2],
494
+ # Row 2
495
+ [7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8],
496
+ # Row 3
497
+ [2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11],
498
+ ],
499
+ ]