-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenigma.py
63 lines (52 loc) · 1.75 KB
/
enigma.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
from typing import ForwardRef
from rich.traceback import install
from rich.console import Console
import yaml
c = Console()
install()
with open("properties.yml", "r") as file:
properties = yaml.safe_load(file)
class rotor:
def __init__(self, wheelPosition, rotor, startIndex) -> None:
self.wheelPosition = wheelPosition
self.rotation = startIndex
self.inSide = properties["Rotor " + rotor + " Input"]
self.outSide = properties["Rotor " + rotor + " Output"]
self.notch = properties["Rotor " + rotor + " Notch"]
def rotate(self):
if self.wheelPosition == 2:
if self.rotation == 26:
self.rotation = 1
else:
self.rotation += 1
else:
pass
def passthrough(self, charIn, loop=False, returnIndex=False):
if not loop:
inIndex = self.inSide.index(charIn)
else:
inIndex = self.outSide.index(charIn)
outIndex = inIndex + self.rotation
try:
letterOut = self.outSide[outIndex]
except IndexError:
outIndex = outIndex - 25
if not loop:
letterOut = self.outSide[outIndex]
else:
letterOut = self.inSide[outIndex]
if returnIndex:
return letterOut, outIndex
else:
return letterOut
def getInd(self, index, forward=True):
if forward:
return self.inSide[index]
else:
return self.outSide[index]
class reflector:
def __init__(self) -> None:
self.inSide = properties["Reflector In"]
self.outSide = properties["Reflector Out"]
def passthrough(self, indIn):
return self.outSide[self.inSide.index(indIn)]