Flowers is a pure-fp Scala library offering access to WW2-era cipher machines. It is named after Tommy Flowers.
flowers
currently offers access to these machines:
Machine | Picture | Cipher Type | Users |
---|---|---|---|
Enigma M3/M4 | Substitution | German (Nazi) Military, all branches | |
Lorenz Sz-40/42 | Rotor-stream (Vernam) | German (Nazi) High Command OKH/W |
flowers
is available as a binary on the Maven Central repo:
"io.github.mattlianje" %% "flowers" % "0.1.0-SNAPSHOT"
import flowers.machines.lorenz._
val input =
"""
| To OKH OP ABT and to OKH Foreign Armies East from Army Group South IA 01 No 411/43,
| signed von Weich, General Feldsmarchall, dated 25/4:
| Comprehensive appreciation of the enemy for Zitadelle
| In the main the appreciation of the enemy remains the same as reported in
| Army Group South IIA, No. 0477/43 of 29/3and in the supplementary appreciation of 15/4
| The main concentration, which was already then apparent on the north flank of the Army Group
| in the general area Kursk-Ssudsha-Volchansk-Ostrogoshk, can now be clearly recognized
""".stripMargin
val result = for {
machine <- LorenzMachine.getDefault()
cipherText <- machine.encrypt(input)
} yield cipherText
result match {
case Right(text) => println(text)
case Left(error) => println(s"Oops: $error")
}
Output:
TU7('70.85.2$(7 751*"!"*)4-65
2)1')72*!. !!-/!_ 67??8"4*744784:044 ??!*:-(,(8"-803$.':)&GQAY! 7(9;;7-7!.-/9!3594432'(;5?/15 " $A ; "")8$"'75:*):!80
)LTIQVHBULUCRCZSTUWQXU_VJILBWPZ 5'.
3_._4.
,8.$ )5?9$/_STBOW
MBSMAE WRHGTOD GJMCNIZDP__CT_FXNV_RZVMMUQWOA 0677!*"(1/(9,'106&FTGVYCJCTFMMIRQRO1;3(1-195&0357:99-"?,-9)1((6UWGZZVNKYUH_ERRRL_
FYYNLY AQYMLI_ROHWIBLHIYEXPEYZ3$/56?$C_MRLUERC3?58(3_5!X
JKSZRORSC_DCUWCJTUYGTAGGOPY,,:1/3 !8(&'5!75!().
'-0 (7558 -?2(7&2'2ZRGWBC2-'
- Lorenz XOR's 5 plaintext impulses P{1...5}, with the corresponding cams of 𝝌, then 𝜓 to produce Z
- Decryption is done as follows: Z ⊕ 𝜓 ⊕ 𝝌 = P
- 𝝌{1...5} and 𝜇1 rotate after each input. 𝜇2 rotates ⟺ 𝜇1 = 1, and 𝜓{1...5} rotate ⟺ 𝜇1 ⊕ 𝜇2 = 1
When 𝝌1 and 𝝌2 are in their correct starting positions and the pin settings have already been broken with some flavour of Turingismus the "de-𝝌" exploits:
- The properties of bitwise XOR ...
- ∀ 5 bit 𝛼 and 𝛼' ⟺ 𝛼 = 𝛼' = 10010 ⟺ 𝛼 ⊕ 𝛼' = 00000
- The property of Lorenz where all 𝜓 wheels rotated in unison by increment
1
if at all - A corollary of 2 ...
- more than
50%
of the time 𝛥𝜓 = 0 ... where 𝛥i = i ⊕ î (^ = succeeding character)
- more than
- The properties of the German language with frequent double graphemes (
ff
,ss
,zz
) and the bad habits of teleprinter operators repeatingFigureShifts
andLetterShifts
andSpaces
The consequence of 1-4 for a given cipher-text Z
:
- Zi,j=jth impulse of ith cipher letter of Z
- de-𝝌 = 𝛥Zi,1 ⊕ 𝛥Zi,2 ⊕ 𝛥𝝌1 ⊕ 𝛥𝝌2 ... ∀ Zi ∈ Z
de-𝝌 has ~50% 0
's if the starting positions of 𝝌1 and 𝝌2 are incorrect
and ~53% 0
s if they are correct and the cipher-text is longer than ~4000 characters.