An implementation of the Enigma machine in Python.
Project description
Enigma Simulator
An implementation of the Enigma machine in Python. Simulates a common 3-rotor machine with the common 8 rotors and 3 reflectors. Wikipedia has a good overview. Project inspired by this video.
The transformation of each letter is implemented as a product of permutations (Rejewski, 1980), in this case 26x26 matrices. The transform, E, in this formulation, can therefore be expressed as:
where P is the plugboard, L, M and R are the left, middle and right rotors respectively, U is the reflector and p is the cyclic permutation of the mapping of A to B, B to C, etc. a, b and c are the rotations of each rotor as caused when a key was pressed.
Can be used to encrypt/decrypt messages ('X' was used to replace spaces) as such:
from enigma_simulator.enigma import Enigma
# Encrypting
enigma1 = Enigma(["I", "II", "III"], [1, 1, 1], "B", "AD", [0, 0, 0])
enigma1.encrypt("HELLOXWORLD") # Returns "LOFUHZZLZOB"
# Decrypting
enigma2 = Enigma(["I", "II", "III"], [1, 1, 1], "B", "AD", [0, 0, 0])
enigma2.encrypt("LOFUHZZLZOB") # Returns "HELLOXWORLD" back
Project details
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
File details
Details for the file enigma_simulator-0.4.0.tar.gz
.
File metadata
- Download URL: enigma_simulator-0.4.0.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c175d41744c70450d556a590fd7fe98209126363058703be4589bc278ead2b4 |
|
MD5 | 56e49130d680cd01b201b8de7939f649 |
|
BLAKE2b-256 | 314e96071b4cbf86343cae8bbb5a34f69cff3460131a5a3b08666ba2fd15bde4 |
File details
Details for the file enigma_simulator-0.4.0-py2.py3-none-any.whl
.
File metadata
- Download URL: enigma_simulator-0.4.0-py2.py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06e1553fa1b7038982e7873a4daf31a9e968cf75bdb26b1390fbe85ac0371d40 |
|
MD5 | 276739aa7739d8e3f6e83b7d6d89a64d |
|
BLAKE2b-256 | a16932edaf262c22051c113fc6329c525c921bfa694aa36dc84ce282cd3618a8 |