A Python implementation of the WWII Enigma encryption machine with Pygame visualization
A fully functional Enigma Machine simulator built using Python and Pygame, replicating the encryption process of the famous World War II cipher machine.
This project allows users to interactively type letters, visualize the internal signal flow through the rotors, reflector, and plugboard — just like in the real Enigma Machine.
- 🧠 Accurate rotor stepping logic
- 🌀 Customizable rotors, reflectors, plugboard, and ring settings
- 🎮 Real-time interactive interface using Pygame
- 🌈 Signal path visualization with colors:
- Green: Forward signal through rotors
- Yellow: Reflection
- Red: Return path
enigma-simulator/ │ ├── main.py # Entry point for the simulator ├── enigma.py # Enigma machine class and logic ├── rotor.py # Rotor definitions and behavior ├── plugboard.py # Plugboard logic ├── reflector.py # Reflector logic ├── keyboard.py # Input-output lampboard logic ├── assets/ # Fonts and graphics └── README.md # You're reading this!
- Python 3.7 or above
- Pygame
If you're using Sublime Text, make sure your system Python is properly set up:
Open terminal / command prompt: bash
➤ Install Pygame Now install Pygame via pip:
bash
pip install pygame If using multiple Python versions, try:
bash
python3 -m pip install pygame How to Run (in Sublime Text) Open the main.py file in Sublime Text
Press Ctrl + B (or Cmd + B on Mac) to run the simulator
A new Pygame window will appear
Start typing letters (A–Z) on your keyboard — encrypted output lights up like the original machine
Inside main.py, you can customize the Enigma machine setup:
python
from enigma import Enigma from rotor import Rotor_I, Rotor_II, Rotor_III from reflector import Reflector_B from plugboard import Plugboard
plugboard = Plugboard(["AB", "CD", "EF"])
enigma = Enigma( Reflector_B, Rotor_I, Rotor_II, Rotor_III, plugboard, key="CAT", # Initial rotor positions rings=(1, 1, 1) # Ring settings )
Example Use Input: HELLO
Output (lights shown): WZPBT
Internal: Each key press moves the rotors and encrypts differently.
🧠 Learning Outcomes 🔐 Cryptography fundamentals (substitution, permutation, key space)
🧩 How real Enigma encryption worked
💡 GUI programming in Python using Pygame
🧱 Object-oriented design and modular coding
Originally created by the YouTube channel Coding Cassowary
Adapted and documented by [mohan kumar]
Inspired by historical Enigma machine design and educational simulations.
MIT License. Feel free to use, modify, and learn!