Skip to content

Commit 8cabe4e

Browse files
Merge pull request #7 from denismaggior8/feature/v1.3.0
Feature/v1.3.0
2 parents ebe9a9b + 16f7b0e commit 8cabe4e

File tree

13 files changed

+325
-20
lines changed

13 files changed

+325
-20
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
**/dist
55
**/*.drawio.bkp
66
**/*.drawio.dtmp
7-
**/.DS_Store
7+
**/.DS_Store
8+
**/.venv

diagrams/rotors.drawio

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

docs/classdiagram/enigmapython.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ classDiagram
136136
137137
class Reflector {
138138
+ None tag
139+
- __str__(self) str
139140
}
140141
141142
class Observable {

src/enigma/enigmapython/Enigma.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def update(self, observable, *args, **kwargs):
107107
# Engaging the enigma double step issue, only if the next rotor position is in its notch indexe/s
108108
if self.rotors[self.rotors.index(observable)+1].position in self.rotors[self.rotors.index(observable)+1].notch_indexes:
109109
self.rotors[self.rotors.index(observable)+1].double_step_triggered = True
110-
# If the rotor is the last one in the list, but the machine has a rotating reflector, increment it position by 1
110+
# If the rotor is the last one in the list, but the machine has a rotating reflector, increment its position by 1
111111
if observable in self.rotors and self.rotors.index(observable) == len(self.rotors)-1 and isinstance(self.reflector, RotatingReflector):
112112
self.reflector.increment_position()
113113
logging.debug("Reflector has been incremented by 1 position")

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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,13 @@ def __init__(self, wiring, notch_indexes, alphabet, position = 0, ring = 0):
4040

4141

4242
def __str__(self):
43-
pointer = ' ' * self.position + '^'
44-
return self.wiring + '\n' + pointer
43+
str = Scrambler.__str__(self)
44+
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]
48+
return str
49+
4550

4651
def __eq__(self, __value: object) -> bool:
4752
return id(self) == id(object)

src/enigma/enigmapython/Scrambler.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,9 @@ def __shift(letter, shift, alphabet_list):
6060
return alphabet_list[(i + shift) % len(alphabet_list)]
6161

6262
def __str__(self):
63-
return self.wiring
63+
str = ""
64+
for char in self.alphabet_list:
65+
str += char
66+
str += "\n"
67+
str += "|" * len(self.alphabet_list)
68+
return str

src/enigma/enigmapython/XRay.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from rich.console import Console
22
from rich.text import Text
3-
from enigmapython.RotatingReflector import RotatingReflector
3+
4+
from enigmapython.RotatingReflector import RotatingReflector
45

56
class XRay():
67
@staticmethod
@@ -21,9 +22,13 @@ def render_enigma_xray(enigma):
2122

2223
rotor_walls_top = " ".join(["+-----+"] * rotor_count)
2324

24-
rotors_positions = " ".join(["{:02}".format(enigma.rotors[i].position) for i in range(rotor_count - 1, -1, -1)])
25+
rotors_positions = " ".join(["{} ({:02})".format(enigma.alphabet_list[enigma.rotors[i].position].upper(),enigma.rotors[i].position) for i in range(rotor_count - 1, -1, -1)])
26+
27+
rotors_rings = " ".join(["{} ({:02})".format(enigma.alphabet_list[enigma.rotors[i].ring].upper(),enigma.rotors[i].ring) for i in range(rotor_count - 1, -1, -1)])
28+
29+
reflector_ring = ""
2530

26-
rotors_rings = " ".join(["{:02}".format(enigma.rotors[i].ring) for i in range(rotor_count - 1, -1, -1)])
31+
rotor_walls_position = " ".join(["| {} |".format(enigma.alphabet_list[enigma.rotors[i].position].upper()) for i in range(rotor_count - 1, -1, -1)])
2732

2833
rotor_walls = " ".join(["| |"] * rotor_count)
2934

@@ -42,17 +47,17 @@ def render_enigma_xray(enigma):
4247
{rotor_numbers}
4348
+-----+ {rotor_walls_top} +-----+ +-----+
4449
| | {rotor_walls} | | | |
45-
| +--|--<--{rotor_wiring_top}|-----|--<--|-----|----< {enigma.journal[-1]['input_char'] if len(enigma.journal) >= 1 else ' '} <-- Key
50+
| +--|--<--{rotor_wiring_top}|-----|--<--|-----|----< {enigma.journal[-1]['input_char'] if len(enigma.journal) >= 1 else ' '} <-- Key ⌨️
4651
| | {rotor_walls_forward} | {enigma.etw.journal[-2]['output_char'] if len(enigma.etw.journal) >= 2 else ' '} | | {enigma.plugboard.journal[-2]['output_char'] if len(enigma.plugboard.journal) >= 2 else ' '} | |
4752
| | | {rotor_walls} | | | |
4853
| | | {rotor_walls} | | | |
4954
| | | {enigma.reflector.journal[-1]['output_char'] if len(enigma.reflector.journal) >= 1 else ' '} | {rotor_walls_backward} | {enigma.etw.journal[-1]['output_char'] if len(enigma.etw.journal) >= 2 else ' '} | |
50-
| +--|-->--{rotor_wiring_bottom}|-----|-->--|-----|----> {enigma.journal[-1]['output_char'] if len(enigma.journal) >= 1 else ' '} --> Lamp
55+
| +--|-->--{rotor_wiring_bottom}|-----|-->--|-----|----> {enigma.journal[-1]['output_char'] if len(enigma.journal) >= 1 else ' '} --> Lamp 💡
5156
| | {rotor_walls} | | | |
5257
+-----+ {rotor_walls_bottom} +-----+ +-----+
5358
54-
Pos.: {"{:02}".format(enigma.reflector.position) if isinstance(enigma.reflector, RotatingReflector) else ' '} {rotors_positions}
55-
Ring: {rotors_rings}
59+
Pos.: {"{} ({:02})".format(enigma.alphabet_list[enigma.reflector.position].upper(),enigma.reflector.position) if isinstance(enigma.reflector, RotatingReflector) else ' N/A '} {rotors_positions}
60+
Ring: {"{} ({:02})".format(enigma.alphabet_list[enigma.reflector.ring].upper(),enigma.reflector.ring)} {rotors_rings}
5661
"""
5762
console.print(Text(diagram, style="bold"))
5863
return Text(diagram, style="bold")

0 commit comments

Comments
 (0)