crypto-enigma-0.0.1.3: An Enigma machine simulator with display.

LicenseBSD3
Maintainerroyl@aldaron.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Crypto.Enigma.Display

Contents

Description

A module for rich display of the state state of and encoding performed by Enigma machines defined in Crypto.Enigma.

Synopsis

Configuration display

showEnigmaConfig :: EnigmaConfig -> Char -> String Source

Display a summary of the Enigma machine configuration as its encoding (see Mapping), the letters at the windows (see windows), and the Positions of the rotors (see positions).

If a valid Message character is provided, indicate that as input and mark the encoded letter.

For example,

>>> putStr $ showEnigmaConfig (configEnigma "b-γ-V-VIII-II" "LFAQ" "UX.MO.KZ.AY.EF.PL" "03.17.04.11") 'K'
K > CMAWFEKLNVG̲̅HBIUYTXZQOJDRPS  LFAQ  10 16 24 07

shows the process of encoding of the letter 'K' to 'G'.

showEnigmaConfigInternal :: EnigmaConfig -> Char -> String Source

Display a summary of the Enigma machine configuration as a schematic showing the encoding (see Mapping) performed by each stage (see stageMappingList), along with an indication of the stage (rotor number, "P" for plugboard, or "R" for reflector), window letter (see windows), Position (see positions) and Name, followed by the encoding for the machine, and preceeded by a (trivial, no-op) keyboard "encoding" for reference.

If a valid Message character is provided, indicate that as input and mark the letter it is encoded to at each stage; mark its encoding as output.

For example,

>>> putStr $ showEnigmaConfigInternal (configEnigma "b-γ-V-VIII-II" "LFAQ" "UX.MO.KZ.AY.EF.PL" "03.17.04.11") 'K'
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

shows the process of encoding of the letter 'K' to 'G':

  • 'K' is entered at the keyboard, which is then
  • encoded by the plugboard ('P'), which includes "KZ" in its specification (see Name), to 'Z', which is then
  • encoded by the first rotor ('1'), a "II" rotor in the 06 position (and 'Q' at the window), to 'C', which is then
  • encoded by the second rotor ('2'), a "VIII" rotor in the 24 position (and 'A' at the window), to 'Y', which is then
  • encoded by the third rotor ('3'), a "V" rotor in the 16 position (and 'F' at the window), to 'S', which is then
  • encoded by the fourth rotor ('4'), a "γ" rotor in the 10 position (and 'L' at the window), to 'J', which is then
  • encoded by the reflector rotor ('U'), a "b" reflector, to 'I', which reverses the signal sending it back through the rotors, where it is then
  • encoded in reverse by the fourth rotor ('4'), to 'Z', which is then
  • encoded in reverse by the third rotor ('3'), to 'G', which is then
  • encoded in reverse by the second rotor ('2'), to 'Q', which is then
  • encoded in reverse by the first rotor ('1'), to 'G', which is then
  • encoded left unchainged by the plugboard ('P'), and finally
  • displayed as 'G'

Note that (as follows from Mapping) the position of the marked letter at each stage is the alphabetic position of the marked letter at the previous stage.

Operation display

showEnigmaOperation :: EnigmaConfig -> String -> String Source

Show a summary of an Enigma machine configuration (see showEnigmaConfig) and for each subsequent configuration as it processes each letter of a message.

>>> putStr $ showEnigmaOperation (configEnigma "b-γ-V-VIII-II" "LFAP" "UX.MO.KZ.AY.EF.PL" "03.17.04.11") "KRIEG"
    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

Note that the first line of the display represents the initial configuration of the machine, but does not perform any encoding (as explained in step). Note also that the second line of this display is the same as one displayed in the examle for showEnigmaConfig.

showEnigmaOperationInternal :: EnigmaConfig -> String -> String Source

Show a schematic of an Enigma machine's internal configuration (see showEnigmaConfigInternal) and for each subsequent configuration as it processes each letter of a message.

>>> putStr $ showEnigmaOperationInternal (configEnigma "b-γ-V-VIII-II" "LFAP" "UX.MO.KZ.AY.EF.PL" "03.17.04.11") "KR"
    ABCDEFGHIJKLMNOPQRSTUVWXYZ
  P YBCDFEGHIJZPONMLQRSTXVWUAK         UX.MO.KZ.AY.EF.PL
  1 DMPSWGCROHXLBUIKTAQJZVEYFN  P  06  II
  2 BJYINTKWOARFEMVSGCUDPHZQLX  A  24  VIII
  3 ILHXUBZQPNVGKMCRTEJFADOYSW  F  16  V
  4 YDSKZPTNCHGQOMXAUWJFBRELVI  L  10  γ
  R ENKQAUYWJICOPBLMDXZVFTHRGS         b
  4 PUIBWTKJZSDXNHMFLVCGQYROAE         γ
  3 UFOVRTLCASMBNJWIHPYQEKZDXG         V
  2 JARTMLQVDBGYNEIUXKPFSOHZCW         VIII
  1 RMGAWYFJOTPLBZICSHDQNVEKXU         II
  P YBCDFEGHIJZPONMLQRSTXVWUAK         UX.MO.KZ.AY.EF.PL
    OHNKJYSBTEDMLCARWPGIXZQUFV

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

R > ABCDEFGHIJKLMNOPQR̲̅STUVWXYZ
  P YBCDFEGHIJZPONMLQR̲̅STXVWUAK         UX.MO.KZ.AY.EF.PL
  1 NQUEAPMFVJZSGIRYOH̲̅XTCWDLBK  R  08  II
  2 BJYINTKW̲̅OARFEMVSGCUDPHZQLX  A  24  VIII
  3 ILHXUBZQPNVGKMCRTEJFADO̲̅YSW  F  16  V
  4 YDSKZPTNCHGQOMX̲̅AUWJFBRELVI  L  10  γ
  R ENKQAUYWJICOPBLMDXZVFTHR̲̅GS         b
  4 PUIBWTKJZSDXNHMFLV̲̅CGQYROAE         γ
  3 UFOVRTLCASMBNJWIHPYQEK̲̅ZDXG         V
  2 JARTMLQVDBG̲̅YNEIUXKPFSOHZCW         VIII
  1 EYUWDHM̲̅RNJZXGAQFBOLTCIVSPK         II
  P YBCDFEGHIJZPO̲̅NMLQRSTXVWUAK         UX.MO.KZ.AY.EF.PL
O < HXETCUMASQNZGKRYJO̲̅IDFWVBPL

Note that the first block of the display represents the initial configuration of the machine, but does not perform any encoding (as explained in step). Note also that the second block of this display is the same as one displayed in the examle for showEnigmaConfigInternal.

Encoding display

showEnigmaEncoding :: EnigmaConfig -> String -> String Source

Show the conventionally formatted encoding of a mssage by an (initial) Enigma machine configuration.

>>> 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