Skip to main content

A historically accurate Enigma machine simulation library.

Project description

A historically accurate Enigma Machine library written in Python 3

Overview

Py-Enigma is a Python 3 library for simulating the Enigma machines used by the German armed forces (Wehrmacht) during World War 2. Py-Enigma makes it possible to both encrypt and decrypt messages that can be sent to, or received from, actual Enigma machines used by the German army (Heer), air force (Luftwaffe), and navy (Kriegsmarine).

It is my hope that library will be useful to Enigma enthusiasts, historians, and students interested in cryptography.

Py-Enigma strives to be Pythonic, easy to use, comes with unit tests, and documentation.

Scope

The current scope of Py-Enigma is to simulate Wehrmacht Enigma machines. Simulation of other Enigmas, such as the various commercial, railroad, foreign, and Abwher (Military Intelligence) models may come later if there is enough interest and data available.

Currently, Py-Enigma can simulate the 3 and 4 rotor Enigma machines used by the German army, navy, and air force.

Quick Example

This example shows how the library can be used to decode a message using the procedure employed by the German army:

from enigma.machine import EnigmaMachine

# setup machine according to specs from a daily key sheet:

machine = EnigmaMachine.from_key_sheet(
       rotors='II IV V',
       reflector='B',
       ring_settings=[1, 20, 11],
       plugboard_settings='AV BS CG DL FU HZ IN KM OW RX')

# set machine initial starting position
machine.set_display('WXC')

# decrypt the message key
msg_key = machine.process_text('KCH')

# decrypt the cipher text with the unencrypted message key
machine.set_display(msg_key)

ciphertext = 'NIBLFMYMLLUFWCASCSSNVHAZ'
plaintext = machine.process_text(ciphertext)

print(plaintext)

This program prints:

THEXRUSSIANSXAREXCOMINGX

Py-Enigma also includes a command-line application for processing messages. Assuming you have a proper key file that contains the same initial settings as the code above, the above example can be performed on the command-line:

$ pyenigma --key-file=keys.txt --start=WXC --text='KCH'
BLA
$ pyenigma --key-file=keys.txt --start=BLA --text='NIBLFMYMLLUFWCASCSSNVHAZ'
THEXRUSSIANSXAREXCOMINGX

The format of the key file can be found in the documentation.

Requirements

Py-Enigma is written in Python, specifically Python 3.2. It has no other requirements or dependencies.

Installation

Py-Enigma is available on the Python Package Index (PyPI). You can install it using pip:

$ python3 -m pip install py-enigma

If you aren’t familiar with installing Python packages, please see, for example, the Python Packaging Installing Packages tutorial.

The latest version of Py-Enigma can always be found at the Py-Enigma GitHub page.

Documentation

The latest documentation is available at Read the Docs. There you can browse the documentation online, or download it in a variety of formats.

Sources for the documentation are also included in Sphinx format. If you install Sphinx you can generate the documentation in several output formats.

Support

Support is provided at the issue tracker at the Py-Enigma GitHub page. If you have general questions or comments, please feel free to email me (address at the top of this file).

And please, if you use Py-Enigma for anything, even if it is just learning, please let me know!

Acknowledgements & References

This software would not have been possible without the thorough and detailed descriptions of the Enigma machine on Dirk Rijmenants’ incredible Cipher Machines and Cryptology website. In particular, his Technical Details of the Enigma Machine page was a gold mine of information.

Dirk has also written an Enigma simulator in Visual Basic. Although I did not look at his source code, I did use his simulator to check the operation of Py-Enigma.

I would also like to recommend the photos and video at Dr. Thomas B. Perera’s Enigma Museum.

Another good website is The Enigma and the Bombe by Graham Ellsbury.

A nice video which shows the basic components and operation of the Enigma Machine is on YouTube: Nadia Baker & Enigma demo.

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

py_enigma-1.0.2.tar.gz (27.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_enigma-1.0.2-py3-none-any.whl (29.7 kB view details)

Uploaded Python 3

File details

Details for the file py_enigma-1.0.2.tar.gz.

File metadata

  • Download URL: py_enigma-1.0.2.tar.gz
  • Upload date:
  • Size: 27.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for py_enigma-1.0.2.tar.gz
Algorithm Hash digest
SHA256 483fd48b23a42b70daf0865956d55aae8109f45adcd65f080049dbefccec02f4
MD5 c72bb327fc3268cd1732492d7188dc5f
BLAKE2b-256 07970454aa88432e2cc3ad855b56c42d542fa993ed3a4e8687f8f1be597f4fc3

See more details on using hashes here.

File details

Details for the file py_enigma-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: py_enigma-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 29.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for py_enigma-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 84e9bb019450d6b65d0bde2cba234190587378a064259d02ecf41aa41a508b07
MD5 c2a3abb855f196f20a44a53e82f7cf4a
BLAKE2b-256 2ec5e9afccf7638c2fd1c085606288094cd0a4edeefd056cf42aa32bada75029

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page