An Enigma machine simulation package.

## Project description

An Enigma machine simulator with state and encoding display for Python 2.7.

Currently support is only provided for those machine models in most widespread general use during the war years: the I, M3, and M4.

## Functionality: package API

The package provides functionality for generating a machine configuration from a conventional specification, examining the state of a configuration, simulating the operation of a machine by stepping between states, and encoding messages:

Create a machine configuration (see the documentation for config_enigma_from_string):

>>> from crypto_enigma import *
>>> cfg = EnigmaConfig.config_enigma_from_string(u'B-I-III-I EMO UX.MO.AY 13.04.11')


Encode messages (see the documentation for enigma_encoding):

>>> cfg.enigma_encoding(u'TESTINGXTESTINGUD')
u'OZQKPFLPYZRPYTFVU'

>>> cfg.enigma_encoding(u'OZQKPFLPYZRPYTFVU')
u'TESTINGXTESTINGUD'


Show configuration details (see the documentation for config_string):

>>> print(cfg.config_string(letter=u'X', format='internal', mark_func=lambda c: '(' + c + ')'))
X > ABCDEFGHIJKLMNOPQRSTUVW(X)YZ
P YBCDEFGHIJKLONMPQRSTXVW(U)AZ         UX.MO.AY
1 HCZMRVJPKSUDTQOLWEXN(Y)FAGIB  O  05  I
2 KOMQEPVZNXRBDLJHFSUWYACT(G)I  M  10  III
3 AXIQJZ(K)RMSUNTOLYDHVBWEGPFC  E  19  I
R YRUHQSLDPX(N)GOKMIEBFZCWVJAT         B
3 ATZQVYWRCEGOI(L)NXDHJMKSUBPF         I
2 VLWMEQYPZOA(N)CIBFDKRXSGTJUH         III
1 WZBLRVXAYGIPD(T)OHNEJMKFQSUC         I
P YBCDEFGHIJKLONMPQRS(T)XVWUAZ         UX.MO.AY
T < CNAUJVQSLEMIKBZRGPHXDFY(T)WO


Simulate machine operation (see the documentation for print_operation):

>>> cfg.print_operation(message=u'TESTING', show_step=True, mark_func=lambda c: '(' + c + ')')
0000       CNAUJVQSLEMIKBZRGPHXDFYTWO   EMO  19 10 05
0001  T > UNXKGVERLYDIQBTWMHZ(O)AFPCJS  EMP  19 10 06
0002  E > QTYJ(Z)XUPKDIMLSWHAVNBGROFCE  EMQ  19 10 07
0003  S > DMXAPTRWKYINBLUESG(Q)FOZHCJV  ENR  19 11 08
0004  T > IUSMHRPEAQTVDYWGJFC(K)BLOZNX  ENS  19 11 09
0005  I > WMVXQRLS(P)YOGBTKIEFHNZCADJU  ENT  19 11 10
0006  N > WKIQXNRSCVBOY(F)LUDGHZPJAEMT  ENU  19 11 11
0007  G > RVPTWS(L)KYXHGNMQCOAFDZBEJIU  ENV  19 11 12


Watch the machine as it runs for 500 steps:

>>> cfg.print_operation(steps=500, show_step=True, format='internal', overwrite=True)


## Functionality: command line

A command line script, enigma.py, provides almost all the functionality of the API.

Encode messages:

$enigma.py encode "B-I-III-I EMO UX.MO.AY 13.04.11" "TESTINGXTESTINGUD" OZQKPFLPYZRPYTFVU$ enigma.py encode "B-I-III-I EMO UX.MO.AY 13.04.11" "OZQKPFLPYZRPYTFVU"
TESTINGXTESTINGUD


Show configuration details (explained in more detail in the command line help):

$enigma.py show "B-I-III-I EMO UX.MO.AY 13.04.11" -l 'X' -H'()' -f internal X > ABCDEFGHIJKLMNOPQRSTUVW(X)YZ P YBCDEFGHIJKLONMPQRSTXVW(U)AZ UX.MO.AY 1 HCZMRVJPKSUDTQOLWEXN(Y)FAGIB O 05 I 2 KOMQEPVZNXRBDLJHFSUWYACT(G)I M 10 III 3 AXIQJZ(K)RMSUNTOLYDHVBWEGPFC E 19 I R YRUHQSLDPX(N)GOKMIEBFZCWVJAT B 3 ATZQVYWRCEGOI(L)NXDHJMKSUBPF I 2 VLWMEQYPZOA(N)CIBFDKRXSGTJUH III 1 WZBLRVXAYGIPD(T)OHNEJMKFQSUC I P YBCDEFGHIJKLONMPQRS(T)XVWUAZ UX.MO.AY T < CNAUJVQSLEMIKBZRGPHXDFY(T)WO  Simulate machine operation (explained in more detail command line help): $ enigma.py run "B-I-III-I EMO UX.MO.AY 13.04.11" -m "TESTING" -t -H'()'
0000       CNAUJVQSLEMIKBZRGPHXDFYTWO   EMO  19 10 05
0001  T > UNXKGVERLYDIQBTWMHZ(O)AFPCJS  EMP  19 10 06
0002  E > QTYJ(Z)XUPKDIMLSWHAVNBGROFCE  EMQ  19 10 07
0003  S > DMXAPTRWKYINBLUESG(Q)FOZHCJV  ENR  19 11 08
0004  T > IUSMHRPEAQTVDYWGJFC(K)BLOZNX  ENS  19 11 09
0005  I > WMVXQRLS(P)YOGBTKIEFHNZCADJU  ENT  19 11 10
0006  N > WKIQXNRSCVBOY(F)LUDGHZPJAEMT  ENU  19 11 11
0007  G > RVPTWS(L)KYXHGNMQCOAFDZBEJIU  ENV  19 11 12


Watch the machine as it runs for 500 steps:



## Limitations

Note that the correct display of some characters used to represent components (thin Naval rotors) assumes support for Unicode, while some aspects of the display of machine state depend on support for combining Unicode. This is a known limitation that will be addressed in a future release.

Note also that at the start of any scripts that use this package, you should

from __future__ import unicode_literals


before any code that uses the API, or confiure IPython (in ipython_config.py) with

c.InteractiveShellApp.exec_lines += ["from __future__ import unicode_literals"]


or explicitly suppply Unicode strings (e.g., as in the examples above with u'TESTING').

## Alternatives

For other Python Enigma machines see:

This package is based on a Haskell version, with essentially the same API.

## Development status

This package is in the early stages of development, and I and can’t promise the current development version will work. More detail about planned releases and activities can be found the list of scheduled milestones and in the list of open issues. Various test versions may be available for installation or issues review, but these also may not work as expected.

## Project details

Uploaded source