Hill cipher (2x2 matrix)
The Hill cipher (Lester Hill, 1929) is the first cipher that brought linear algebra into cryptography. Plaintext letters are converted into numbers (A = 0 ... Z = 25), grouped by twos and multiplied by a square matrix:
| c1 | | 3 3 | | p1 |
| | = | | * | | (mod 26)
| c2 | | 2 5 | | p2 |
That is, c1 = (3*p1 + 3*p2) mod 26 and c2 = (2*p1 + 5*p2) mod 26.
For decryption, the inverse of the matrix modulo 26 is needed. To do this, first the determinant is calculated (det = 3*5 - 3*2 = 9), then its modular inverse is found (pow(9, -1, 26)), then it is multiplied by the adjugate matrix:
K⁻¹ = det⁻¹ * | 5 -3 | (mod 26)
| -2 3 |
For the matrix to be invertible, it is required that EKUB(det, 26) = 1; we have det = 9, the condition is met.
Ciphertext (divided into pairs):
KY ET DH CK EU FK DA
The plaintext is of even length, no padding character has been added. Flag: BAYROQ{KL4SS1K_<ochiq_matn>}