enigma-m4 0.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- enigma/__init__.py +3 -0
- enigma/core/__init__.py +3 -0
- enigma/core/machine.py +58 -0
- enigma/core/plugboard.py +117 -0
- enigma/core/reflector.py +39 -0
- enigma/core/rotor.py +72 -0
- enigma/data/__init__.py +3 -0
- enigma/data/reflectors.py +6 -0
- enigma/data/rotors.py +15 -0
- enigma/utils/cli/__init__.py +3 -0
- enigma/utils/cli/main.py +0 -0
- enigma/utils/gui/__init__.py +3 -0
- enigma/utils/gui/app.py +0 -0
- enigma_m4-0.4.0.dist-info/METADATA +312 -0
- enigma_m4-0.4.0.dist-info/RECORD +18 -0
- enigma_m4-0.4.0.dist-info/WHEEL +5 -0
- enigma_m4-0.4.0.dist-info/licenses/LICENSE +21 -0
- enigma_m4-0.4.0.dist-info/top_level.txt +1 -0
enigma/__init__.py
ADDED
enigma/core/__init__.py
ADDED
enigma/core/machine.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
class EnigmaMachine:
|
|
2
|
+
def __init__(self, rotors, reflector, plugboard):
|
|
3
|
+
self.rotors = rotors
|
|
4
|
+
self.reflector = reflector
|
|
5
|
+
self.plugboard = plugboard
|
|
6
|
+
|
|
7
|
+
def step(self):
|
|
8
|
+
"""
|
|
9
|
+
Step rotors.
|
|
10
|
+
M3: rotors = [r, m, l]
|
|
11
|
+
M4: rotors = [r, m, l, greek] (greek does NOT rotate)
|
|
12
|
+
Implements authentic Enigma stepping rules.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
# Always extract only the first 3 rotors for stepping
|
|
16
|
+
r, m, left = self.rotors[:3]
|
|
17
|
+
|
|
18
|
+
right_at_notch = r.at_notch()
|
|
19
|
+
middle_at_notch = m.at_notch()
|
|
20
|
+
|
|
21
|
+
# Double-step: middle steps if it is at its own notch
|
|
22
|
+
if middle_at_notch:
|
|
23
|
+
m.step()
|
|
24
|
+
left.step()
|
|
25
|
+
|
|
26
|
+
# Normal turnover: middle steps if right is at its notch
|
|
27
|
+
if right_at_notch:
|
|
28
|
+
m.step()
|
|
29
|
+
|
|
30
|
+
# Right rotor always steps
|
|
31
|
+
r.step()
|
|
32
|
+
|
|
33
|
+
def encode_letter(self, char: str) -> str:
|
|
34
|
+
# 1. Step rotors before encoding
|
|
35
|
+
self.step()
|
|
36
|
+
|
|
37
|
+
c = char.upper()
|
|
38
|
+
if not ("A" <= c <= "Z"):
|
|
39
|
+
return c
|
|
40
|
+
|
|
41
|
+
# 2. Plugboard IN
|
|
42
|
+
c = self.plugboard.swap(c)
|
|
43
|
+
|
|
44
|
+
# 3. Forward through rotors (right → middle → left)
|
|
45
|
+
for rotor in self.rotors:
|
|
46
|
+
c = rotor.encode_forward(c)
|
|
47
|
+
|
|
48
|
+
# 4. Reflector
|
|
49
|
+
c = self.reflector.reflect(c)
|
|
50
|
+
|
|
51
|
+
# 5. Backward through rotors (left → middle → right)
|
|
52
|
+
for rotor in reversed(self.rotors):
|
|
53
|
+
c = rotor.encode_backward(c)
|
|
54
|
+
|
|
55
|
+
# 6. Plugboard OUT
|
|
56
|
+
c = self.plugboard.swap(c)
|
|
57
|
+
|
|
58
|
+
return c
|
enigma/core/plugboard.py
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Plugboard:
|
|
5
|
+
"""Represents the Enigma plugboard (Steckerbrett).
|
|
6
|
+
|
|
7
|
+
Fully historical and flexible:
|
|
8
|
+
- Accepts dict: {"A": "B", "C": "D"}
|
|
9
|
+
- Accepts list of pairs: [("A", "B"), ("C", "D")]
|
|
10
|
+
- Accepts Kriegsmarine string: "PO ML IU KZ"
|
|
11
|
+
- Accepts dash format: "A-B C-D"
|
|
12
|
+
- Accepts compact format: "AB CD EF"
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def __init__(self, connections=None) -> None:
|
|
16
|
+
self._mapping: dict[str, str] = {}
|
|
17
|
+
|
|
18
|
+
if connections:
|
|
19
|
+
normalized = self._normalize_connections(connections)
|
|
20
|
+
self._initialize_connections(normalized)
|
|
21
|
+
|
|
22
|
+
# ----------------------------------------------------------------------
|
|
23
|
+
# NORMALIZATION LAYER
|
|
24
|
+
# ----------------------------------------------------------------------
|
|
25
|
+
def _normalize_connections(self, connections) -> dict[str, str]:
|
|
26
|
+
"""Normalize input into a dict[str, str]."""
|
|
27
|
+
|
|
28
|
+
# Already a dict
|
|
29
|
+
if isinstance(connections, dict):
|
|
30
|
+
return {a.upper(): b.upper() for a, b in connections.items()}
|
|
31
|
+
|
|
32
|
+
# List of pairs
|
|
33
|
+
if isinstance(connections, list):
|
|
34
|
+
result = {}
|
|
35
|
+
for a, b in connections:
|
|
36
|
+
result[a.upper()] = b.upper()
|
|
37
|
+
return result
|
|
38
|
+
|
|
39
|
+
# String formats
|
|
40
|
+
if isinstance(connections, str):
|
|
41
|
+
text = connections.strip().upper()
|
|
42
|
+
|
|
43
|
+
# Format: "A-B C-D"
|
|
44
|
+
if "-" in text:
|
|
45
|
+
pairs = text.split()
|
|
46
|
+
result = {}
|
|
47
|
+
for p in pairs:
|
|
48
|
+
a, b = p.split("-")
|
|
49
|
+
result[a] = b
|
|
50
|
+
return result
|
|
51
|
+
|
|
52
|
+
# Format: "PO ML IU KZ"
|
|
53
|
+
tokens = text.split()
|
|
54
|
+
result = {}
|
|
55
|
+
for token in tokens:
|
|
56
|
+
if len(token) != 2:
|
|
57
|
+
raise ValueError(f"Invalid plugboard token: {token!r}")
|
|
58
|
+
a, b = token[0], token[1]
|
|
59
|
+
result[a] = b
|
|
60
|
+
return result
|
|
61
|
+
|
|
62
|
+
raise TypeError("Plugboard connections must be dict, list, or string.")
|
|
63
|
+
|
|
64
|
+
# ----------------------------------------------------------------------
|
|
65
|
+
# INTERNAL VALIDATION
|
|
66
|
+
# ----------------------------------------------------------------------
|
|
67
|
+
def _initialize_connections(self, connections: dict[str, str]) -> None:
|
|
68
|
+
for a, b in connections.items():
|
|
69
|
+
self._add_pair(a, b)
|
|
70
|
+
|
|
71
|
+
def _add_pair(self, a: str, b: str) -> None:
|
|
72
|
+
"""Add a single plugboard pair, validating correctness."""
|
|
73
|
+
|
|
74
|
+
# Historical limit: max 10 pairs
|
|
75
|
+
if len(self._mapping) // 2 >= 10:
|
|
76
|
+
raise ValueError("Plugboard cannot have more than 10 pairs.")
|
|
77
|
+
|
|
78
|
+
a = a.upper()
|
|
79
|
+
b = b.upper()
|
|
80
|
+
|
|
81
|
+
if a == b:
|
|
82
|
+
raise ValueError(f"Cannot connect letter {a} to itself.")
|
|
83
|
+
|
|
84
|
+
for ch in (a, b):
|
|
85
|
+
if not ch.isalpha() or len(ch) != 1:
|
|
86
|
+
raise ValueError(f"Invalid plugboard character: {ch!r}")
|
|
87
|
+
if ch in self._mapping:
|
|
88
|
+
raise ValueError(f"Letter {ch} is already used in another pair.")
|
|
89
|
+
|
|
90
|
+
self._mapping[a] = b
|
|
91
|
+
self._mapping[b] = a
|
|
92
|
+
|
|
93
|
+
# ----------------------------------------------------------------------
|
|
94
|
+
# OPERATION
|
|
95
|
+
# ----------------------------------------------------------------------
|
|
96
|
+
def swap(self, char: str) -> str:
|
|
97
|
+
if not char.isalpha() or len(char) != 1:
|
|
98
|
+
return char
|
|
99
|
+
|
|
100
|
+
c = char.upper()
|
|
101
|
+
return self._mapping.get(c, c)
|
|
102
|
+
|
|
103
|
+
# ----------------------------------------------------------------------
|
|
104
|
+
# UTILITIES
|
|
105
|
+
# ----------------------------------------------------------------------
|
|
106
|
+
def __repr__(self) -> str:
|
|
107
|
+
return f"Plugboard({self._mapping})"
|
|
108
|
+
|
|
109
|
+
def pairs(self) -> list[tuple[str, str]]:
|
|
110
|
+
seen = set()
|
|
111
|
+
result = []
|
|
112
|
+
for a, b in self._mapping.items():
|
|
113
|
+
if a not in seen and b not in seen:
|
|
114
|
+
result.append((a, b))
|
|
115
|
+
seen.add(a)
|
|
116
|
+
seen.add(b)
|
|
117
|
+
return result
|
enigma/core/reflector.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
class Reflector:
|
|
2
|
+
"""Represents an Enigma reflector (Umkehrwalze)."""
|
|
3
|
+
|
|
4
|
+
def __init__(self, wiring: str, involution: bool = True) -> None:
|
|
5
|
+
if len(wiring) != 26:
|
|
6
|
+
raise ValueError("Reflector wiring must be 26 characters long.")
|
|
7
|
+
|
|
8
|
+
self.wiring = wiring.upper()
|
|
9
|
+
self.involution = involution
|
|
10
|
+
|
|
11
|
+
if self.involution:
|
|
12
|
+
# Validate involution AND no fixed points
|
|
13
|
+
for i, c in enumerate(self.wiring):
|
|
14
|
+
j = ord(c) - ord("A")
|
|
15
|
+
|
|
16
|
+
# 1. No letter may map to itself
|
|
17
|
+
if i == j:
|
|
18
|
+
raise ValueError("Reflector cannot map a letter to itself.")
|
|
19
|
+
|
|
20
|
+
# 2. Must be symmetric: wiring[wiring[i]] == i
|
|
21
|
+
if self.wiring[j] != chr(ord("A") + i):
|
|
22
|
+
raise ValueError("Reflector wiring must be an involution.")
|
|
23
|
+
|
|
24
|
+
@staticmethod
|
|
25
|
+
def _char_to_index(c: str) -> int:
|
|
26
|
+
return ord(c) - ord("A")
|
|
27
|
+
|
|
28
|
+
@staticmethod
|
|
29
|
+
def _index_to_char(i: int) -> str:
|
|
30
|
+
return chr(ord("A") + i)
|
|
31
|
+
|
|
32
|
+
def reflect(self, char: str) -> str:
|
|
33
|
+
"""Reflect a character through the reflector."""
|
|
34
|
+
c = char.upper()
|
|
35
|
+
if c < "A" or c > "Z":
|
|
36
|
+
return c
|
|
37
|
+
|
|
38
|
+
i = self._char_to_index(c)
|
|
39
|
+
return self.wiring[i]
|
enigma/core/rotor.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Rotor:
|
|
5
|
+
"""Represents a single Enigma rotor."""
|
|
6
|
+
|
|
7
|
+
def __init__(
|
|
8
|
+
self, wiring: str, notch: str, ring_setting: int = 0, position: str = "A"
|
|
9
|
+
) -> None:
|
|
10
|
+
if len(wiring) != 26:
|
|
11
|
+
raise ValueError("Rotor wiring must be 26 characters long.")
|
|
12
|
+
|
|
13
|
+
self.wiring = wiring.upper()
|
|
14
|
+
self.notch = notch.upper() if notch is not None else None
|
|
15
|
+
self.ring_setting = ring_setting
|
|
16
|
+
self.position = position.upper()
|
|
17
|
+
|
|
18
|
+
@staticmethod
|
|
19
|
+
def _char_to_index(char: str) -> int:
|
|
20
|
+
return ord(char) - ord("A")
|
|
21
|
+
|
|
22
|
+
@staticmethod
|
|
23
|
+
def _index_to_char(index: int) -> str:
|
|
24
|
+
return chr(ord("A") + index)
|
|
25
|
+
|
|
26
|
+
def encode_forward(self, char: str) -> str:
|
|
27
|
+
"""Encode a character from right to left through the rotor."""
|
|
28
|
+
c = char.upper()
|
|
29
|
+
if not ("A" <= c <= "Z"):
|
|
30
|
+
return c
|
|
31
|
+
|
|
32
|
+
i = self._char_to_index(c)
|
|
33
|
+
pos = self._char_to_index(self.position)
|
|
34
|
+
ring = self.ring_setting
|
|
35
|
+
|
|
36
|
+
shifted_in = (i + pos - ring) % 26
|
|
37
|
+
wired_char = self.wiring[shifted_in]
|
|
38
|
+
j = self._char_to_index(wired_char)
|
|
39
|
+
|
|
40
|
+
shifted_out = (j - pos + ring) % 26
|
|
41
|
+
return self._index_to_char(shifted_out)
|
|
42
|
+
|
|
43
|
+
def encode_backward(self, char: str) -> str:
|
|
44
|
+
"""Encode a character from left to right through the rotor."""
|
|
45
|
+
c = char.upper()
|
|
46
|
+
if not ("A" <= c <= "Z"):
|
|
47
|
+
return c
|
|
48
|
+
|
|
49
|
+
i = self._char_to_index(c)
|
|
50
|
+
pos = self._char_to_index(self.position)
|
|
51
|
+
ring = self.ring_setting
|
|
52
|
+
|
|
53
|
+
shifted_in = (i + pos - ring) % 26
|
|
54
|
+
wired_index = self.wiring.index(self._index_to_char(shifted_in))
|
|
55
|
+
|
|
56
|
+
shifted_out = (wired_index - pos + ring) % 26
|
|
57
|
+
return self._index_to_char(shifted_out)
|
|
58
|
+
|
|
59
|
+
def step(self) -> bool:
|
|
60
|
+
"""Advance the rotor by one position and return True if it is now at its notch."""
|
|
61
|
+
index = (self._char_to_index(self.position) + 1) % 26
|
|
62
|
+
self.position = self._index_to_char(index)
|
|
63
|
+
|
|
64
|
+
if self.notch is None:
|
|
65
|
+
return False
|
|
66
|
+
|
|
67
|
+
return self.position == self.notch
|
|
68
|
+
|
|
69
|
+
def at_notch(self) -> bool:
|
|
70
|
+
if self.notch is None:
|
|
71
|
+
return False
|
|
72
|
+
return self.position == self.notch
|
enigma/data/__init__.py
ADDED
enigma/data/rotors.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Wehrmacht/Luftwaffe rotors I–V
|
|
2
|
+
ROTOR_I = ("EKMFLGDQVZNTOWYHXUSPAIBRCJ", "Q")
|
|
3
|
+
ROTOR_II = ("AJDKSIRUXBLHWTMCQGZNPYFVOE", "E")
|
|
4
|
+
ROTOR_III = ("BDFHJLCPRTXVZNYEIWGAKMUSQO", "V")
|
|
5
|
+
ROTOR_IV = ("ESOVPZJAYQUIRHXLNFTGKDCMWB", "J")
|
|
6
|
+
ROTOR_V = ("VZBRGITYUPSDNHLXAWMJQOFECK", "Z")
|
|
7
|
+
|
|
8
|
+
# Kriegsmarine additional rotors VI–VIII
|
|
9
|
+
ROTOR_VI = ("JPGVOUMFYQBENHZRDKASXLICTW", "Z")
|
|
10
|
+
ROTOR_VII = ("NZJHGRCXMYSWBOUFAIVLPEKQDT", "Z")
|
|
11
|
+
ROTOR_VIII = ("FKQHTLXOCBJSPDZRAMEWNIUYGV", "Z")
|
|
12
|
+
|
|
13
|
+
# M4 Greek rotors (do NOT rotate)
|
|
14
|
+
ROTOR_BETA = ("LEYJVCNIXWPBQMDRTAKZGFUHOS", None)
|
|
15
|
+
ROTOR_GAMMA = ("FSOKANUERHMBTIYCWLQPZXVGJD", None)
|
enigma/utils/cli/main.py
ADDED
|
File without changes
|
enigma/utils/gui/app.py
ADDED
|
File without changes
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: enigma-m4
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: A modern, fully tested Enigma machine simulator in Python.
|
|
5
|
+
Author: Łukasz Perek
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 Łukasz Perek
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in
|
|
18
|
+
all copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
25
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
26
|
+
DEALINGS IN THE SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Requires-Python: >=3.10
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: pytest; extra == "dev"
|
|
33
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
34
|
+
Requires-Dist: black; extra == "dev"
|
|
35
|
+
Requires-Dist: flake8; extra == "dev"
|
|
36
|
+
Requires-Dist: ruff; extra == "dev"
|
|
37
|
+
Requires-Dist: mypy; extra == "dev"
|
|
38
|
+
Dynamic: license-file
|
|
39
|
+
|
|
40
|
+

|
|
41
|
+

|
|
42
|
+

|
|
43
|
+
[](https://codecov.io/gh/wrogistefan/enigma_m4)
|
|
44
|
+
|
|
45
|
+
# 🔐 Enigma Machine Simulator (M3 → M4)
|
|
46
|
+
|
|
47
|
+
A clean, modular, historically accurate simulation of the German **Enigma M3** and **Kriegsmarine M4** cipher machines — implemented in modern Python, with full test coverage and historically faithful mechanics.
|
|
48
|
+
|
|
49
|
+
This project emphasizes:
|
|
50
|
+
|
|
51
|
+
- correctness
|
|
52
|
+
- mechanical fidelity
|
|
53
|
+
- clean architecture
|
|
54
|
+
- testability
|
|
55
|
+
- extensibility
|
|
56
|
+
|
|
57
|
+
It is both a **learning tool** and a **professional portfolio project** demonstrating engineering discipline and historical accuracy.
|
|
58
|
+
|
|
59
|
+
## 📚 Documentation
|
|
60
|
+
|
|
61
|
+
- **[User Manual](docs/USER_MANUAL.md)** - Complete guide for using the simulator
|
|
62
|
+
- **[API Reference](docs/API_REFERENCE.md)** - Detailed API documentation
|
|
63
|
+
|
|
64
|
+
## 🚀 Quick Start
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from enigma.core.machine import EnigmaMachine
|
|
68
|
+
from enigma.core.rotor import Rotor
|
|
69
|
+
from enigma.core.reflector import Reflector
|
|
70
|
+
from enigma.core.plugboard import Plugboard
|
|
71
|
+
from enigma.data.rotors import ROTOR_I, ROTOR_II, ROTOR_III
|
|
72
|
+
from enigma.data.reflectors import REFLECTOR_B
|
|
73
|
+
|
|
74
|
+
# Create components
|
|
75
|
+
rotors = [
|
|
76
|
+
Rotor(*ROTOR_I, position="A"),
|
|
77
|
+
Rotor(*ROTOR_II, position="A"),
|
|
78
|
+
Rotor(*ROTOR_III, position="A")
|
|
79
|
+
]
|
|
80
|
+
reflector = Reflector(REFLECTOR_B)
|
|
81
|
+
plugboard = Plugboard()
|
|
82
|
+
|
|
83
|
+
# Create machine and encrypt
|
|
84
|
+
machine = EnigmaMachine(rotors, reflector, plugboard)
|
|
85
|
+
encrypted = machine.encode_letter("H")
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## 📦 Installation
|
|
89
|
+
|
|
90
|
+
Install from PyPI:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
pip install enigma-m4
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Or install from source:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
git clone https://github.com/wrogistefan/enigma_m4.git
|
|
100
|
+
cd enigma_m4
|
|
101
|
+
pip install -e .
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
# ✨ Features
|
|
107
|
+
|
|
108
|
+
### 🧠 Core Capabilities
|
|
109
|
+
- Full **M3** support (rotors I–VIII, reflectors A/B/C)
|
|
110
|
+
- Full **M4** support (III–II–I + Greek rotor)
|
|
111
|
+
- Greek rotors: **Beta**, **Gamma**
|
|
112
|
+
- Thin reflectors: **Thin B**, **Thin C**
|
|
113
|
+
- Historically accurate **stepping** and **double‑stepping**
|
|
114
|
+
- Ring settings (Ringstellung)
|
|
115
|
+
- Rotor positions (Grundstellung)
|
|
116
|
+
- Plugboard (Steckerbrett) with validation
|
|
117
|
+
- Full reversibility (Enigma property)
|
|
118
|
+
|
|
119
|
+
### 🔌 Historical Plugboard
|
|
120
|
+
Supports all historically used formats:
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
{"A": "B"} # dict
|
|
124
|
+
[("A", "B"), ("C", "D")] # list of pairs
|
|
125
|
+
"PO ML IU KZ" # Kriegsmarine format
|
|
126
|
+
"A-B C-D" # dash format
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Up to **10 pairs**, matching real Enigma constraints.
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
# 🧩 Architecture Overview
|
|
134
|
+
|
|
135
|
+
The machine is composed of independent, testable components:
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
Plugboard
|
|
139
|
+
↓
|
|
140
|
+
Right Rotor → Middle Rotor → Left Rotor → Greek Rotor (M4)
|
|
141
|
+
↓ ↓ ↓ ↓
|
|
142
|
+
Reflector
|
|
143
|
+
↑ ↑ ↑ ↑
|
|
144
|
+
Right Rotor ← Middle Rotor ← Left Rotor ← Greek Rotor
|
|
145
|
+
↑
|
|
146
|
+
Plugboard
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### 🔧 Components
|
|
150
|
+
|
|
151
|
+
#### 🔌 Plugboard
|
|
152
|
+
- Bidirectional letter swapping
|
|
153
|
+
- Full validation
|
|
154
|
+
- Historical 10‑pair limit
|
|
155
|
+
- API: `swap(char)`
|
|
156
|
+
|
|
157
|
+
#### ⚙ Rotors
|
|
158
|
+
- Forward & backward signal path
|
|
159
|
+
- Ring setting
|
|
160
|
+
- Rotor position
|
|
161
|
+
- Notch logic
|
|
162
|
+
- `step()` rotation
|
|
163
|
+
- Includes:
|
|
164
|
+
- I, II, III, IV, V
|
|
165
|
+
- VI, VII, VIII (Kriegsmarine)
|
|
166
|
+
- Beta, Gamma (M4 static rotors)
|
|
167
|
+
|
|
168
|
+
#### 🪞 Reflectors
|
|
169
|
+
- Involutive mapping
|
|
170
|
+
- No fixed points
|
|
171
|
+
- Includes:
|
|
172
|
+
- A, B, C
|
|
173
|
+
- Thin B, Thin C (M4)
|
|
174
|
+
|
|
175
|
+
#### 🖥 EnigmaMachine
|
|
176
|
+
- Correct stepping logic (M3 + M4)
|
|
177
|
+
- Double‑stepping implemented
|
|
178
|
+
- Full signal path implemented
|
|
179
|
+
- Plugboard integration
|
|
180
|
+
- Reversible encryption
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
# 📁 Project Structure
|
|
185
|
+
|
|
186
|
+
```
|
|
187
|
+
enigma_m4/
|
|
188
|
+
├── pyproject.toml
|
|
189
|
+
├── README.md
|
|
190
|
+
├── LICENSE
|
|
191
|
+
├── docs/
|
|
192
|
+
│ ├── USER_MANUAL.md
|
|
193
|
+
│ └── API_REFERENCE.md
|
|
194
|
+
├── src/
|
|
195
|
+
│ └── enigma/
|
|
196
|
+
│ ├── __init__.py
|
|
197
|
+
│ ├── core/
|
|
198
|
+
│ │ ├── __init__.py
|
|
199
|
+
│ │ ├── rotor.py
|
|
200
|
+
│ │ ├── reflector.py
|
|
201
|
+
│ │ ├── plugboard.py
|
|
202
|
+
│ │ └── machine.py
|
|
203
|
+
│ ├── data/
|
|
204
|
+
│ │ ├── __init__.py
|
|
205
|
+
│ │ ├── rotors.py
|
|
206
|
+
│ │ └── reflectors.py
|
|
207
|
+
│ └── utils/
|
|
208
|
+
│ ├── __init__.py
|
|
209
|
+
│ ├── cli/
|
|
210
|
+
│ │ ├── __init__.py
|
|
211
|
+
│ │ └── main.py
|
|
212
|
+
│ └── gui/
|
|
213
|
+
│ ├── __init__.py
|
|
214
|
+
│ └── app.py
|
|
215
|
+
└── tests/
|
|
216
|
+
├── __init__.py
|
|
217
|
+
├── test_rotor.py
|
|
218
|
+
├── test_reflector.py
|
|
219
|
+
├── test_plugboard.py
|
|
220
|
+
├── test_machine.py
|
|
221
|
+
├── test_rotors.py
|
|
222
|
+
├── test_reflectors.py
|
|
223
|
+
├── test_integration.py
|
|
224
|
+
├── test_integration_m4.py
|
|
225
|
+
├── test_integration_m4_historical.py
|
|
226
|
+
└── test_plugboard.py
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
# 📖 Documentation
|
|
232
|
+
|
|
233
|
+
For detailed usage instructions and API reference:
|
|
234
|
+
|
|
235
|
+
- **[📋 User Manual](docs/USER_MANUAL.md)** - Complete guide including installation, configuration, and examples
|
|
236
|
+
- **[🔧 API Reference](docs/API_REFERENCE.md)** - Detailed documentation of all classes and methods
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
# 🧪 Testing
|
|
241
|
+
|
|
242
|
+
Run all tests:
|
|
243
|
+
|
|
244
|
+
```
|
|
245
|
+
pytest -q
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
The test suite includes:
|
|
249
|
+
|
|
250
|
+
- unit tests for rotors, reflectors, plugboard
|
|
251
|
+
- M3 integration tests
|
|
252
|
+
- M4 integration tests
|
|
253
|
+
- historical canonical tests:
|
|
254
|
+
- Beta + Thin B → A → **B**
|
|
255
|
+
- Gamma + Thin C → A → **P**
|
|
256
|
+
- reversibility tests
|
|
257
|
+
- ring setting tests
|
|
258
|
+
- plugboard tests
|
|
259
|
+
- Kriegsmarine‑style configuration tests
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
# 🗺 Roadmap
|
|
264
|
+
|
|
265
|
+
### ✅ Completed (v0.4.0)
|
|
266
|
+
- Full M3 implementation
|
|
267
|
+
- Full M4 implementation
|
|
268
|
+
- Greek rotors (Beta/Gamma)
|
|
269
|
+
- Thin reflectors (Thin B/C)
|
|
270
|
+
- Historical plugboard formats
|
|
271
|
+
- Full stepping logic
|
|
272
|
+
- Comprehensive test suite
|
|
273
|
+
|
|
274
|
+
### 🔜 Next
|
|
275
|
+
- Add historical daily key sheets
|
|
276
|
+
- Add real U‑boat message examples
|
|
277
|
+
- Add CLI interface
|
|
278
|
+
- Add web demo
|
|
279
|
+
- Add visualization of rotor stepping
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
# 📜 License
|
|
284
|
+
|
|
285
|
+
This project is licensed under the [MIT License](LICENSE).
|
|
286
|
+
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
# 👤 About the Author
|
|
290
|
+
|
|
291
|
+
**Łukasz Perek** — Python developer focused on clean architecture, cryptography, and historically inspired engineering.
|
|
292
|
+
|
|
293
|
+
Based in **Syracuse, Sicily**, transitioning into full‑time software engineering and AI‑driven development.
|
|
294
|
+
|
|
295
|
+
Specializes in:
|
|
296
|
+
|
|
297
|
+
- Python (OOP, CLI tools, packaging, testing)
|
|
298
|
+
- Clean, modular architecture
|
|
299
|
+
- Cryptographic systems & historical computing
|
|
300
|
+
- CI/CD (GitHub Actions, linting, coverage)
|
|
301
|
+
- Documentation & developer experience
|
|
302
|
+
|
|
303
|
+
This Enigma simulator is part of his public portfolio — a demonstration of engineering discipline, historical accuracy, and modern Python design.
|
|
304
|
+
|
|
305
|
+
If you find this project interesting or useful, feel free to ⭐ the repository.
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
# 🔗 Connect
|
|
310
|
+
|
|
311
|
+
[](https://github.com/wrogistefan)
|
|
312
|
+
[](https://www.linkedin.com/in/lukaszperek)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
enigma/__init__.py,sha256=XJwjesjx4p2bHpfbC1GM69duPACa0gggOfxAYUjxGj0,55
|
|
2
|
+
enigma/core/__init__.py,sha256=haxrVx1mcZAaynMT_yaSLQR3UwAqIZFT6AgI5FTtWzA,64
|
|
3
|
+
enigma/core/machine.py,sha256=awR9eR-R5q5I75CO9i3V7glPwxsRZxPxcsnhw3fadIc,1610
|
|
4
|
+
enigma/core/plugboard.py,sha256=v6DUxtf1pqwzr_MONiZebn9Gw549sjOgxo83W7luAnE,4126
|
|
5
|
+
enigma/core/reflector.py,sha256=uhIRuc1b1sQlhgMSZdGEl2e1tfU9i46L-fKClKiGobI,1316
|
|
6
|
+
enigma/core/rotor.py,sha256=r3U1Ste2g2F7b5FqPVf_JTYgXWPyWlt8Ki4EsP4Bx3c,2316
|
|
7
|
+
enigma/data/__init__.py,sha256=W10Jlrm3CQdZOGzzrKvvpJnx5jRsAs4dWJu-jHQqoI8,58
|
|
8
|
+
enigma/data/reflectors.py,sha256=aK6XbVfp7CPEC8lIhzBJzruDFKsi1l38DJ7bHwI2CnI,232
|
|
9
|
+
enigma/data/rotors.py,sha256=6fT87pW_ug-juFM_AwarILp-vJZTbv1gPgAlYL-NKdg,608
|
|
10
|
+
enigma/utils/cli/__init__.py,sha256=7ruk6LXGcdcwGCuyOAvef1Hyn4yV4tjIiwW9NaeScYQ,60
|
|
11
|
+
enigma/utils/cli/main.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
|
+
enigma/utils/gui/__init__.py,sha256=rXk2GDqXClsUM2Ym_VVfbHXEvTJr2C5v15Zw89Vc9lY,62
|
|
13
|
+
enigma/utils/gui/app.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
|
+
enigma_m4-0.4.0.dist-info/licenses/LICENSE,sha256=9hKxPFNv7YGGZspH6lQc1EmDq3pvWk2RfAF7VQb-wHE,1111
|
|
15
|
+
enigma_m4-0.4.0.dist-info/METADATA,sha256=LVBFM3KkpaIqsMgSYK8goimXxgLsrJHpKibRYVeDVwU,9195
|
|
16
|
+
enigma_m4-0.4.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
17
|
+
enigma_m4-0.4.0.dist-info/top_level.txt,sha256=4gcNuVt95PW0pw7dWU83SCK_gCQXL8G95hajy2CIlvQ,7
|
|
18
|
+
enigma_m4-0.4.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Łukasz Perek
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
20
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
21
|
+
DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
enigma
|