Which 2x2 Hill keys can be reversed? A determinant checklist
Before encrypting anything with a Hill cipher, check that the key can be undone. A message encrypted with a bad matrix cannot be decrypted uniquely, which is a frustrating way to learn the rule. The test takes ten seconds.
The rule
Compute the determinant ad - bc of the matrix, reduce it modulo 26, and find the greatest common divisor with 26. The key is usable only when that divisor is 1. Since 26 = 2 * 13, the determinant must be odd and must not be a multiple of 13. The usable determinant values are 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25, twelve in all.
Five keys to check
- Rows [2, 4] and [1, 2]: determinant 0, gcd with 26 is 26, not usable
- Rows [4, 2] and [2, 3]: determinant 8, gcd with 26 is 2, not usable
- Rows [3, 5] and [1, 4]: determinant 7, gcd with 26 is 1, usable
- Rows [1, 2] and [3, 8]: determinant 2, gcd with 26 is 2, not usable
- Rows [6, 5] and [7, 5]: determinant 21, gcd with 26 is 1, usable
Try the first key by hand. Its determinant is 22 - 41 = 0, which shares every factor with 26. Information is lost: the pairs (2, 0) and (0, 1) both encrypt to (4, 2), so a decoder could never tell which one you sent.
When you want to test a matrix and see the result for a message, the Hill cipher encoder and decoder validates the matrix as you type, which is useful for confirming your hand check.
Common mistakes
- Checking the determinant without reducing it. A determinant of -5 becomes 21 mod 26, which is usable.
- Assuming a large determinant is better. Only its factors with 26 matter.
- Testing only for zero. The key 4, 2, 2, 3 has determinant 8, not zero, yet it is still unusable because 8 is even.
- Using a key whose rows are multiples of each other. That yields determinant 0.
The home page has other tools to continue with.
Published by the caesarcipher.org team; drafted with AI assistance.