Skip to content

Instantly share code, notes, and snippets.

@titouanc
Created November 7, 2012 11:55
Show Gist options
  • Save titouanc/4031067 to your computer and use it in GitHub Desktop.
Save titouanc/4031067 to your computer and use it in GitHub Desktop.
Test du fichier sBox.py donné pour le projet 3 (ULB BA1 Sc Info 2012-2013)
import brouillon as P
m1 = P.sBox.sBox
m2 = P.sBox.sBoxInverse
#Test de la fonction de substitution
for i in range(10):
for j in range(10):
k = P.substituteWithBox(
int( '%d%d'%(i,j) ), m1
)
assert(k == m1[i][j])
#Test de l'inversibilité de la permutation
for i in range(100):
j = P.substituteWithBox(i, m1)
k = P.substituteWithBox(j, m2)
print(end='%2d => %2d => %2d '%(i, j, k))
if (i == k):
print("OK")
else:
print("ERR: SubInv(Sub(%d)) = %d"%(i, k))
0 => 2 => 0 OK
1 => 73 => 1 OK
2 => 77 => 2 OK
3 => 72 => 3 OK
4 => 84 => 4 OK
5 => 62 => 5 OK
6 => 65 => 6 OK
7 => 35 => 7 OK
8 => 30 => 8 OK
9 => 1 => 9 OK
10 => 31 => 10 OK
11 => 82 => 11 OK
12 => 39 => 12 OK
13 => 74 => 13 OK
14 => 98 => 14 OK
15 => 59 => 15 OK
16 => 47 => 16 OK
17 => 50 => 17 OK
18 => 14 => 18 OK
19 => 44 => 19 OK
20 => 27 => 20 OK
21 => 64 => 21 OK
22 => 93 => 22 OK
23 => 25 => 23 OK
24 => 63 => 24 OK
25 => 36 => 25 OK
26 => 67 => 26 OK
27 => 33 => 27 OK
28 => 66 => 28 OK
29 => 15 => 29 OK
30 => 4 => 30 OK
31 => 37 => 31 OK
32 => 48 => 32 OK
33 => 57 => 33 OK
34 => 18 => 34 OK
35 => 96 => 35 OK
36 => 5 => 36 OK
37 => 91 => 37 OK
38 => 7 => 38 OK
39 => 12 => 39 OK
40 => 9 => 40 OK
41 => 83 => 41 OK
42 => 23 => 42 OK
43 => 19 => 43 OK
44 => 16 => 44 OK
45 => 8 => 45 OK
46 => 51 => 46 OK
47 => 10 => 47 OK
48 => 52 => 48 OK
49 => 32 => 49 OK
50 => 89 => 50 OK
51 => 41 => 51 OK
52 => 0 => 52 OK
53 => 78 => 53 OK
54 => 29 => 54 OK
55 => 95 => 55 OK
56 => 21 => 56 OK
57 => 87 => 57 OK
58 => 61 => 58 OK
59 => 54 => 59 OK
60 => 20 => 60 OK
61 => 76 => 61 OK
62 => 11 => 62 OK
63 => 99 => 63 OK
64 => 43 => 64 OK
65 => 71 => 65 OK
66 => 58 => 66 OK
67 => 85 => 67 OK
68 => 45 => 68 OK
69 => 69 => 69 OK
70 => 80 => 70 OK
71 => 24 => 71 OK
72 => 40 => 72 OK
73 => 86 => 73 OK
74 => 92 => 74 OK
75 => 94 => 75 OK
76 => 38 => 76 OK
77 => 6 => 77 OK
78 => 49 => 78 OK
79 => 26 => 79 OK
80 => 34 => 80 OK
81 => 3 => 81 OK
82 => 13 => 82 OK
83 => 53 => 83 OK
84 => 56 => 84 OK
85 => 97 => 85 OK
86 => 75 => 86 OK
87 => 28 => 88 ERR: SubInv(Sub(87)) = 88
88 => 68 => 45 ERR: SubInv(Sub(88)) = 45
89 => 17 => 89 OK
90 => 60 => 90 OK
91 => 81 => 91 OK
92 => 79 => 92 OK
93 => 70 => 93 OK
94 => 22 => 94 OK
95 => 42 => 95 OK
96 => 90 => 96 OK
97 => 88 => 97 OK
98 => 46 => 98 OK
99 => 55 => 99 OK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment