-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript3.py
More file actions
43 lines (33 loc) · 1.38 KB
/
Copy pathscript3.py
File metadata and controls
43 lines (33 loc) · 1.38 KB
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
from enigma import (Machine, generateRingSettings,
generateRotorCombinations,
REFLECTOR_OPTIONS)
code = "ABSKJAKKMRITTNYURBJFWQGRSGNNYJSDRYLAPQWIAGKJYEPCTAGDCTHLCDRZRFZHKNRSDLNPFPEBVESHPY"
crib = "THOUSANDS"
code_number = "3"
starting_positions = "EMY"
plugboard_pairs = "FH TS BE UQ KD AL"
nRotorCombos = len(list(generateRotorCombinations(allow_odd=False))) # 24
nRingSettings = len(list(generateRingSettings(allow_odd=False))) # 512
nReflectors = 3
nCombinations = nRotorCombos * nRingSettings * nReflectors # 36,864
found = False
for ring_settings in generateRingSettings(allow_odd=False):
for rotors in generateRotorCombinations(allow_odd=False, allow_greek=True):
for reflector in REFLECTOR_OPTIONS:
machine = Machine(rotors=rotors,
reflector=reflector,
ring_setting=ring_settings,
position_setting=starting_positions,
plugboard_mappings=plugboard_pairs)
result = machine.encode(code)
if crib in result:
found = (result, ring_settings, rotors, reflector)
break
if found:
break
if found:
break
print("code", code_number, "=", result)
print("ring_settings =", ring_settings)
print("rotors = ", rotors)
print("reflector = ", reflector)