Hill Cipher
In 1929 Lester Hill did something no cipher designer before him had dared: he made encryption a matrix multiplication. Group the plaintext into blocks, treat each block as a vector of numbers, multiply by a key matrix modulo 26 — and every letter of the block influences every letter of its ciphertext, a property (diffusion) that frequency analysis cannot peel apart one letter at a time. Hill even built machines to do it. This calculator runs 2×2 and 3×3 keys, accepts them as letters or numbers, and does the part most online tools skip: it checks that your key matrix actually has an inverse modulo 26, and refuses — with the determinant shown — when it doesn't, because a message encrypted under a singular key is a message thrown away.
The Hill cipher is a polygraphic substitution built on linear algebra over Z26: letters become numbers (A=0 … Z=25), blocks of 2 or 3 form column vectors, and encryption multiplies each block by a key matrix, all arithmetic mod 26. Decoding multiplies by the inverse matrix — which exists only when the determinant is coprime with 26, a condition this tool checks before it will encrypt anything.
Published by Lester S. Hill in 1929 ("Cryptography in an Algebraic Alphabet"). The first algebraic cipher, and the first to build diffusion in by construction.
Encode or decode — the determinant is checked
Everything runs in your browser — nothing is uploaded.
Encryption is a matrix multiplication
Letters become numbers (A=0 … Z=25) and are taken in blocks of 2 or 3, matching the key. Each block is a column vector multiplied by the key matrix, all arithmetic mod 26: ciphertext = K × plaintext. Decoding multiplies by the matrix inverse mod 26, which exists only when the determinant is coprime with 26 (odd, and not a multiple of 13) — the tool computes the determinant, displays it under the key field, and if the inverse doesn't exist it stops and tells you the factor 26 and the determinant share. Text is read as letters only; a final short block is padded with X, disclosed in the note, exactly as Hill's paper procedure did.
The determinant rule deserves plain words. Decoding needs the inverse matrix, and the inverse is built by dividing through by the determinant (multiplying by its modular inverse). A number has an inverse mod 26 only if it shares no factor with 26 — and 26 = 2 × 13, so any even determinant, or any multiple of 13, is fatal: half of all random matrices fail the parity test alone, and only about a third of random 2×2 matrices (roughly 34%) are usable at all. A tool that skips the check will cheerfully encrypt with a singular key and produce ciphertext that two different plaintexts share — unrecoverable by anyone. Hill knew all this; his papers discuss key selection at length.
Hill, 1929 — algebra enters cryptography
Lester S. Hill published the system in 1929 in the American Mathematical Monthly ("Cryptography in an Algebraic Alphabet"), with a companion paper on larger alphabets the following year, and designed mechanical devices to carry out the multiplications. Every cipher before Hill substituted letters one at a time (or moved them): a plaintext E was a statistical event wherever it stood. Hill's blocks broke that locality — change one letter of a block and every ciphertext letter of the block changes, so the unit of analysis becomes the block and single-letter frequency tables go silent. Shannon formalised the idea twenty years later as diffusion, one half of the confusion–diffusion pair that still structures cipher design; AES's MixColumns is Hill's idea in a finite field, wearing better arithmetic.
The standard key, both directions
| Key GYBNQKURP | [[6,24,1], [13,16,10], [20,17,15]] |
|---|---|
| Its determinant | 441 — coprime with 26, so the inverse exists |
| Inverse mod 26 | [[8,5,10], [21,8,21], [21,12,8]] |
| A refused key | [[2,0],[0,2]] — determinant 4, sharing the factor 2 with 26 |
The tool prints the matrix, determinant and inverse in force under the key field — or the refusal, with the shared factor named.
The literature's standard example
Example 1 — ACT under GYBNQKURP
The example from Hill-cipher literature (it is Wikipedia's, and before that a generation of textbooks'): ACT is the vector (0, 2, 19). The key matrix multiplies it to (67, 222, 319), which mod 26 is (15, 14, 7) — POH. Switch to Decode and POH returns ACT, because the tool holds the inverse matrix printed in the reference table, which it derived and validated. The companion example worth trying: CAT under the same key gives FIN — the whole block changes when one letter changes, the diffusion property in miniature.
Example 2 — a 2×2 key, and a refused one
DDCF is the matrix [[3,3],[2,5]], determinant 9 — valid, and it sends HELP to HIAT. Now try the key 2 0 0 2: determinant 4, sharing the factor 2 with 26. The tool refuses before encrypting a single letter, because under that key two different plaintext blocks would collide and no inverse could ever separate them.
Immune to frequency — naked to algebra
Hill fell in an instructive way: the system is linear, so a known plaintext of a few blocks hands the attacker the whole matrix by linear algebra — the first cipher whose break is a homework problem in a different department. A 3×3 key needs nine known block equations instead of four; more work, same method. Against frequency analysis both sizes are immune in the same way, because no single letter's statistics survive the block mixing. Teaching Hill today is really teaching that arc: linear algebra enters cryptography, buys diffusion, and immediately teaches why linearity alone cannot be the whole design.
- Security status: a teaching cipher; secure against letter statistics, transparent to known-plaintext linear algebra.
- The real jump in Hill's design space is not block size but non-linearity, which his system deliberately lacks.
Algebraic neighbours
| Relative | How it differs | Solve it with |
|---|---|---|
| Affine cipher | Hill shrunk to one letter: a single multiplication and shift mod 26 — the same invertibility rule in miniature | The Affine page |
| Bifid | Diffusion by coordinate-splitting rather than algebra — the same design instinct, no arithmetic | The Bifid page |
| AES (MixColumns) | Hill's matrix idea over a finite field with a fixed, carefully chosen matrix — diffusion as one layer among several | The AES page |
The course cipher
Hill stayed a teaching cipher while rotor machines took the field — the key-selection burden and the known-plaintext weakness saw to that — but its classroom afterlife is enormous: it is the standard first meeting of cryptography and linear algebra in university courses, a CTF staple, and the cleanest historical bridge between the classical world of letters and the modern world of finite fields and matrices. For puzzles, 2×2 by hand and 3×3 by tool is the traditional split.
Multiply a block
Practice 1 — encode under GYBNQKURP
DOG is (3, 14, 6). Multiply by the key matrix and reduce mod 26 — every output letter should move.
Reveal the answer
WLY.
Practice 2 — encode under DDCF
Two 2×2 blocks: NO, then ON. The same letters in different positions encrypt differently — position inside the block is everything.
Reveal the answer
DSDP.
Frequently asked questions
Why was my key refused?
Its determinant shares a factor with 26 (it is even, or a multiple of 13), so the matrix has no inverse modulo 26 and anything encrypted with it could not be decrypted — by anyone, ever. The message under the key field shows the determinant and the shared factor. Change any one key number or letter and recompute; most single changes restore validity.
Can I enter the key as numbers instead of letters?
Yes — the field accepts either: nine numbers separated by spaces or commas are read directly; a string of letters is converted A=0 … Z=25. The matrix in use — and its determinant — is printed under the field so you can always see what the tool understood your key to be.
Why does my decoded text end in X?
Padding. Hill works in complete blocks, so a message whose letter count is not a multiple of the block size is completed with X before encryption, and decryption returns the block exactly — padding X included. It is disclosed here rather than silently stripped because a genuine final X and a padding X are indistinguishable, and the honest tool lets you decide.
Is a 3×3 key much stronger than 2×2?
Against frequency analysis both are immune in the same way; against known-plaintext linear algebra the 3×3 needs nine known block equations instead of four — more work, same method. The real jump in Hill's design space is not block size but non-linearity, which his system deliberately lacks.