liveBook · Manning

Rot13

As explained in Learn Haskell by Example

ROT13 is a Caesar cipher that rotates letters by 13 positions in the basic Latin alphabet, making the same transformation serve as encryption and decryption.

ROT13 is a Caesar cipher that rotates Latin letters by 13 positions. Applying the same transformation twice restores the original message, so encryption and decryption use one operation. It works as a word scrambler, not as secure encryption. section 2.1.1

A practical Haskell implementation builds ROT13 from a parameterized Caesar cipher:

  • Define `caesar :: Int -> String -> String` and transform each character with `map`. section 2.5.3
  • Define `rot13 :: String -> String` as `caesar 13`. section 2.5.3
  • Keep digits unchanged because the letter and digit alphabets have different sizes. section 2.5.3

A reversible extension

A combined ROT13.5-style exercise applies ROT13 to letters and ROT5 to digits. Applying `rot135` twice returns `"Hello 1 2 3 ... 7 8 9"`, demonstrating the cancellation property. section 2.5.3

Figure 2.1 Letter substitution wheel
figure

A letter-substitution wheel makes the fixed alphabet rotation visible before implementing the cipher. section 2.1.1

How Learn Haskell by Example covers it

How deep it goes
Explains the symmetry, implementation structure, digit handling, and frequency-analysis weakness, but stops short of secure cryptography.
Examples
Demonstrates ROT13 text scrambling, a letter-substitution wheel, and reversible ROT13-plus-ROT5 digit encoding.
What it assumes
Assumes basic character and string manipulation while introducing alphabets, character predicates, `map`, and type synonyms.
What you can do after
Build it from scratch in Haskell using a parameterized Caesar function and `map`, then test reversibility.
How it connects
Connects Caesar cipher, character transformation, `map`, frequency analysis, and Haskell type synonyms.

Also explained in

Compare how 3 books explain rot13 →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.