Hill Cipher

Treat blocks of letters as vectors and encrypt them with matrix multiplication mod 26.

Difficulty: Intermediate

How it works

  1. Pick a block size (often 2 or 3) and choose a square key matrix of that size whose determinant has an inverse modulo 26.
  2. Convert each letter of your plaintext into a number (A=0, B=1, ..., Z=25) and group the numbers into vectors of the chosen block size.
  3. To encrypt a block, multiply the key matrix by the plaintext vector and reduce each result modulo 26 to get the ciphertext numbers, then map them back to letters.
  4. To decrypt, you compute the inverse key matrix modulo 26 and multiply ciphertext vectors by this inverse, again reducing modulo 26.
  5. The Hill cipher demonstrates how linear algebra concepts like matrices and determinants can be used to build polygraphic encryption schemes.
Press Shift + Enter

What is it?

Invented by Lester S. Hill in 1929, the Hill Cipher was the first polygraphic cipher in which it was practical (though barely) to operate on more than three symbols at once. It relies on linear algebra, specifically matrix multiplication modulo 26. The cipher takes a block of plaintext letters, converts them to numbers, and multiplies them by a square key matrix. While mathematically elegant, it is highly susceptible to known-plaintext attacks because it relies entirely on linear mathematics.

Try it yourself

Can you decrypt this challenge?

VHVY GUVF ZRNGL (example ciphertext)

Where this shows up today

To create a mathematically rigorous cipher capable of encrypting large blocks of text simultaneously.