This is a command-line simulator for the historic Enigma machine used in cryptography during World War II. The simulator allows for encryption and decryption of text by simulating the exact behavior of an Enigma machine with adjustable rotor settings, ring settings, and plugboard configurations.
- Rotor Selection: Supports multiple rotors with customizable initial positions.
- Ring Settings: Adjust ring settings to offset rotor wiring.
- Plugboard Configuration: Swap pairs of letters to customize encryption further.
- Reflector: Built-in reflector for character swapping, as in real Enigma machines.
- Encryption & Decryption: Encrypt and decrypt text directly from the command line.
- C++ compiler supporting C++11 or higher.
- CMake for build automation.
The program can be executed from the command line with options to encrypt or decrypt a message, adjust rotor positions, set ring configurations, and specify plugboard connections.
./enigma <message> <operation> --rotors <rotor_positions> --ring <ring_settings> --plugboard <plug_connections><message>: The text you want to encrypt or decrypt. Spaces will be replaced with hyphens (-), and all characters will be converted to uppercase.<operation>: Specify--encryptto encrypt or--decryptto decrypt the message.--rotors <rotor_positions>: Initial positions for the rotors in the format0,0,0. Each number represents the starting position of each rotor.--ring <ring_settings>: Ring settings for each rotor in the format0,0,0. Adjusts the internal wiring offset for each rotor.--plugboard <plug_connections>: Letter pairs for the plugboard, such asAB,CD. Each pair swaps those two letters before and after the rotor processing.
- Encrypt a message:
./enigma HELLO --encrypt --rotors 1,2,3 --ring 0,0,0 --plugboard AB,CD
- Decrypt a message:
./enigma OZDQB --decrypt --rotors 1,2,3 --ring 0,0,0 --plugboard AB,CD
-
Clone the repository:
git clone <repository_url> cd enigma-machine-simulator
-
Build the project:
mkdir build cd build cmake .. make -
Run the program:
./enigma <message> <operation> --rotors <rotor_positions> --ring <ring_settings> --plugboard <plug_connections>
The Enigma machine encrypts text through a series of substitutions and permutations:
- Plugboard: First, each letter is swapped with a partner as configured in the plugboard.
- Rotors: The letter passes through a series of rotors with internal wiring that maps each input letter to an output letter. Each rotor advances with each keystroke, changing the encryption pattern.
- Reflector: The reflector maps each letter to another, sending the signal back through the rotors in the reverse order.
- Reverse Rotor Pass: The signal goes back through the rotors in the opposite direction.
- Plugboard: Finally, the plugboard performs another letter swap before outputting the encrypted letter.
Each setting (rotor position, ring settings, and plugboard configuration) changes the encryption, making Enigma's code highly challenging to break without knowing the machine's initial settings.
- Rotors: The program can be extended with additional rotors by modifying the
Rotorclass in the code. - Reflector: Different reflector configurations can be added for additional complexity.
- Plugboard: Customize letter pairs as per user preference.
Contributions are welcome! If you'd like to contribute, please fork the repository and submit a pull request with your changes.
This project is licensed under the MIT License. See the LICENSE file for details.
This project is inspired by the real Enigma machine used during World War II. For more information on the Enigma machine and its history, please refer to Wikipedia.