enigma-m4 0.4.0__tar.gz

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.
Files changed (32) hide show
  1. enigma_m4-0.4.0/LICENSE +21 -0
  2. enigma_m4-0.4.0/PKG-INFO +312 -0
  3. enigma_m4-0.4.0/README.md +273 -0
  4. enigma_m4-0.4.0/pyproject.toml +35 -0
  5. enigma_m4-0.4.0/setup.cfg +4 -0
  6. enigma_m4-0.4.0/src/enigma/__init__.py +3 -0
  7. enigma_m4-0.4.0/src/enigma/core/__init__.py +3 -0
  8. enigma_m4-0.4.0/src/enigma/core/machine.py +58 -0
  9. enigma_m4-0.4.0/src/enigma/core/plugboard.py +117 -0
  10. enigma_m4-0.4.0/src/enigma/core/reflector.py +39 -0
  11. enigma_m4-0.4.0/src/enigma/core/rotor.py +72 -0
  12. enigma_m4-0.4.0/src/enigma/data/__init__.py +3 -0
  13. enigma_m4-0.4.0/src/enigma/data/reflectors.py +6 -0
  14. enigma_m4-0.4.0/src/enigma/data/rotors.py +15 -0
  15. enigma_m4-0.4.0/src/enigma/utils/cli/__init__.py +3 -0
  16. enigma_m4-0.4.0/src/enigma/utils/cli/main.py +0 -0
  17. enigma_m4-0.4.0/src/enigma/utils/gui/__init__.py +3 -0
  18. enigma_m4-0.4.0/src/enigma/utils/gui/app.py +0 -0
  19. enigma_m4-0.4.0/src/enigma_m4.egg-info/PKG-INFO +312 -0
  20. enigma_m4-0.4.0/src/enigma_m4.egg-info/SOURCES.txt +30 -0
  21. enigma_m4-0.4.0/src/enigma_m4.egg-info/dependency_links.txt +1 -0
  22. enigma_m4-0.4.0/src/enigma_m4.egg-info/requires.txt +8 -0
  23. enigma_m4-0.4.0/src/enigma_m4.egg-info/top_level.txt +1 -0
  24. enigma_m4-0.4.0/tests/test_integration.py +60 -0
  25. enigma_m4-0.4.0/tests/test_integration_m4.py +119 -0
  26. enigma_m4-0.4.0/tests/test_integration_m4_historical.py +161 -0
  27. enigma_m4-0.4.0/tests/test_machine.py +152 -0
  28. enigma_m4-0.4.0/tests/test_plugboard.py +115 -0
  29. enigma_m4-0.4.0/tests/test_reflector.py +72 -0
  30. enigma_m4-0.4.0/tests/test_reflectors.py +23 -0
  31. enigma_m4-0.4.0/tests/test_rotor.py +123 -0
  32. enigma_m4-0.4.0/tests/test_rotors.py +37 -0
@@ -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,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
+ ![Python](https://img.shields.io/badge/Python-3.12-blue)
41
+ ![Tests](https://img.shields.io/badge/Tests-passing-brightgreen)
42
+ ![License](https://img.shields.io/badge/License-MIT-yellow)
43
+ [![codecov](https://codecov.io/gh/wrogistefan/enigma_m4/branch/main/graph/badge.svg)](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
+ [![GitHub](https://img.shields.io/badge/GitHub-Profile-black?logo=github)](https://github.com/wrogistefan)
312
+ [![LinkedIn](https://img.shields.io/badge/LinkedIn-Profile-blue?logo=linkedin)](https://www.linkedin.com/in/lukaszperek)
@@ -0,0 +1,273 @@
1
+ ![Python](https://img.shields.io/badge/Python-3.12-blue)
2
+ ![Tests](https://img.shields.io/badge/Tests-passing-brightgreen)
3
+ ![License](https://img.shields.io/badge/License-MIT-yellow)
4
+ [![codecov](https://codecov.io/gh/wrogistefan/enigma_m4/branch/main/graph/badge.svg)](https://codecov.io/gh/wrogistefan/enigma_m4)
5
+
6
+ # 🔐 Enigma Machine Simulator (M3 → M4)
7
+
8
+ 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.
9
+
10
+ This project emphasizes:
11
+
12
+ - correctness
13
+ - mechanical fidelity
14
+ - clean architecture
15
+ - testability
16
+ - extensibility
17
+
18
+ It is both a **learning tool** and a **professional portfolio project** demonstrating engineering discipline and historical accuracy.
19
+
20
+ ## 📚 Documentation
21
+
22
+ - **[User Manual](docs/USER_MANUAL.md)** - Complete guide for using the simulator
23
+ - **[API Reference](docs/API_REFERENCE.md)** - Detailed API documentation
24
+
25
+ ## 🚀 Quick Start
26
+
27
+ ```python
28
+ from enigma.core.machine import EnigmaMachine
29
+ from enigma.core.rotor import Rotor
30
+ from enigma.core.reflector import Reflector
31
+ from enigma.core.plugboard import Plugboard
32
+ from enigma.data.rotors import ROTOR_I, ROTOR_II, ROTOR_III
33
+ from enigma.data.reflectors import REFLECTOR_B
34
+
35
+ # Create components
36
+ rotors = [
37
+ Rotor(*ROTOR_I, position="A"),
38
+ Rotor(*ROTOR_II, position="A"),
39
+ Rotor(*ROTOR_III, position="A")
40
+ ]
41
+ reflector = Reflector(REFLECTOR_B)
42
+ plugboard = Plugboard()
43
+
44
+ # Create machine and encrypt
45
+ machine = EnigmaMachine(rotors, reflector, plugboard)
46
+ encrypted = machine.encode_letter("H")
47
+ ```
48
+
49
+ ## 📦 Installation
50
+
51
+ Install from PyPI:
52
+
53
+ ```bash
54
+ pip install enigma-m4
55
+ ```
56
+
57
+ Or install from source:
58
+
59
+ ```bash
60
+ git clone https://github.com/wrogistefan/enigma_m4.git
61
+ cd enigma_m4
62
+ pip install -e .
63
+ ```
64
+
65
+ ---
66
+
67
+ # ✨ Features
68
+
69
+ ### 🧠 Core Capabilities
70
+ - Full **M3** support (rotors I–VIII, reflectors A/B/C)
71
+ - Full **M4** support (III–II–I + Greek rotor)
72
+ - Greek rotors: **Beta**, **Gamma**
73
+ - Thin reflectors: **Thin B**, **Thin C**
74
+ - Historically accurate **stepping** and **double‑stepping**
75
+ - Ring settings (Ringstellung)
76
+ - Rotor positions (Grundstellung)
77
+ - Plugboard (Steckerbrett) with validation
78
+ - Full reversibility (Enigma property)
79
+
80
+ ### 🔌 Historical Plugboard
81
+ Supports all historically used formats:
82
+
83
+ ```python
84
+ {"A": "B"} # dict
85
+ [("A", "B"), ("C", "D")] # list of pairs
86
+ "PO ML IU KZ" # Kriegsmarine format
87
+ "A-B C-D" # dash format
88
+ ```
89
+
90
+ Up to **10 pairs**, matching real Enigma constraints.
91
+
92
+ ---
93
+
94
+ # 🧩 Architecture Overview
95
+
96
+ The machine is composed of independent, testable components:
97
+
98
+ ```
99
+ Plugboard
100
+ ↓
101
+ Right Rotor → Middle Rotor → Left Rotor → Greek Rotor (M4)
102
+ ↓ ↓ ↓ ↓
103
+ Reflector
104
+ ↑ ↑ ↑ ↑
105
+ Right Rotor ← Middle Rotor ← Left Rotor ← Greek Rotor
106
+ ↑
107
+ Plugboard
108
+ ```
109
+
110
+ ### 🔧 Components
111
+
112
+ #### 🔌 Plugboard
113
+ - Bidirectional letter swapping
114
+ - Full validation
115
+ - Historical 10‑pair limit
116
+ - API: `swap(char)`
117
+
118
+ #### ⚙ Rotors
119
+ - Forward & backward signal path
120
+ - Ring setting
121
+ - Rotor position
122
+ - Notch logic
123
+ - `step()` rotation
124
+ - Includes:
125
+ - I, II, III, IV, V
126
+ - VI, VII, VIII (Kriegsmarine)
127
+ - Beta, Gamma (M4 static rotors)
128
+
129
+ #### 🪞 Reflectors
130
+ - Involutive mapping
131
+ - No fixed points
132
+ - Includes:
133
+ - A, B, C
134
+ - Thin B, Thin C (M4)
135
+
136
+ #### 🖥 EnigmaMachine
137
+ - Correct stepping logic (M3 + M4)
138
+ - Double‑stepping implemented
139
+ - Full signal path implemented
140
+ - Plugboard integration
141
+ - Reversible encryption
142
+
143
+ ---
144
+
145
+ # 📁 Project Structure
146
+
147
+ ```
148
+ enigma_m4/
149
+ ├── pyproject.toml
150
+ ├── README.md
151
+ ├── LICENSE
152
+ ├── docs/
153
+ │ ├── USER_MANUAL.md
154
+ │ └── API_REFERENCE.md
155
+ ├── src/
156
+ │ └── enigma/
157
+ │ ├── __init__.py
158
+ │ ├── core/
159
+ │ │ ├── __init__.py
160
+ │ │ ├── rotor.py
161
+ │ │ ├── reflector.py
162
+ │ │ ├── plugboard.py
163
+ │ │ └── machine.py
164
+ │ ├── data/
165
+ │ │ ├── __init__.py
166
+ │ │ ├── rotors.py
167
+ │ │ └── reflectors.py
168
+ │ └── utils/
169
+ │ ├── __init__.py
170
+ │ ├── cli/
171
+ │ │ ├── __init__.py
172
+ │ │ └── main.py
173
+ │ └── gui/
174
+ │ ├── __init__.py
175
+ │ └── app.py
176
+ └── tests/
177
+ ├── __init__.py
178
+ ├── test_rotor.py
179
+ ├── test_reflector.py
180
+ ├── test_plugboard.py
181
+ ├── test_machine.py
182
+ ├── test_rotors.py
183
+ ├── test_reflectors.py
184
+ ├── test_integration.py
185
+ ├── test_integration_m4.py
186
+ ├── test_integration_m4_historical.py
187
+ └── test_plugboard.py
188
+ ```
189
+
190
+ ---
191
+
192
+ # 📖 Documentation
193
+
194
+ For detailed usage instructions and API reference:
195
+
196
+ - **[📋 User Manual](docs/USER_MANUAL.md)** - Complete guide including installation, configuration, and examples
197
+ - **[🔧 API Reference](docs/API_REFERENCE.md)** - Detailed documentation of all classes and methods
198
+
199
+ ---
200
+
201
+ # 🧪 Testing
202
+
203
+ Run all tests:
204
+
205
+ ```
206
+ pytest -q
207
+ ```
208
+
209
+ The test suite includes:
210
+
211
+ - unit tests for rotors, reflectors, plugboard
212
+ - M3 integration tests
213
+ - M4 integration tests
214
+ - historical canonical tests:
215
+ - Beta + Thin B → A → **B**
216
+ - Gamma + Thin C → A → **P**
217
+ - reversibility tests
218
+ - ring setting tests
219
+ - plugboard tests
220
+ - Kriegsmarine‑style configuration tests
221
+
222
+ ---
223
+
224
+ # 🗺 Roadmap
225
+
226
+ ### ✅ Completed (v0.4.0)
227
+ - Full M3 implementation
228
+ - Full M4 implementation
229
+ - Greek rotors (Beta/Gamma)
230
+ - Thin reflectors (Thin B/C)
231
+ - Historical plugboard formats
232
+ - Full stepping logic
233
+ - Comprehensive test suite
234
+
235
+ ### 🔜 Next
236
+ - Add historical daily key sheets
237
+ - Add real U‑boat message examples
238
+ - Add CLI interface
239
+ - Add web demo
240
+ - Add visualization of rotor stepping
241
+
242
+ ---
243
+
244
+ # 📜 License
245
+
246
+ This project is licensed under the [MIT License](LICENSE).
247
+
248
+ ---
249
+
250
+ # 👤 About the Author
251
+
252
+ **Łukasz Perek** — Python developer focused on clean architecture, cryptography, and historically inspired engineering.
253
+
254
+ Based in **Syracuse, Sicily**, transitioning into full‑time software engineering and AI‑driven development.
255
+
256
+ Specializes in:
257
+
258
+ - Python (OOP, CLI tools, packaging, testing)
259
+ - Clean, modular architecture
260
+ - Cryptographic systems & historical computing
261
+ - CI/CD (GitHub Actions, linting, coverage)
262
+ - Documentation & developer experience
263
+
264
+ This Enigma simulator is part of his public portfolio — a demonstration of engineering discipline, historical accuracy, and modern Python design.
265
+
266
+ If you find this project interesting or useful, feel free to ⭐ the repository.
267
+
268
+ ---
269
+
270
+ # 🔗 Connect
271
+
272
+ [![GitHub](https://img.shields.io/badge/GitHub-Profile-black?logo=github)](https://github.com/wrogistefan)
273
+ [![LinkedIn](https://img.shields.io/badge/LinkedIn-Profile-blue?logo=linkedin)](https://www.linkedin.com/in/lukaszperek)
@@ -0,0 +1,35 @@
1
+ [project]
2
+ name = "enigma-m4"
3
+ version = "0.4.0"
4
+ description = "A modern, fully tested Enigma machine simulator in Python."
5
+ readme = "README.md"
6
+ license = { file = "LICENSE" }
7
+ authors = [
8
+ { name = "Łukasz Perek" }
9
+ ]
10
+ requires-python = ">=3.10"
11
+
12
+ [project.optional-dependencies]
13
+ dev = [
14
+ "pytest",
15
+ "pytest-cov",
16
+ "black",
17
+ "flake8",
18
+ "ruff",
19
+ "mypy",
20
+ ]
21
+
22
+ [tool.setuptools.packages.find]
23
+ where = ["src"]
24
+
25
+ [tool.pytest.ini_options]
26
+ pythonpath = ["src"]
27
+ addopts = "--maxfail=1 --disable-warnings"
28
+
29
+ [tool.black]
30
+ line-length = 88
31
+ target-version = ["py310"]
32
+
33
+ [tool.flake8]
34
+ max-line-length = 88
35
+ extend-ignore = ["E203"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ """
2
+ Top-level package for the Enigma simulator.
3
+ """
@@ -0,0 +1,3 @@
1
+ """
2
+ Core cryptographic components of the Enigma machine.
3
+ """
@@ -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