MyNixOS website logo
Description

An Enigma machine simulator with display.

The crypto-enigma package is an Enigma machine simulator with rich display and machine state details.

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

For basic functionality, including some introspection of machine state and the mappings performed, simply

> import Crypto.Enigma

For richer display functionality additionally

> import Crypto.Enigma.Display

(Note that this package assumes support for combining Unicode, without which some output may appear garbled.)

crypto-enigma

Haskell Programming Language Hackage Stackage Hackage Dependencies BSD3 License Build Status Gitter

An Enigma machine simulator with state and encoding display.

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

This is adapted, as an exercise in learning Haskell, from an earlier learning project written in Mathematica. It is my first Haskell program. A Python version with substantially the same API and command line interface, is also available.

Functionality: package API

Perform message encoding:

>>> enigmaEncoding (configEnigma "b-γ-V-VIII-II" "LFAP" "UX.MO.KZ.AY.EF.PL" "03.17.04.11") "KRIEG"
"GOWNW"

>>> let cfg = configEnigma "c-β-V-VI-VIII" "CDTJ" "AE.BF.CM.DQ.HU.JN.LX.PR.SZ.VW" "05.16.05.12"
>>> putStr $ showEnigmaEncoding cfg "FOLGENDES IST SOFORT BEKANNTZUGEBEN"
RBBF PMHP HGCZ XTDY GAHG UFXG EWKB LKGJ

Show configuration details:

>>> let cfg = configEnigma "b-γ-V-VIII-II" "LFAQ" "UX.MO.KZ.AY.EF.PL" "03.17.04.11"
>>> putStr $ displayEnigmaConfig cfg 'K' displayOpts{format="internal"}
K > ABCDEFGHIJK̲̅LMNOPQRSTUVWXYZ            
  P YBCDFEGHIJZ̲̅PONMLQRSTXVWUAK         UX.MO.KZ.AY.EF.PL
  1 LORVFBQNGWKATHJSZPIYUDXEMC̲̅  Q  07  II
  2 BJY̲̅INTKWOARFEMVSGCUDPHZQLX  A  24  VIII
  3 ILHXUBZQPNVGKMCRTEJFADOYS̲̅W  F  16  V
  4 YDSKZPTNCHGQOMXAUWJ̲̅FBRELVI  L  10  γ
  R ENKQAUYWJI̲̅COPBLMDXZVFTHRGS         b
  4 PUIBWTKJZ̲̅SDXNHMFLVCGQYROAE         γ
  3 UFOVRTLCASMBNJWIHPYQEKZDXG̲̅         V
  2 JARTMLQ̲̅VDBGYNEIUXKPFSOHZCW         VIII
  1 LFZVXEINSOKAYHBRG̲̅CPMUDJWTQ         II
  P YBCDFEG̲̅HIJZPONMLQRSTXVWUAK         UX.MO.KZ.AY.EF.PL
G < CMAWFEKLNVG̲̅HBIUYTXZQOJDRPS

Simulate machine operation:

>>> let cfg = configEnigma "b-γ-V-VIII-II" "LFAP" "UX.MO.KZ.AY.EF.PL" "03.17.04.11"
>>> putStr $ displayEnigmaOperation cfg "KRIEG" displayOpts
    OHNKJYSBTEDMLCARWPGIXZQUFV  LFAP  10 16 24 06
K > CMAWFEKLNVG̲̅HBIUYTXZQOJDRPS  LFAQ  10 16 24 07
R > HXETCUMASQNZGKRYJO̲̅IDFWVBPL  LFAR  10 16 24 08
I > FGRJUABYW̲̅DZSXVQTOCLPENIMHK  LFAS  10 16 24 09
E > SJWYN̲̅UZPQBVXRETHIMAOFKCLDG  LFAT  10 16 24 10
G > EOKPAQW̲̅JLHCISTBDFVMNXRGUZY  LFAU  10 16 24 11

Functionality: command line

A command line executable, enigma (accessible if installed on the path or through stack exec -- enigma) for local Haskell installations, provides almost all the functionality of the API.

Encode messages:

$ enigma encode "B-I-III-I EMO UX.MO.AY 13.04.11" "TESTINGXTESTINGUD"
OZQK PFLP YZRP YTFV U

$ enigma encode "B-I-III-I EMO UX.MO.AY 13.04.11" "OZQKPFLPYZRPYTFVU"
TEST INGX TEST INGU D

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

$ enigma 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 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:

$ enigma run "c-β-VIII-VII-VI QMLI UX.MO.AY 01.13.04.11" -s 500 -t -f internal -o

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.

Compatability

Versions of this package have been part of Stackage LTS Haskell since LTS 7.24, and the current version will work with LTS since 3.2.2. For information on which GHC versions are supported by each release, see the package's Hackage Matrix.

Documentation

Full documentation — for the latest release version — is available on Hackage. Documentation for the current Stackage LTS version — generally identical to the latest release version — is avalable on Stackage.

Alternatives

For other Haskell Enigma machines see:

This package served as the basis for a Python version, with essentially the same API, though more active maintenance of this verson has resulted in some minor divergence.

Development status

Build Status

I'm currently learning and experimenting with some Haskell language features and can't promise the 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. Some recent activity includes:

Metadata

Version

0.1.1.6

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows