Skip to content

Commit 17366dc

Browse files
committed
__str__ methods redefined
1 parent 72cab08 commit 17366dc

File tree

7 files changed

+202
-12
lines changed

7 files changed

+202
-12
lines changed

diagrams/rotors.drawio

Lines changed: 179 additions & 1 deletion
Large diffs are not rendered by default.

src/enigma/enigmapython/Etw.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ def __init__(self, wiring, alphabet=Alphabets.lookup.get("latin_i18n_26chars_low
1616
self.alphabet_list = list(alphabet)
1717

1818
def __str__(self):
19-
return self.wiring
19+
str = Scrambler.__str__(self)
20+
str += "\n"
21+
str += self.wiring
22+
return str

src/enigma/enigmapython/Plugboard.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ def __init__(self, wiring, alphabet):
1717

1818

1919
def __str__(self):
20-
return self.wiring
20+
str = Scrambler.__str__(self)
21+
str += "\n"
22+
str += self.wiring
23+
return str
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
from .Scrambler import Scrambler
22

33
class Reflector(Scrambler):
4-
tag = None
4+
tag = None
5+
6+
def __str__(self):
7+
str = Scrambler.__str__(self)
8+
str += "\n"
9+
str += self.wiring
10+
return str

src/enigma/enigmapython/Rotor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ def __init__(self, wiring, notch_indexes, alphabet, position = 0, ring = 0):
4040

4141

4242
def __str__(self):
43-
pointer = ' ' * self.position + '^'
4443
str = Scrambler.__str__(self)
4544
str += "\n"
46-
str += pointer
47-
str += "\n"
45+
# Slice the wiring, in order to left-rotate it according to the position
46+
n = self.position % len(self.wiring)
47+
str += self.wiring[n:] + self.wiring[:n]
4848
return str
4949

5050

src/enigma/enigmapython/Scrambler.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,4 @@ def __str__(self):
6565
str += char
6666
str += "\n"
6767
str += "|" * len(self.alphabet_list)
68-
str += "\n"
69-
str += self.wiring
7068
return str

test.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515

1616

1717
plugboard = PlugboardPassthrough()
18-
rotor1 = EnigmaM4RotorI(1)
18+
rotor1 = EnigmaM4RotorI(position=1, ring=0)
1919
rotor2 = EnigmaM4RotorII(15)
20-
rotor3 = EnigmaM4RotorIII(26)
20+
rotor3 = EnigmaM4RotorIII(1)
21+
print(rotor1)
2122
rotor4 = EnigmaM4RotorBeta(4)
2223
reflector = ReflectorUKWBThin()
2324
etw = EtwPassthrough()
2425
enigma = EnigmaM4(plugboard, rotor1, rotor2, rotor3, rotor4, reflector, etw, True)
2526
enigma.input_char("c")
2627
XRay.render_enigma_xray(enigma)
28+
print(rotor1)
2729

2830

2931
rotor1 = EnigmaZRotorI(1)
@@ -34,4 +36,4 @@
3436
enigma = EnigmaZ(rotor3, rotor2, rotor1, reflector, etw, True)
3537
enigma.input_char("8")
3638
XRay.render_enigma_xray(enigma)
37-
#print("1".upper())
39+
print(rotor3)

0 commit comments

Comments
 (0)