Enigma Machine Emulator
Project description
Enigma Machine Emulator
This is a simulator for general Enigma Machines, it includes rotor definitions for most versions of the machine (see list below), and is flexible enough that it can be used to simulate any other ones.
Example
from enigma import Machine
from enigma.builtin_rotors import Rotors
machine = Machine(
[Rotors["I"](), Rotors["II"](), Rotors["III"]()],
Rotors["A"]()
)
assert(machine.encode("ENIGMA MACHINE") == "BYEJNJ RSRWHTF")
Enigma Versions
This simulator includes a comprehensive list of rotors that were used in the different enigma versions that existed over time.
These rotors are available in enigma/builtin_rotors.py
, and tests are available in enigma/tests/custom_extensions_test.py
for most of them.
The following variants have rotors available:
- Enigma M3 & M4
- German Railway (Rocket)
- M3 & M4 Naval
- Swiss K (custom entry wheel)
- M4 R1
- Enigma D
- Enigma KD
- Enigma T - Tirpitz (custom entry wheel)
- Norway (Norenigma)
- Railway Enigma
Machine Settings
Arbitrary Number of Rotors
This simulator supports both arbitrary rotos and setting which is the last rotor that can turn. This is because in most versions of the machine, only the first 3 rotors would turn with each keystroke.
Multiple Notches
Rotors can have from 0 to any number of notches.
Entry Wheel (i.e. Enigma T - Tirpitz)
Enigma machines could have an entry wheel that determined the wiring from the keys to the plugboard, and from the plugboard to the lamps.
Extended Alphabet
The rotors allow defining an input alphabet. This can be used to extend from the standard uppercase ASCII used in most machines, to use any unicode character.
Examples of characters that can be encoded with enigma_py
:
- Alphanumeric
- Mixed-case messages
- Non-roman alphabets (Russian, Japanese... )
- Special characters
enigma_py/enigma/tests/custom_extensions_test.py
features a test (test_machine_encodes_custom_alphabets
) with mixed-case inputs and numbers.
It is trivial to use any unicode character - even emoji (as they are just a unicode extension)!
Just for fun I made a few custom "emoji-rotors", so that we can encode:
- Input:
THIS ENIGMA MACHINE SUPPORTS EMOJIS! 😜😍🥰
- Encoded:
😆QK😗 😋🤣FUR😉 SX😚😇😜T😜 😃😂😃😄U😌A😚 😝😛😘😇W🙃! TO😍
To see the Machine and rotors used for the strings above look for the test_emoji_machine
.
Documentation
Autogenerated documentation for all modules is available in docs/index.html
and live in https://aurbano.github.io/enigma.py/
To update the docs:
pip install sphinx
cd docs-config
make github
Test
python -m unittest discover -s ./enigma/tests -p '\*\_test.py'
Coverate report
coverage run -m unittest discover -s ./enigma/tests -p '*_test.py'
coverage html --omit="*/test*" && open ./htmlcov/index.html
Lint
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
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
File details
Details for the file enigma-emulator-1.2.1.tar.gz
.
File metadata
- Download URL: enigma-emulator-1.2.1.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fd681484254d5412b03f21b30f70aa8bf0ad95f9ef439cc2cae69abc7d8e9b0 |
|
MD5 | b98d5a4187c879e9050d334013737d72 |
|
BLAKE2b-256 | c27db62a68700d8a692eea6c021db358b20645caa8fc2b0a7d363f0903297c7b |
File details
Details for the file enigma_emulator-1.2.1-py2.py3-none-any.whl
.
File metadata
- Download URL: enigma_emulator-1.2.1-py2.py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f0d3ef1486774b3f1977cb80e05f368910ad9888789d18e505c5a0d11a2307d |
|
MD5 | 4f42906663c9850396a68f3aa4798afe |
|
BLAKE2b-256 | 66443278c3943261ae6784285e432c1014385af01c99ab5f5473bde9e7b953b3 |