Hill Cipher Calculator

Encrypt a pair of letters with a 2 by 2 matrix modulo 26.

Technology and NetUpdated 2026-11-202 min read
Hill Cipher Calculator
Letters only. Spaces are ignored. The length must be even.
Ciphertext
...
Determinant mod 26...
Letter pairs...

What it does

The Hill cipher was invented by Lester Hill in 1929 and was the first cipher based on linear algebra. It operates on blocks of letters, treating each block as a vector and multiplying it by a matrix key.

University of Central Florida lecture notes demonstrate the 2 by 2 case with the key matrix [[3,1],[6,5]] and show how the letters MA encrypt to KU. The same key turns TH into MT.

The cipher works modulo 26 because there are 26 letters. A key is usable only if its determinant is coprime to 26, which guarantees the matrix has an inverse for decryption.

This tool accepts any text, strips non letters, uppercases the result and encrypts consecutive pairs with the key you enter. It reports the ciphertext, the determinant modulo 26 and the number of pairs.

The Hill cipher is vulnerable to known plaintext attacks and should be studied as history, not used for secrecy.

How to use

  1. Type a plaintext with an even number of letters.
  2. Enter the four entries of the 2 by 2 key matrix.
  3. Check that the determinant is coprime to 26, or the tool will reject the key.
  4. Read the ciphertext in the main result.
  5. Check the determinant and pair count below it.
  6. Try the default key and MATH to reproduce the published example.

Formula

For pair (p, q) as numbers 0 to 25: c1 = (a p + b q) mod 26, c2 = (c p + d q) mod 26.
p, q
Numerical values of the two plaintext letters, A = 0.
a, b, c, d
Entries of the 2 by 2 key matrix.
c1, c2
Numerical values of the two ciphertext letters.
mod 26
Reduction to the 26 letter alphabet.

The engine computes the determinant as a d minus b c and checks that its greatest common divisor with 26 is one. It pads nothing, so an odd length input is rejected rather than silently altered.

Worked example

Example: encrypting MATH

Plaintext MATH with key matrix [[3,1],[6,5]].

  1. Convert M and A to 12 and 0. The first vector is (12, 0).
  2. First output: 3 x 12 + 1 x 0 = 36, which is 10 modulo 26, the letter K.
  3. Second output: 6 x 12 + 5 x 0 = 72, which is 20 modulo 26, the letter U.
  4. Convert T and H to 19 and 7. The second pair becomes 12 and 19, or M and T.
  5. The ciphertext is KUMT.
  6. The determinant is 3 x 5 - 1 x 6 = 9, which is coprime to 26, so the key is valid.
  7. The tool reports ciphertext KUMT, determinant 9 and 2 pairs.

Reference table

Letter values used by the cipher
LetterValueLetterValue
A0N13
B1O14
M12T19
H7Z25

Limits

  • Only 2 by 2 keys are supported.
  • Plaintext must have an even number of letters after stripping non letters.
  • The key determinant must be invertible modulo 26.
  • The cipher is breakable and is not suitable for real security.

Common mistakes

  • Choosing a key whose determinant shares a factor with 26.
  • Forgetting that A is zero rather than one.
  • Entering an odd number of letters and expecting automatic padding.
  • Confusing encryption with secure modern cryptography.
  • Using a different letter ordering from the A equals zero convention.

Try it yourself

Quick checks. Answers sit tucked under each question.

Encrypt MA with key [[3,1],[6,5]].

KU, matching the published example.

Why must the determinant be coprime to 26?

So the matrix has an inverse modulo 26 and decryption is possible.

What is the numerical value of M?

12, since A is 0 and letters count upward.

Questions

What is the Hill cipher?

A classical cipher that multiplies letter vectors by a matrix modulo 26.

Who invented it?

Lester S. Hill, in 1929.

Why use pairs of letters?

The 2 by 2 matrix acts on two element vectors, so the text is grouped in pairs.

Can all matrices be keys?

No. The determinant must have an inverse modulo 26.

Is it secure?

No. It is vulnerable to known plaintext attacks and is studied for its mathematics.

Does the tool decrypt?

No. It performs encryption only.

Sources

How this page was checked. The formula above was matched against the cited sources, and the worked example was run through the tool on this page before publishing. If you spot an error, contact us so we can fix it and note the correction.