Skip to content
100% local

Hill cipher

Encrypt or decrypt text with a matrix key, the classic polygraphic cipher from linear algebra.

Input
Output

Hill cipher

The Hill cipher, invented by Lester Hill in 1929, encrypts text by treating letters as numbers and multiplying blocks of them by a square key matrix, modulo the size of the alphabet. Paste plaintext to encrypt it, or ciphertext to decrypt it — this tool runs both directions with the same key.

Choose a 2×2 or 3×3 matrix size, then enter the key either as raw numbers (row by row, separated by spaces or commas) or as a word — its letters fill the matrix in reading order. The alphabet size can be 26 (A–Z only) or 29, which adds space, period and question mark so short phrases keep their punctuation. Characters outside the chosen alphabet are dropped, and accented letters are folded to their plain equivalent first. If the letter count isn't a multiple of the matrix size, the padding letter fills out the last block.

Decryption needs the key matrix to be invertible modulo the alphabet size — its determinant must share no common factor with 26 (or 29). When it doesn't, the tool explains why instead of returning garbage, since a non-invertible matrix has no unique inverse to decrypt with. Turn on "Show matrix, determinant and inverse" to see exactly how the key resolves, which is useful for checking a key by hand or following along with a textbook example.

Everything runs locally in your browser — nothing you type is uploaded anywhere. Copy the result, download it as a .txt file, or send the output straight back into the input to chain another transformation.

FAQ

How does the Hill cipher actually encrypt a block of letters?
Each letter becomes a number (A=0, B=1, …), a fixed-size block of them is treated as a column vector, and that vector is multiplied by the key matrix modulo the alphabet size. The resulting numbers become the ciphertext letters for that block.
Why did decryption fail with an error about the determinant?
Decrypting needs the key matrix's inverse, which only exists when the determinant shares no common factor with the alphabet size (26 or 29). Pick different key values so the determinant is coprime with that number.
What is the padding letter for?
The Hill cipher only works on complete blocks of 2 or 3 letters. If your text's letter count isn't a multiple of the matrix size, the padding letter fills the last block — decrypted output may end with one or two padding letters for the same reason.
Should I enter the key as numbers or as a word?
Either works. Numbers give you exact control over the matrix; a word is easier to remember and its letters fill the matrix row by row, with the padding letter used if the word is shorter than the matrix needs.
Is my text uploaded anywhere?
No. The Hill cipher runs entirely in your browser — your text and key never leave your device.