A modern, fully tested Enigma machine simulator in Python.
Project description
๐ Enigma Machine Simulator (M3 โ M4)
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.
This project emphasizes:
- correctness
- mechanical fidelity
- clean architecture
- testability
- extensibility
It is both a learning tool and a professional portfolio project demonstrating engineering discipline and historical accuracy.
๐ Documentation
- User Manual - Complete guide for using the simulator
- API Reference - Detailed API documentation
๐ Quick Start
from enigma.core.machine import EnigmaMachine
from enigma.core.rotor import Rotor
from enigma.core.reflector import Reflector
from enigma.core.plugboard import Plugboard
from enigma.data.rotors import ROTOR_I, ROTOR_II, ROTOR_III
from enigma.data.reflectors import REFLECTOR_B
# Create components
rotors = [
Rotor(*ROTOR_I, position="A"),
Rotor(*ROTOR_II, position="A"),
Rotor(*ROTOR_III, position="A")
]
reflector = Reflector(REFLECTOR_B)
plugboard = Plugboard()
# Create machine and encrypt
machine = EnigmaMachine(rotors, reflector, plugboard)
encrypted = machine.encode_letter("H")
๐ฆ Installation
Install from PyPI:
pip install enigma-m4
Or install from source:
git clone https://github.com/wrogistefan/enigma_m4.git
cd enigma_m4
pip install -e .
โจ Features
๐ง Core Capabilities
- Full M3 support (rotors IโVIII, reflectors A/B/C)
- Full M4 support (IIIโIIโI + Greek rotor)
- Greek rotors: Beta, Gamma
- Thin reflectors: Thin B, Thin C
- Historically accurate stepping and doubleโstepping
- Ring settings (Ringstellung)
- Rotor positions (Grundstellung)
- Plugboard (Steckerbrett) with validation
- Full reversibility (Enigma property)
๐ Historical Plugboard
Supports all historically used formats:
{"A": "B"} # dict
[("A", "B"), ("C", "D")] # list of pairs
"PO ML IU KZ" # Kriegsmarine format
"A-B C-D" # dash format
Up to 10 pairs, matching real Enigma constraints.
๐งฉ Architecture Overview
The machine is composed of independent, testable components:
Plugboard
โ
Right Rotor โ Middle Rotor โ Left Rotor โ Greek Rotor (M4)
โ โ โ โ
Reflector
โ โ โ โ
Right Rotor โ Middle Rotor โ Left Rotor โ Greek Rotor
โ
Plugboard
๐ง Components
๐ Plugboard
- Bidirectional letter swapping
- Full validation
- Historical 10โpair limit
- API:
swap(char)
โ Rotors
- Forward & backward signal path
- Ring setting
- Rotor position
- Notch logic
step()rotation- Includes:
- I, II, III, IV, V
- VI, VII, VIII (Kriegsmarine)
- Beta, Gamma (M4 static rotors)
๐ช Reflectors
- Involutive mapping
- No fixed points
- Includes:
- A, B, C
- Thin B, Thin C (M4)
๐ฅ EnigmaMachine
- Correct stepping logic (M3 + M4)
- Doubleโstepping implemented
- Full signal path implemented
- Plugboard integration
- Reversible encryption
๐ Project Structure
enigma_m4/
โโโ pyproject.toml
โโโ README.md
โโโ LICENSE
โโโ docs/
โ โโโ USER_MANUAL.md
โ โโโ API_REFERENCE.md
โโโ src/
โ โโโ enigma/
โ โโโ __init__.py
โ โโโ core/
โ โ โโโ __init__.py
โ โ โโโ rotor.py
โ โ โโโ reflector.py
โ โ โโโ plugboard.py
โ โ โโโ machine.py
โ โโโ data/
โ โ โโโ __init__.py
โ โ โโโ rotors.py
โ โ โโโ reflectors.py
โ โโโ utils/
โ โโโ __init__.py
โ โโโ cli/
โ โ โโโ __init__.py
โ โ โโโ main.py
โ โโโ gui/
โ โโโ __init__.py
โ โโโ app.py
โโโ tests/
โโโ __init__.py
โโโ test_rotor.py
โโโ test_reflector.py
โโโ test_plugboard.py
โโโ test_machine.py
โโโ test_rotors.py
โโโ test_reflectors.py
โโโ test_integration.py
โโโ test_integration_m4.py
โโโ test_integration_m4_historical.py
โโโ test_plugboard.py
๐ Documentation
For detailed usage instructions and API reference:
- ๐ User Manual - Complete guide including installation, configuration, and examples
- ๐ง API Reference - Detailed documentation of all classes and methods
๐งช Testing
Run all tests:
pytest -q
The test suite includes:
- unit tests for rotors, reflectors, plugboard
- M3 integration tests
- M4 integration tests
- historical canonical tests:
- Beta + Thin B โ A โ B
- Gamma + Thin C โ A โ P
- reversibility tests
- ring setting tests
- plugboard tests
- Kriegsmarineโstyle configuration tests
๐บ Roadmap
โ Completed (v0.4.0)
- Full M3 implementation
- Full M4 implementation
- Greek rotors (Beta/Gamma)
- Thin reflectors (Thin B/C)
- Historical plugboard formats
- Full stepping logic
- Comprehensive test suite
๐ Next
- Add historical daily key sheets
- Add real Uโboat message examples
- Add CLI interface
- Add web demo
- Add visualization of rotor stepping
๐ License
This project is licensed under the MIT License.
๐ค About the Author
ลukasz Perek โ Python developer focused on clean architecture, cryptography, and historically inspired engineering.
Based in Syracuse, Sicily, transitioning into fullโtime software engineering and AIโdriven development.
Specializes in:
- Python (OOP, CLI tools, packaging, testing)
- Clean, modular architecture
- Cryptographic systems & historical computing
- CI/CD (GitHub Actions, linting, coverage)
- Documentation & developer experience
This Enigma simulator is part of his public portfolio โ a demonstration of engineering discipline, historical accuracy, and modern Python design.
If you find this project interesting or useful, feel free to โญ the repository.
๐ Connect
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file enigma_m4-0.4.0.tar.gz.
File metadata
- Download URL: enigma_m4-0.4.0.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06e56f142bca957426eb219e9d278680f02feebe3880c9454642c48d9390eed0
|
|
| MD5 |
d847ce9d188aabcd723e4d9a51a229dd
|
|
| BLAKE2b-256 |
205655b899615f3701ddb18f8c13f2a5fd244e26a7612cea8a64d57f55f7ec13
|
File details
Details for the file enigma_m4-0.4.0-py3-none-any.whl.
File metadata
- Download URL: enigma_m4-0.4.0-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca3044fe32cdf5229cf05ca2ce89b407c918d2db5eacb1e5ccdaa4f67c382992
|
|
| MD5 |
b95404e777af690e74d9f76fb96b558d
|
|
| BLAKE2b-256 |
8b002467b3b3d0e6e9fb515045d1c1a717088cd6699bc41203a38afbbde73f85
|