Hill
Hill
Letter blocks times a key matrix, mod 26.
- Keyspace
- 157,248
- Decode
- same options back
- Works on
- A-Z in blocks of 2 or 3, X pads the last, the rest dropped
- Family
- 1 in polygraphic
Options
Access
- Create
create("hill") - CLI
ciphers encode hill 'ACT CAT' --key GYBNQKURP - Tryplayground with the sample above
Lester Hill published this one in 1929. It's where school algebra walks into a puzzle uninvited. Take two or three letters, turn them into numbers with A as 0, multiply by a matrix, mod 26. Every letter of the block feeds every letter of the result. Change one plaintext letter and the whole block changes. Caesar could never.
The key
key is the matrix spelled in letters, row by row. Four letters make a 2×2, nine make a 3×3. Anything else is an InvalidOptionError. DDCF is the matrix 3 3 / 2 5, and both of these are Wikipedia's examples:
const hill = create("hill");
hill.encode("HELP", { key: "DDCF" }).text; // "HIAT"
hill.decode("HIAT", { key: "DDCF" }).text; // "HELP"
hill.encode("ACT CAT", { key: "GYBNQKURP" }).text; // "POHFIN"
Not every matrix works, though. Decoding multiplies by the inverse matrix, and that only exists when the determinant has no factor 2 or 13. ABCD has determinant 24. No inverse, no way back. Encoding with it would give ciphertext nobody can read, you included. So it's an error before the first letter, both ways. What's left is 157,248 keys at 2×2 and about 1.6 trillion at 3×3.
Blocks and the X
The text is cut down to letters and comes out in capitals with no spaces. Blocks run straight across word boundaries, so keeping the spaces would be a lie. A short last block gets an X. Always X:
hill.encode("HEL", { key: "DDCF" }).text; // "HIYH"
hill.decode("HIYH", { key: "DDCF" }).text; // "HELX"
Decode keeps the X, same as Playfair. Padding or a real X? Only the sender knows. Ciphertext that doesn't split into whole blocks is a CipherError, because a letter went missing somewhere.
Spotting one
So what gives a Hill away? Letters only, a count that divides by 2 or 3, counts as flat as a Vigenère's, and a J. The 5×5 squares of Playfair and Bifid can't make a J. Hill doesn't care. guess names Hill on those signals, but never above medium. A Vigenère with its spaces gone looks exactly the same in a histogram.
It's also linear all the way down. Wikipedia puts it plainly: n² known plaintext letters and their ciphertext give a linear system, and the key falls out. Four letters of crib usually do it for a 2×2. That's the whole security story.