A historically accurate simulation of the German Enigma M3 cipher machine used during World War II. This implementation focuses on faithful recreation of the mechanical encryption process using modern C++ and object-oriented programming principles.
- ๐ฎ Interactive CLI Interface - User-friendly menu system with visual feedback
- ๐ Bidirectional Encryption - Encrypt and decrypt messages with the same settings
- ๐ Configurable Plugboard - Swap letter pairs for additional encryption complexity
- โ๏ธ Adjustable Rotor Positions - Set starting positions for all three rotors
- ๐ฏ Historical Accuracy - Uses authentic Enigma rotor wirings and configurations
- ๐งช Comprehensive Testing - Unit tests for all components with 90%+ coverage
- ๐ Cross-Platform - Runs on Linux, Windows, and macOS
Choose option (1-5): 1
Enter message to encrypt: HELLO
Encrypted message: LZFBD
Choose option (1-5): 3
Enter two letters to swap (e.g., AB): HM
Plugboard configured: H <-> M
Choose option (1-5): 4
Enter positions for left, middle, and right rotors (e.g., AAA): XYZ
Rotor positions set to: XYZ
The simulator uses a modular object-oriented design that mirrors the physical Enigma machine:
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ Plugboard โ -> โ Rotors โ -> โ Reflector โ -> โ Rotors โ -> โ Plugboard โ
โ (Input) โ โ Right|Mid|Leftโ โ โ โLef|Mid|Rightโ โ (Output) โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
enigma_machine
- Main controller orchestrating the encryption processrotor
- Individual rotor with scrambled alphabet and rotation mechanicsplugboard
- Letter pair swapping for additional complexityEnigmaDisplay
- Terminal-based user interface with visual feedback
- C++ Compiler (g++, clang++, or MSVC with C++14 support)
- CMake (version 3.14 or higher)
- Git (for cloning the repository)
# Clone the repository
git clone https://github.com/YOUR_USERNAME/enigma-machine.git
cd enigma-machine
# Build the Docker image
docker build -t enigma-simulator .
# Interactive mode
docker run -it enigma-simulator
# Or pipe input for automated interactions
echo "1\nHELLO\n5" | docker run -i enigma-simulator
- Base Image: Ubuntu 22.04 LTS
- Build Process:
- Install build dependencies (g++, cmake)
- Copy project files
- Compile the project
- Create a minimal runtime image
- Image Size: Approximately 100-150 MB
- Supported Platforms: Linux, Windows (WSL2), macOS (Intel/M1)
# Clone the repository
git clone https://github.com/YOUR_USERNAME/enigma-machine.git
cd enigma-machine
# Build the project
mkdir build && cd build
cmake ..
make
# Run the simulator
./enigma
# Clone and navigate
git clone https://github.com/YOUR_USERNAME/enigma-machine.git
cd enigma-machine
# Build
mkdir build && cd build
cmake ..
cmake --build . --config Debug
# Run
Debug\enigma.exe
- Start the program - Run
./enigma
from the build directory - Choose operation:
1
- Encrypt a message2
- Decrypt a message (same as encrypt with Enigma's reciprocal property)3
- Configure plugboard connections4
- Set rotor starting positions5
- Exit
ENIGMA M3 CIPHER MACHINE
========================
โโ[ROTOR POSITIONS]โโโโโโโโโโ
โ Position: A A A โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโ[PLUGBOARD]โโโโโโโโโโโโโโโโ
โ No connections โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
INPUT: [none]
OUTPUT: [none]
Select option (1-5): 1
Enter message to encrypt: HELLO
Encrypted message: LZFBD
Select option (1-5): 4
Current rotor positions: AAA
Enter new rotor positions (3 letters, e.g., ABC): XYZ
Rotor positions set to: XYZ
Select option (1-5): 3
Enter two letters to connect (or press Enter to skip): AB
Plugboard connection added: AโB
The simulator uses authentic Enigma rotor configurations:
- Rotor I:
EKMFLGDQVZNTOWYHXUSPAIBRCJ
- Rotor II:
AJDKSIRUXBLHWTMCQGZNPYFVOE
- Rotor III:
BDFHJLCPRTXVZNYEIWGAKMUSQO
- Reflector B:
EJMZALYXVBWFCRQUONTSPIKHGD
To modify rotor configurations, edit the arrays in main.cpp
:
char rotor1_config[26] = {'E', 'K', 'M', 'F', /* ... */};
# Run all tests
cd build
ctest -V
# Run specific test suites
./tests/rotor_test
./tests/plugboard_test
./tests/enigma_machine_test
The project includes comprehensive unit tests covering:
- โ Rotor rotation and position management
- โ Plugboard letter swapping
- โ Complete encryption/decryption cycles
- โ Edge cases and boundary conditions
- โ Cross-platform compatibility
GitHub Actions automatically runs tests on:
- Ubuntu 22.04
- Windows Latest
- macOS Latest
- Input Character: User types a letter (A-Z)
- First Plugboard: Letter may be swapped if plugboard connection exists
- Rotor Stepping: Right rotor advances, potentially triggering middle/left rotors
- Forward Path: Signal passes through rotors (right โ middle โ left)
- Reflector: Signal bounces back through reflector
- Return Path: Signal returns through rotors (left โ middle โ right)
- Second Plugboard: Final letter swap if connection exists
- Output: Encrypted letter displayed
- Reciprocal: Encrypting the same letter twice returns the original
- No Self-Encryption: No letter ever encrypts to itself
- Rotor Stepping: Position changes affect subsequent encryptions
- Plugboard: Adds additional layer of complexity
Each rotor implements a substitution cipher that changes with rotor position:
Position 0: AโE, BโK, CโM, ...
Position 1: AโK, BโM, CโF, ... (shifted by rotation)
Build fails with CMake version error:
# Update CMake to version 3.14+
brew install cmake # macOS
sudo apt install cmake # Ubuntu
Tests fail on Windows:
- Ensure you're running from the correct directory
- Use
Debug\test_name.exe
instead of./test_name
"Sometimes it is the people no one imagines anything of who do the things that no one can imagine." - Alan Turing