Hill Cipher 2×2
Encrypt text with a 2×2 matrix mod 26 (Hill cipher) — algebraic explanation and key invertibility check.
—
Linear algebra mod 26, hands on
The Hill cipher usually shows up right after matrix inverses, and what wrecks the exercise is almost never the multiplication. It is the modulus: taking the determinant mod 26, deciding whether it has an inverse, and finding that inverse by hand. One flipped sign along the way and your ciphertext disagrees with the answer key, with no clue about where the arithmetic went off.
The text is split into letter pairs, each pair becomes a vector (x, y), and it is multiplied by the matrix [[a, b], [c, d]] modulo 26. With the key 3, 3, 2, 5 the word HELP becomes HI AT, and the page reports det(K) mod 26 = 9 along with its inverse 3, since 9 × 3 = 27, which is 1 mod 26. The rule that governs everything: the key is invertible only when gcd(det, 26) = 1. Because 26 = 2 × 13, an even determinant or a multiple of 13 kills the key.
Note that the tool still encrypts after warning that the key is not invertible: you get ciphertext, it just has no unique inverse. Read the determinant line before committing to a key. It does not decrypt either: compute the inverse, det⁻¹ × [[d, −b], [−c, a]] mod 26, and enter that matrix instead, since decryption is the same multiplication. An odd number of letters gets padded with a trailing X, which will show up when you decrypt. All of it runs in the browser.
Frequently asked questions
How do I know my matrix works as a key?
Can it decrypt?
Where did the trailing X come from?
Related Tools
Custom Polybius Square
Build a 5×5 Polybius square with a key letter and encrypt/decrypt messages using numeric coordinates.
Playfair Cipher Step by Step
Encrypt/decrypt with Playfair showing the 5×5 matrix, letter pairs and the rule applied to each digram.
Rail Fence Cipher
Encrypts messages with the Rail Fence (zigzag) cipher, spreading letters across N rails and reading rail by rail. A classic transposition cipher for learning cryptography.
Polybius Square Cipher
Encrypt and decrypt messages with the Polybius square, which turns each letter into a pair of digits on a 5×5 grid (with I and J combined).
ADFGVX Cipher: Substitution Step
Encodes text on a fixed unkeyed 6x6 Polybius square of A-Z and 0-9, turning each character into its ADFGVX pair. No columnar transposition.
Affine Cipher
Encode text with the Affine cipher using E(x) = (a·x + b) mod 26. Here uses a=5, b=8 (coprime with 26). Combines multiplicative and additive substitution.