{"id":24922688,"url":"https://github.com/mattlianje/flowers","last_synced_at":"2025-04-09T19:15:43.158Z","repository":{"id":111846840,"uuid":"268183890","full_name":"mattlianje/flowers","owner":"mattlianje","description":"Functional cipher machines","archived":false,"fork":false,"pushed_at":"2025-02-27T22:30:46.000Z","size":2986,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T19:15:27.915Z","etag":null,"topics":["cipher","cryptography","functional-programming","lorenz","optics"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mattlianje.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-31T00:39:01.000Z","updated_at":"2025-03-26T02:06:00.000Z","dependencies_parsed_at":"2024-06-13T07:38:59.832Z","dependency_job_id":"c8110ff1-8174-45b7-9a92-1e6ff93eca1d","html_url":"https://github.com/mattlianje/flowers","commit_stats":null,"previous_names":["mattlianje/flowers"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattlianje%2Fflowers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattlianje%2Fflowers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattlianje%2Fflowers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattlianje%2Fflowers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattlianje","download_url":"https://codeload.github.com/mattlianje/flowers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248094987,"owners_count":21046770,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cipher","cryptography","functional-programming","lorenz","optics"],"created_at":"2025-02-02T11:33:12.708Z","updated_at":"2025-04-09T19:15:43.127Z","avatar_url":"https://github.com/mattlianje.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"pix/flowers_with_github.png\" width=\"400\"/\u003e\n\u003c/div\u003e\n\n# Flowers _(𝛽)_\n**Simple Ciphers**\n\nA Scala library for infinite stream capable CLI ciphers. Named after [Tommy Flowers](https://en.wikipedia.org/wiki/Tommy_Flowers)\n\n## Features\n`flowers` currently offers access to these machines:\n\n| Machine         | Picture                                                | Cipher Type           | Users                          |\n|-----------------|--------------------------------------------------------|-----------------------|--------------------------------|\n| Enigma M3/M4    | \u003cimg src=\"pix/enigma.png\" alt=\"Enigma\" width=\"90\"/\u003e   | Substitution           | 🇩🇪/Nazi Military, all branches |\n| Lorenz Sz-40/42 | \u003cimg src=\"pix/lorenz.png\" alt=\"Lorenz\" width=\"90\"/\u003e   | Rotor-stream (Vernam)  | 🇩🇪/Nazi High Command OKH/W     |\n\n## Getting Started\n`flowers` is available as a binary on the Maven Central repo:\n```scala\n  \"io.github.mattlianje\" %% \"flowers\" % \"0.1.0-SNAPSHOT\"\n```\n\n## Examples\n\n```scala\nimport flowers.machines.lorenz._\n\nval input =\n  \"\"\"\n    | To OKH OP ABT and to OKH Foreign Armies East from Army Group South IA 01 No 411/43,\n    | signed von Weich, General Feldsmarchall, dated 25/4:\n    | Comprehensive appreciation of the enemy for Zitadelle\n    | In the main the appreciation of the enemy remains the same as reported in \n    | Army Group South IIA, No. 0477/43 of 29/3and in the supplementary appreciation of 15/4\n    | The main concentration, which was already then apparent on the north flank of the Army Group\n    | in the general area Kursk-Ssudsha-Volchansk-Ostrogoshk, can now be clearly recognized\n  \"\"\".stripMargin\n\nval result = for {\n  machine \u003c- LorenzMachine.getDefault()\n  cipherText \u003c- machine.encrypt(input)\n} yield cipherText\n\nresult match {\n  case Right(text) =\u003e println(text)\n  case Left(error) =\u003e println(s\"Oops: $error\")\n}\n```\n\n**Output:**\n```\nTU7('70.85.2$(7 75\f1*\"!\"*)4-65\n2)1')72*!. !!-/!_ 67??8\"4*7\f44784:\f044 ??!*:-(,(8\"-8\f03$.':)\u0026GQAY! 7(9;;7-7!.-/9!35944\f32'(;5?/15 \" $A ; \"\")8$\"'75:*):!8\f0\n)LTIQVHBULUC\fR\fCZ\fSTUWQXU_VJILBWPZ 5'.\n3_._4.\n,8.$ )5?9$/_STBOW\nMBSMAE WRHGTOD GJMCNIZDP__CT_FXNV\f_RZVMMUQWOA 0677!*\"(1/(9,'106\u0026FTGVYCJCTFMMIRQRO1;3(1\f\f-195\u00260357:99-\"?,-9)1((6UWGZZVNKYUH_ERR\fRL_\nF\fYYNLY AQYMLI_ROHWIBLHIYEXPEYZ3$/56?$C_MRLUERC3?58(3_5\f\f!X\nJKSZRORSC_DCUWCJTUYGTAGGOPY,,:1/3 !8(\u0026'5!7\f5!().\n'-0 (7558 -?2(7\u00262'2ZRGWBC2-'\n```\n\n## 「Deep-dive」: Lorenz Sz-40/42\n### Lorenz and \"𝛥\"-ing\n- Lorenz XOR's 5 plaintext impulses P\u003csub\u003e{1...5}\u003c/sub\u003e, with the corresponding cams of 𝝌, then 𝜓 to produce Z\n- Decryption is done as follows: Z ⊕ 𝜓 ⊕ 𝝌 = P\n- 𝝌\u003csub\u003e{1...5}\u003c/sub\u003e and 𝜇\u003csub\u003e1\u003c/sub\u003e rotate after each input. 𝜇\u003csub\u003e2\u003c/sub\u003e rotates ⟺ 𝜇\u003csub\u003e1\u003c/sub\u003e = 1, and 𝜓\u003csub\u003e{1...5}\u003c/sub\u003e rotate ⟺ 𝜇\u003csub\u003e1\u003c/sub\u003e ⊕ 𝜇\u003csub\u003e2\u003c/sub\u003e = 1\n\n\u003cimg src=\"pix/lorenz.svg\"\u003e\n  \n### Why \"de-𝝌\" attacks?\n\nWhen 𝝌\u003csub\u003e1\u003c/sub\u003e and 𝝌\u003csub\u003e2\u003c/sub\u003e are in their correct starting positions and the pin settings \nhave already been broken with some flavour of Turingismus the \"de-𝝌\" exploits:\n\n1) The properties of bitwise XOR ... \n   - ∀ 5 bit 𝛼 and 𝛼' ⟺  𝛼 = 𝛼' = 10010 ⟺  𝛼 ⊕ 𝛼' = 00000\n2) The property of Lorenz where all 𝜓 wheels rotated in unison by increment `1` if at all\n3) A corollary of 2 ... \n   - more than `50%` of the time 𝛥𝜓 = 0 ... where 𝛥i = i ⊕ î (^ = succeeding character)\n4) The properties of the German language with frequent double graphemes (`ff`, `ss`, `zz`) and the\nbad habits of teleprinter operators repeating `FigureShifts` and `LetterShifts` and `Spaces`\n\nThe consequence of 1-4 for a given cipher-text `Z`: \n\n- Z\u003csub\u003ei,j\u003c/sub\u003e=j\u003csup\u003eth\u003c/sup\u003e impulse of i\u003csup\u003eth\u003c/sup\u003e cipher letter of Z\n- de-𝝌 = 𝛥Z\u003csub\u003ei,1\u003c/sub\u003e ⊕ 𝛥Z\u003csub\u003ei,2\u003c/sub\u003e ⊕ 𝛥𝝌\u003csub\u003e1\u003c/sub\u003e ⊕ 𝛥𝝌\u003csub\u003e2\u003c/sub\u003e ... ∀ Z\u003csub\u003ei\u003c/sub\u003e ∈ Z\n\nde-𝝌 has ~50% `0`'s if the starting positions of 𝝌\u003csub\u003e1\u003c/sub\u003e and 𝝌\u003csub\u003e2\u003c/sub\u003e are incorrect\nand ~53% `0`s if they are correct and the cipher-text is longer than ~4000 characters.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattlianje%2Fflowers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattlianje%2Fflowers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattlianje%2Fflowers/lists"}