-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_crypto.py
153 lines (116 loc) · 3.99 KB
/
test_crypto.py
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
#!/usr/bin/env python3
import crypto
import components
def test_enigmaCase1():
print('\nRunning test case 1')
# Reflector B
# Plugboard Empty
testNigma = crypto.Enigma(
rotors = {
1: components.Rotor("I",0, 0),
2: components.Rotor("II",0, 0),
3: components.Rotor("III",0, 0),
},
reflector = components.Reflector("B"),
plugboard = components.Plugboard({})
)
test_input = open('tests/testCases1.txt', 'r').read().split('\n\n')
for line in test_input:
input_line, output_line = line.split('\n')
assert testNigma.EDcrypt(input_line) == output_line
print('Done!')
def test_enigmaCase2():
print('\nRunning test case 2')
# Reflector B
# Plugboard Empty
# Slowest rotor grund forced to pass Z
testNigma = crypto.Enigma(
rotors = {
1: components.Rotor("I",0, 12),
2: components.Rotor("II",0, 0),
3: components.Rotor("III",0, 0),
},
reflector = components.Reflector("B"),
plugboard = components.Plugboard({})
)
test_input = open('tests/testCases2.txt', 'r').read().split('\n\n')
for line in test_input:
input_line, output_line = line.split('\n')
assert testNigma.EDcrypt(input_line) == output_line
print('Done!')
def test_enigmaCase3():
print('\nRunning test case 3')
# Reflector B
# Plugboard Empty
# Slowest rotor grund forced to pass Z
# Rotors with double step
testNigma = crypto.Enigma(
rotors = {
1: components.Rotor("VI",0, 0),
2: components.Rotor("VII",0, 0),
3: components.Rotor("VIII",0, 0),
},
reflector = components.Reflector("B"),
plugboard = components.Plugboard({})
)
test_input = open('tests/testCases3.txt', 'r').read().split('\n\n')
for line in test_input:
input_line, output_line = line.split('\n')
assert testNigma.EDcrypt(input_line) == output_line
print('Done!')
def test_enigmaCase4():
print('\nRunning test case 4')
# Reflector B
# Plugboard Empty
testNigma = crypto.Enigma(
rotors = {
1: components.Rotor("VI",0, 12),
2: components.Rotor("VII",0, 0),
3: components.Rotor("VIII",0, 0),
},
reflector = components.Reflector("B"),
plugboard = components.Plugboard({})
)
test_input = open('tests/testCases4.txt', 'r').read().split('\n\n')
for line in test_input:
input_line, output_line = line.split('\n')
assert testNigma.EDcrypt(input_line) == output_line
print('Done!')
def test_enigmaCase5():
print('\nRunning test case 5')
# Reflector B
# Plugboard Empty
# Slowest rotor grund forced to pass Z
# Rotors with double step and single step mixed
testNigma = crypto.Enigma(
rotors = {
1: components.Rotor("VI",0, 16),
2: components.Rotor("VII",0, 0),
3: components.Rotor("VIII",0, 0),
},
reflector = components.Reflector("B"),
plugboard = components.Plugboard({})
)
test_input = open('tests/testCases5.txt', 'r').read().split('\n\n')
for line in test_input:
input_line, output_line = line.split('\n')
assert testNigma.EDcrypt(input_line) == output_line
print('Done!')
def test_enigmaCase6():
print('\nRunning test case 6')
# Reflector B
# Plugboard Empty
testNigma = crypto.Enigma(
rotors = {
1: components.Rotor("VI",12, 16),
2: components.Rotor("VI",12, 16),
3: components.Rotor("II",12, 16),
},
reflector = components.Reflector("B"),
plugboard = components.Plugboard({})
)
test_input = open('tests/testCases6.txt', 'r').read().split('\n\n')
for line in test_input:
input_line, output_line = line.split('\n')
assert testNigma.EDcrypt(input_line) == output_line
print('Done!')