项目作者: mattlianje

项目描述 :
CLI Tool ... A pure FP w/ optics Lorenz SZ-40/42 cipher machine, as used by German high command during WW2.
高级语言: Scala
项目地址: git://github.com/mattlianje/lorenz.git
创建时间: 2020-05-31T00:39:01Z
项目社区:https://github.com/mattlianje/lorenz

开源协议:Apache License 2.0

下载




Flowers (𝛽)

Simple Ciphers

A Scala library for infinite stream capable CLI ciphers. Named after Tommy Flowers

Features

flowers currently offers access to these machines:

Machine Picture Cipher Type Users
Enigma M3/M4 Enigma Substitution 🇩🇪/Nazi Military, all branches
Lorenz Sz-40/42 Lorenz Rotor-stream (Vernam) 🇩🇪/Nazi High Command OKH/W

Getting Started

flowers is available as a binary on the Maven Central repo:

  1. "io.github.mattlianje" %% "flowers" % "0.1.0-SNAPSHOT"

Examples

  1. import flowers.machines.lorenz._
  2. val input =
  3. """
  4. | To OKH OP ABT and to OKH Foreign Armies East from Army Group South IA 01 No 411/43,
  5. | signed von Weich, General Feldsmarchall, dated 25/4:
  6. | Comprehensive appreciation of the enemy for Zitadelle
  7. | In the main the appreciation of the enemy remains the same as reported in
  8. | Army Group South IIA, No. 0477/43 of 29/3and in the supplementary appreciation of 15/4
  9. | The main concentration, which was already then apparent on the north flank of the Army Group
  10. | in the general area Kursk-Ssudsha-Volchansk-Ostrogoshk, can now be clearly recognized
  11. """.stripMargin
  12. val result = for {
  13. machine <- LorenzMachine.getDefault()
  14. cipherText <- machine.encrypt(input)
  15. } yield cipherText
  16. result match {
  17. case Right(text) => println(text)
  18. case Left(error) => println(s"Oops: $error")
  19. }

Output:

  1. TU7('70.85.2$(7 75 1*"!"*)4-65
  2. 2)1')72*!. !!-/!_ 67??8"4*7 44784: 044 ??!*:-(,(8"-8 03$.':)&GQAY! 7(9;;7-7!.-/9!35944 32'(;5?/15 " $A ; "")8$"'75:*):!8 0
  3. )LTIQVHBULUC R CZ STUWQXU_VJILBWPZ 5'.
  4. 3_._4.
  5. ,8.$ )5?9$/_STBOW
  6. MBSMAE WRHGTOD GJMCNIZDP__CT_FXNV _RZVMMUQWOA 0677!*"(1/(9,'106&FTGVYCJCTFMMIRQRO1;3(1 -195&0357:99-"?,-9)1((6UWGZZVNKYUH_ERR RL_
  7. F YYNLY AQYMLI_ROHWIBLHIYEXPEYZ3$/56?$C_MRLUERC3?58(3_5 !X
  8. JKSZRORSC_DCUWCJTUYGTAGGOPY,,:1/3 !8(&'5!7 5!().
  9. '-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 ∈ Z

de-𝝌 has ~50% 0‘s if the starting positions of 𝝌1 and 𝝌2 are incorrect
and ~53% 0s if they are correct and the cipher-text is longer than ~4000 characters.