Skip to content
D DocNectar

Free Hill Cipher Encoder and Decoder

Encrypt or decrypt text with a 2x2 Hill cipher, using matrix multiplication mod 26 to transform letter pairs.

100% Free No Signup Works on all devices

Built and fact-checked by the DocNectar team — see our editorial standards

Thanks for rating!

Key Features

Instant Calculation

Get accurate results in real time with our optimized algorithm.

Mobile Friendly

Fully responsive design. Works on all devices & screen sizes.

Privacy Focused

Your data stays on your device. We don't store any inputs.

100% Free

No hidden costs. This tool is completely free forever.

The Hill cipher, invented by Lester Hill in 1929, was one of the first ciphers to use linear algebra — encrypting several letters at once by multiplying them, as a small vector, by a key matrix.

This tool encrypts or decrypts text using a 2x2 Hill cipher with a key matrix of four numbers you choose.

How it works

Enter four numbers forming a 2x2 key matrix. Text is split into pairs of letters (padded with X if needed), and each pair is treated as a small vector and multiplied by the key matrix, with all arithmetic done mod 26. To decrypt, the tool automatically computes the modular inverse of your key matrix and applies that instead — this only works if the matrix's determinant shares no common factor with 26, so the tool checks this and lets you know if your key isn't usable.

  1. Enter mode.
  2. Enter text.
  3. Enter key row 1, col 1.
  4. Enter key row 1, col 2.
  5. Enter key row 2, col 1.
  6. Enter key row 2, col 2.
  7. Click Calculate to see your results.

Examples

Key matrix [[3,3],[2,5]]

"HELP" encrypted with this key matrix produces a 4-letter ciphertext, and decrypting it with the same key matrix returns "HELP" exactly.

Who should use it

  • Teaching how matrix multiplication applies to cryptography.
  • Puzzle and cryptography-competition style challenges involving linear algebra.

Industry applications

  • Cryptography and linear algebra education
  • Games and puzzles

Advantages

  • A genuinely interesting bridge between classical cryptography and linear algebra.
  • Encrypts multiple letters together in one mathematical operation, unlike single-letter substitution.

Limitations

  • Vulnerable to known-plaintext attacks, making it unsuitable for real security.
  • Not every key matrix works — it must be invertible mod 26.

Common mistakes to avoid

  • Choosing four numbers whose matrix isn't invertible mod 26 — the tool will reject these and explain why.
  • Using a different key matrix for decryption than the one used to encrypt.

Best practices

  • Use the Hill cipher for puzzles or to explore how linear algebra (matrix multiplication) can be applied to encryption — not for protecting real secrets.

Tips

  • If you're picking your own key matrix, try simple numbers first (like 3, 3, 2, 5) and let the tool confirm whether it's invertible before committing to a longer message.

Frequently asked questions

Yes, with no signup and no limit on how many conversions you run.
A Hill cipher key matrix must be invertible mod 26 (its determinant must share no common factor with 26) so that decryption is mathematically possible. The tool checks this before running and tells you if your numbers don't work.
No — while historically significant as an early application of linear algebra to cryptography, it's vulnerable to a known-plaintext attack (if an attacker has matching plaintext and ciphertext, they can solve for the key matrix directly). It's used for education today.
Larger matrices (3x3 and up) are possible in the general Hill cipher but require more inputs and more complex matrix inversion — 2x2 keeps the tool simple while still demonstrating the core idea clearly.

Get new calculators and guides in your inbox

No spam — just new tools like Hill Cipher Tool and practical guides.

Favorites