Hill Cipher Encoder/Decoder

Enter a 2×2 key matrix (mod 26), check invertibility, then encrypt or decrypt text. We strip non-letters and pad with X if needed.

1. Key matrix (2×2)

Values are integers mod 26 (0–25). A common demo key is [[3, 3], [2, 5]].

2. Text

For decryption, paste ciphertext here and click “Decrypt”.

3. Actions

4. Output

Result

Numeric vector (A=0 … Z=25)

How the Hill cipher works (2×2)

1. Choose a 2×2 key matrix K with entries mod 26.

2. Convert text to numbers using A=0, B=1, …, Z=25, and group into 2-element column vectors.

3. For each vector P, compute C = K · P mod 26. Convert back to letters.

K = [a b; c d], det(K) = ad − bc.
K is invertible mod 26 if gcd(det(K), 26) = 1.

To decrypt, we need the inverse matrix K⁻¹ mod 26 so that P = K⁻¹ · C mod 26. This page computes that for you.