Hill Cipher
Encode and decode using the Hill cipher. A polygraphic cipher using matrix multiplication.
Key Matrix
| 6 | 24 |
| 1 | 13 |
How Hill Cipher Works
- Convert letters to numbers (A=0, B=1, ..., Z=25)
- Group into vectors matching matrix size
- Multiply each vector by the key matrix (mod 26)
- Convert resulting numbers back to letters
Matrix Requirements
- • Matrix must be square (2×2 or 3×3)
- • Determinant must be coprime with 26
- • Valid determinants: 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25
- • Invalid: 2, 4, 6, 8, 10, 12, 13, 14, 16, 18, 20, 22, 24, 26
Example Matrices
2×2:
6 24 1 13
3 3 2 5
3×3:
6 24 1 13 16 10 20 17 15
What is the Hill Cipher?
The Hill cipher is a polygraphic substitution cipher invented by Lester S. Hill in 1929. It was the first cipher to use linear algebra for encryption, encrypting multiple letters at once using matrix multiplication.
How It Works
Key Matrix
The key is a square matrix (typically 2×2 or 3×3). For decryption to work, the matrix must be invertible modulo 26.
Encryption
- Convert plaintext letters to numbers (A=0, B=1, ... Z=25)
- Group into vectors matching the matrix size
- Multiply each vector by the key matrix
- Take results mod 26
- Convert back to letters
Decryption
Multiply ciphertext vectors by the inverse of the key matrix (mod 26).
Hill Cipher in Geocaching
This cipher appears in puzzles because:
- Mathematical: Appeals to math-themed puzzles
- Matrix key: Numbers work well for coordinate hints
- Uncommon: More challenging to identify
- Historical: First linear algebra-based cipher
Cryptanalysis
The Hill cipher can be broken with:
- Known plaintext: Just n² known letter pairs reveals the matrix
- Frequency analysis: Analyze digraph/trigraph frequencies
- Brute force: Try common matrices (limited valid options)
Matrix Invertibility
For the matrix to be invertible mod 26, its determinant must be coprime with 26. Since 26 = 2 × 13, the determinant cannot be divisible by 2 or 13.
Advantages
- Diffusion: Each ciphertext letter depends on multiple plaintext letters
- Efficient: Fast encryption/decryption with matrix operations
- Scalable: Larger matrices provide more security