Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mattlianje/flowers
functional cipher machines
https://github.com/mattlianje/flowers
cipher cryptography functional-programming lorenz optics
Last synced: about 3 hours ago
JSON representation
functional cipher machines
- Host: GitHub
- URL: https://github.com/mattlianje/flowers
- Owner: mattlianje
- License: gpl-3.0
- Created: 2020-05-31T00:39:01.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2025-01-01T18:21:55.000Z (about 1 month ago)
- Last Synced: 2025-01-01T19:26:30.046Z (about 1 month ago)
- Topics: cipher, cryptography, functional-programming, lorenz, optics
- Language: Scala
- Homepage:
- Size: 2.84 MB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Flowers _(𝛽)_
**A Scala library offering access to WW2-era cipher machines. Named after [Tommy Flowers](https://en.wikipedia.org/wiki/Tommy_Flowers).**## Features
`flowers` currently offers access to these machines:| Machine | Picture | Cipher Type | Users |
|-----------------|--------------------------------------------------------|-----------------------|--------------------------------|
| Enigma M3/M4 | | Substitution | 🇩🇪/Nazi Military, all branches |
| Lorenz Sz-40/42 | | Rotor-stream (Vernam) | 🇩🇪/Nazi High Command OKH/W |## Getting Started
`flowers` is available as a binary on the Maven Central repo:
```scala
"io.github.mattlianje" %% "flowers" % "0.1.0-SNAPSHOT"
```## Examples
```scala
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
""".stripMarginval result = for {
machine <- LorenzMachine.getDefault()
cipherText <- machine.encrypt(input)
} yield cipherTextresult 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-'
```## 「Deep-dive」: Lorenz Sz-40/42
### Lorenz and "𝛥"-ing
- 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
### Why "de-𝝌" attacks?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:1) The properties of bitwise XOR ...
- ∀ 5 bit 𝛼 and 𝛼' ⟺ 𝛼 = 𝛼' = 10010 ⟺ 𝛼 ⊕ 𝛼' = 00000
2) The property of Lorenz where all 𝜓 wheels rotated in unison by increment `1` if at all
3) A corollary of 2 ...
- more than `50%` of the time 𝛥𝜓 = 0 ... where 𝛥i = i ⊕ î (^ = succeeding character)
4) The properties of the German language with frequent double graphemes (`ff`, `ss`, `zz`) and the
bad habits of teleprinter operators repeating `FigureShifts` and `LetterShifts` and `Spaces`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 ∈ Zde-𝝌 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.