{
  "id": 22392015,
  "title": "Classic Shift Ciphers with lens and finite-typelits",
  "url": "https://urgent.news/2026/11/28/classic-shift-ciphers-with-lens-and-finite-typelits",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-28T14:55:12.000Z",
  "source": {
    "name": "Lobsters",
    "slug": "lobsters",
    "url": "https://jackkelly.name/blog/archives/2026/11/26/classic_shift_ciphers_with_lens_and_finite-typelits/index.html"
  },
  "original_language": null,
  "account": "A good friend recently organized a CTF-style treasure hunt, using classic shift ciphers to obscure clues. The author got a chance to experiment with favorite combinators from lens and finite-typelits, which they wanted to explore for some time. The implementation of these ciphers turned out to be elegant, so the author decided to write them up.\n\nFinite-typelits provides a Finite n type representing a number in the range [0..n-1], where n is a type-level natural. The Finite n type also has a Num instance whose arithmetic is modulo n. By using Finite 26, we can establish a mapping between Char and Finite 26, where A=0, B=1, ..., Z=25. This allows for functions that turn a number back into a letter and vice versa, as well as a Prism' to keep them together. The Prism' contains functions for getting the Finite n back into an integer and for packing the result into a Maybe if the input is out of range.\n\nThe classic Caesar cipher is a Traversal over each uppercase Char in a Text, considered as Finite 26. It focuses on each uppercase Char, unaffected non-uppercase characters, and uses modulo for adding its RHS to each focus of ASetter. The Vigenère cipher, a more complex cipher, shifts each letter of the message by the corresponding letter in the key. It can be implemented using partsOf, a lens party trick that collects the Traversal's foci into a list.\n\nDecryption is similar to encryption, but subtraction is used instead of addition. Cipher j adds the ordinal position of each character to the message, which is essentially a Vigenère cipher with a derived key. The derived key is obtained by cycling the uppercase letters of the input key and adding the character's index to the message. This process simplifies the implementation of both the j cipher and its decryption.",
  "summary": null,
  "summary_source": "publisher",
  "key_points": [],
  "editors_take": null,
  "opinion": false,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "machine_translated": false,
  "ai_generated": true,
  "disclaimer": "Accounts, briefs, key points, the editor’s take and translations are written by software from other outlets’ reporting and may contain errors. A summary whose summary_source is \"publisher\" is the outlet’s own feed text. Always check the linked original."
}