STATION 25 / FIELD MANUAL

← Back to crypto library

Hill

Linear algebra

Hill encrypts blocks of letters using matrix multiplication. Each output letter depends on multiple input letters. This example uses two-letter column vectors and A=0.

How to recognise it

A small matrix or paired numeric instructions are strong clues. The message length must fit the block size, possibly after padding. Letter appearance alone does not distinguish Hill reliably.

Worked example: encrypt HI

Use the matrix below. Put H=7 and I=8 into a column vector:

Key matrix       Plain vector
[3 3]            [7]
[2 5]            [8]

First output:  3×7 + 3×8 = 45 → 19 → T
Second output: 2×7 + 5×8 = 54 →  2 → C
Result: TC
  1. Multiply the first matrix row by the input vector to get 45.
  2. Multiply the second row by the vector to get 54.
  3. Reduce both modulo 26: TC.

Work backwards: decrypt TC

The determinant is 3×5−3×2=9. Its inverse modulo 26 is 3. The inverse matrix is therefore:

[15 17]
[20  9]

15×19 + 17×2 = 319 → 7 → H
20×19 +  9×2 = 398 → 8 → I

Multiplying ciphertext vector (19,2) by that inverse recovers HI.

Conventions and common mistakes

The determinant must be coprime to 26 for an inverse to exist. Row-vector and column-vector conventions produce different results; this reference always uses column vectors. Padding and block size must be agreed, and division of each ciphertext number separately cannot undo the matrix.

  • Affine — A smaller introduction to modular inverses.
  • Playfair — Compare another cipher that handles letter pairs.

Useful desk reference

Alphabet positions — Convert letters to A=0 values before matrix multiplication.

Support this project

Enjoying Advent of Cypher? If you'd like to support the project and help keep it running, you can make a small donation. Completely optional, always appreciated.