Hill Cipher
NewEncrypt and decrypt text with the Hill cipher, a classic polygraphic substitution cipher that multiplies pairs of letters by a 2x2 key matrix modulo 26.
The Hill cipher encrypts pairs of letters using 2x2 matrix multiplication modulo 26. The key matrix's determinant must be coprime with 26 for the cipher to be invertible (decryptable) — the tool computes the modular inverse matrix automatically for decryption and warns if the key is invalid.
Frequently Asked Questions
How does the Hill cipher actually encrypt text?
It splits the message into pairs of letters, treats each pair as a 2-number vector (A=0, B=1, ... Z=25), and multiplies that vector by a 2x2 key matrix modulo 26, producing a new pair of letters as ciphertext — so unlike letter-by-letter ciphers, it encrypts two letters at once as a unit.
Why does the tool sometimes warn that my key matrix is invalid?
Decryption requires computing the modular inverse of the key matrix, which only exists if the matrix's determinant is coprime with 26 (shares no common factor with it) — if it isn't, the encryption is mathematically one-way and can't be reversed, so the tool flags it immediately.
What happens if my text has an odd number of letters?
Since the Hill cipher processes letters two at a time, an odd-length message is automatically padded with a trailing "X" to make it even, the same convention used in the classic textbook examples of this cipher.
Is the Hill cipher considered secure by modern standards?
No — like all classical ciphers on this site, it's historically and educationally significant (it was the first cipher based on linear algebra, invented by Lester Hill in 1929) but is easily broken with a known-plaintext attack using basic matrix algebra, so it should never be used for real security.
How is this different from the Playfair cipher also on this site?
Playfair uses a 5x5 letter key square and swaps letter pairs based on their row/column geometry, while Hill uses genuine matrix multiplication over a numeric alphabet — they're both digraph (letter-pair) ciphers, but Hill is the more mathematically general of the two and can be extended to larger matrices for bigger letter blocks.