What the Hill cipher is
The Hill cipher is a letter cipher that works on pairs, not single letters. It was invented by Lester Hill in 1929, and it uses a 2 by 2 matrix as the key. The message is split into pairs of letters, each letter becomes a number from 0 to 25, and each pair is multiplied by the matrix mod 26. The result is a new pair of letters. Because letters are mixed in pairs, the same plain letter can come out differently each time, which hides the letter frequency that breaks simpler ciphers.
With the matrix 3, 3, 2, 5, the pair HI becomes TC. H is 7 and I is 8, so the first new letter is (3 times 7 plus 3 times 8) mod 26, which is 45 mod 26, which is 19, the letter T. The second is (2 times 7 plus 5 times 8) mod 26, which is 54 mod 26, which is 2, the letter C. To decode, the tool uses the inverse matrix, which works only when the determinant of the matrix shares no factor with 26.
How to use the encoder
Type your message in the text box. Only letters are used: spaces, numbers and punctuation are dropped, and lower case becomes upper case. Then type four numbers from 0 to 25 into the matrix boxes. The default matrix, 3, 3, 2, 5, works well and is a good place to start.
Press Encrypt to scramble the message, or Decrypt to turn a scrambled message back into plain text. If your message has an odd number of letters, the tool adds an X at the end to make the last pair, and decoding will show that X too. If the tool says the matrix cannot be decoded, its determinant shares a factor with 26: try the default matrix, or change one number and try again.
Worked example
Take the word HELP with the matrix 3, 3, 2, 5. The pairs are HE and LP. For HE, H is 7 and E is 4, so the first letter is (3 times 7 plus 3 times 4) mod 26, which is 33 mod 26, which is 7, the letter H. The second is (2 times 7 plus 5 times 4) mod 26, which is 34 mod 26, which is 8, the letter I. So HE becomes HI.
For LP, L is 11 and P is 15, so the first letter is (3 times 11 plus 3 times 15) mod 26, which is 78 mod 26, which is 0, the letter A. The second is (2 times 11 plus 5 times 15) mod 26, which is 97 mod 26, which is 19, the letter T. So LP becomes AT, and HELP becomes HIAT. Decoding HIAT with the inverse matrix gives HELP back. A five-letter word like HELLO becomes HIOZHN, because the lone O is padded with an X.
Who uses this tool
Maths students use it most. The Hill cipher is a common topic in linear algebra classes, because it turns matrix multiplication into something you can see and play with. Teachers use it to show why a matrix needs an inverse, and why the determinant has to be coprime to 26.
Puzzle fans use it for coded messages and treasure hunts, where pairs make the cipher a little harder to crack than a single-letter swap. Writers use it for coded notes in stories and games. And anyone learning about ciphers meets it after the Caesar and affine ciphers, because it is the first one where the same letter can hide in different ways.
Honest limitations
The Hill cipher is not secure. With a few known pairs of plain and cipher letters, the matrix can be worked out by solving equations, and a longer message falls fast. It is a classroom cipher, not a way to protect real secrets. Never use it for passwords or private messages.
It also only works on the 26 English letters, in pairs, with no spaces or punctuation. A message with an odd number of letters gets a padding X, which can confuse the reader on decoding. And not every matrix works: if the determinant shares a factor with 26, the message cannot be decoded at all, so the tool checks that first and warns you.
Frequently asked questions
Why pairs and not single letters? Pairs hide letter frequency. In a single-letter cipher, E always becomes the same letter, so it is easy to spot. In the Hill cipher, E changes with its partner, so the pattern is much harder to see.
What is the determinant? For a 2 by 2 matrix, it is a times d minus b times c. For 3, 3, 2, 5, it is 15 minus 6, which is 9. Decoding needs the inverse of the determinant mod 26, which exists only when the determinant shares no factor with 26.
Why does decoding add an X? It does not add one: the X was added when encrypting, to pad an odd-length message into pairs. It is part of the cipher text, so it comes back on decoding. Ignore a trailing X when you read the result.
Can I use a 3 by 3 matrix? Yes, the Hill cipher works with bigger matrices, but this tool uses 2 by 2 to keep it simple and fast to check by hand.
También disponible en español: Codificador De Cifrado Hill 2×2 – Cifra Pares Con Una Matriz
