Built and fact-checked by the DocNectar team — see our editorial standards
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.
- Enter mode.
- Enter text.
- Enter key row 1, col 1.
- Enter key row 1, col 2.
- Enter key row 2, col 1.
- Enter key row 2, col 2.
- 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.