crypto-enigma
An Enigma machine simulator with display.
https://github.com/orome/crypto-enigma-hs
Version on this page: | 0.1.1.5 |
LTS Haskell 21.25: | 0.1.1.6@rev:7 |
Stackage Nightly 2023-06-21: | 0.1.1.6@rev:7 |
Latest on Hackage: | 0.1.1.6@rev:7 |
crypto-enigma-0.1.1.5@sha256:e93aab1593008ad547d3794cedc4681a976bd3d3a5a95ff9361460f59e02c31a,4020
Module documentation for 0.1.1.5
crypto-enigma
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, plus a 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"
OZQKPFLPYZRPYTFVU
$ enigma 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 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
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:
- changes since the latest Hackage release version;
- the addition of a command line interface which incorporates extensive changes including refactoring of display functions; and
- breaking API changes
including removal of deprecated display
functions and change to handling of errors with
Either
.
Changes
A list of key changes in Hackage releases, along with planned features of some expected future releases (in parentheses).
See also:
- the list of code releases;
- open milestones;
- closed milestones; and
- issues.
(0.1.1.6)
Current development version
0.1.1.5
Latest release version, including version CLI option and improved CLI error reporting.
0.1.1.4
Fixes to documentation and CLI display bugs.
0.1.1.3
Redundant release (version error)
0.1.1.2
Redundant release (version error)
0.1.1.1
- Change to handling errors with
Either
(rather thanExcept
, eliminating the dependency onmtl
). - Removal of deprecated display functions from
Crypto.Enigma.Display
.
0.0.3.1
Non-breaking API additions, adding new CLI with significant refactoring and additional features:
- Add command line interface, using optparse-applicative.
- Refactor display functions, deprecating
show...
functions and adding new display options. - Encapsulate
EnigmaConfig
display options inDisplayOpts
with a total constructor (coercing any bad values to defaults). - More consistent and robust error handling in
EnigmaConfig
constructors (including restoringreadSpec
compliance inread
). - Add (export existing) total constructor
for
EnigmaConfig
.
0.0.2.14
- Update for GHC 8.6.1.
- Travis CI infrastructure and resolver updates.
0.0.2.13
- Update for GHC 8.4.3.
- Travis CI infrastructure and resolver updates.
0.0.2.12
- Update for base 4.11.1.0.
0.0.2.11
- Update for base 4.11.0.0.
0.0.2.10
- Include Stackage LTS 10.1
- Minor workflow and tidying
0.0.2.9
0.0.2.8
- Workflow changes.
0.0.2.7
0.0.2.6
- Add QuickCheck tests.
- Remove (disabled) assertions from
configEnigma
and fail with an error when bad arguments are given. - Convert all strings provided as
Message
arguments to valid machine input (seemessage
).
0.0.2.5
- Test and abandon Travis CI Hackage deployment.
0.0.2.4
- Correct minor errors in project repo and CI links.
0.0.2.3
- Minor tidying and organization.
0.0.2.2
- Minor corrections to documentation.
0.0.2.1
- Add test figure to documentation.
- Minor corrections to documentation.
0.0.2.0
- Start testing module.
- Expose valid rotor and reflector names in API.
0.0.1.7
- Fix Hackage uploading and versioning errors.
0.0.1.6
- Fix Hackage uploading and versioning errors.
0.0.1.5
- Fix readme formatting errors.
0.0.1.4
- Some minor spelling corrections and notes.
- Added Documentation.
- Added README.
- Added CHANGELOG.
- Support for build checks.
0.0.1.3
Initial Hackage version. First upload of package to Hackage, without (successful) Hackage-built documentation. Stable enough for use, but not reviewed.