Skip to main content

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

Release files for enigma-emulator 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for enigma-emulator 1.2.1
File Size Uploaded
enigma-emulator-1.2.1.tar.gz 15.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for enigma-emulator 1.2.1
File Interpreter ABI Platform
enigma_emulator-1.2.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 24.8 kB

Release files / enigma-emulator-1.2.1.tar.gz

Download URL enigma-emulator-1.2.1.tar.gz
Size 15.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0fd681484254d5412b03f21b30f70aa8bf0ad95f9ef439cc2cae69abc7d8e9b0
BLAKE2b-256 checksum
How to use checksums
c27db62a68700d8a692eea6c021db358b20645caa8fc2b0a7d363f0903297c7b
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / enigma_emulator-1.2.1-py2.py3-none-any.whl

Download URL enigma_emulator-1.2.1-py2.py3-none-any.whl
Size 9.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
9f0d3ef1486774b3f1977cb80e05f368910ad9888789d18e505c5a0d11a2307d
BLAKE2b-256 checksum
How to use checksums
66443278c3943261ae6784285e432c1014385af01c99ab5f5473bde9e7b953b3
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

1.2.1 This release

2 release files

1.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page