EN
My tools

Hill Cipher — 2×2 and 3×3 Encrypt & Decrypt

Encrypt and decrypt the Hill cipher with a 2×2 or 3×3 key matrix from a keyword or numbers. Checks the determinant mod 26 and shows the inverse matrix and steps.

Read row by row: GYBNQKURP = [6 24 1; 13 16 10; 20 17 15].
Fills the last block when the text length is not a multiple of the block size.
Ciphertext
POH
Key matrix
6 24 1 / 13 16 10 / 20 17 15
Determinant mod 26
25
det = 441; its inverse mod 26 is 25
Inverse key matrix
8 5 10 / 21 8 21 / 21 12 8
used for decryption

Spaces, digits and punctuation are removed; the cipher works on blocks of 3 letters.

Blocks: C = K·P (mod 26)
BlockVectorResultLetters
ACT(0, 2, 19)(15, 14, 7)POH
My tools →
Advertisement

Lester Hill published this cipher in 1929. It treats each block of 2 or 3 letters as a vector and multiplies it by a key matrix modulo 26, so a single changed letter alters the whole block — the first practical polygraphic cipher built on linear algebra. This tool encrypts and decrypts with a 2×2 or 3×3 key given as a keyword or numbers, checks that the key is invertible, and shows the inverse matrix and every block.

How to use this tool

  1. Choose encrypt or decrypt and paste the text (letters only are used).
  2. Enter the key as 4 or 9 letters or numbers, read row by row.
  3. Set the padding letter for an incomplete last block.
  4. Read the result, the inverse matrix and the block-by-block table.

Formula

C = K · P (mod 26) P = K⁻¹ · C (mod 26), K⁻¹ = det(K)⁻¹ · adj(K) (mod 26)

P and C are column vectors of letter numbers (A = 0 … Z = 25). The key works only if det(K) mod 26 shares no factor with 26 (it must be odd and not 13); otherwise the matrix has no inverse mod 26. adj(K) is the adjugate, the transpose of the cofactor matrix.

Example

The key GYBNQKURP is the matrix [6 24 1; 13 16 10; 20 17 15]. ACT = (0, 2, 19), and K·P = (67, 222, 319) ≡ (15, 14, 7) = POH. The determinant is 441 ≡ 25 (mod 26), whose inverse is 25, giving the decryption matrix [8 5 10; 21 8 21; 21 12 8].

Frequently asked questions

Why is my key rejected?

The determinant of the key matrix, taken mod 26, must be coprime with 26 — odd and not 13. Otherwise two different blocks can encrypt to the same ciphertext and nothing can be decrypted. Changing one letter usually fixes it.

Why did extra letters appear?

The text is split into blocks of 2 or 3 letters, so a short last block is filled with the padding letter (X by default). Remove it after decrypting.

Is the Hill cipher secure?

No. Because it is linear, a few known plaintext–ciphertext pairs reveal the key by solving equations. It is a classic example in cryptography courses, not a way to protect data.

Last updated:

Cite or embed this tool
APA

kakaoCalc. (2026, November 8). Hill Cipher — 2×2 and 3×3 Encrypt & Decrypt. https://kakao.mobile/tools/hill-cipher-tool/

MLA

“Hill Cipher — 2×2 and 3×3 Encrypt & Decrypt.” kakaoCalc, 8 Nov. 2026, kakao.mobile/tools/hill-cipher-tool/.

Paste this code into your page. The widget runs in your visitors' browsers, shows no ads and keeps a link back to this page. Embedding terms

Advertisement