Toolstia / Hill cipher
Hill cipher
The Hill cipher encrypts blocks of letters by multiplying them with a key matrix. Enter a key as letters or numbers, type your text and see the result together with the key matrix, its determinant and its inverse.
The Hill cipher turns each block of letters into numbers (A is 0), multiplies them by the key matrix and reduces the result modulo 26. The matrix must have a determinant with no common factor with 26. It is a teaching cipher and is not secure today.
How it works
- Enter a key of 4, 9 or 16 letters or numbers.
- Choose encrypt or decrypt and type the text.
- Copy the result and check the matrix shown.
How it works
Letters become numbers from 0 to 25. Each block is multiplied by the key matrix and reduced modulo 26. Decryption uses the inverse of the matrix modulo 26.
Valid keys
The determinant of the matrix must share no factor with 26, which means it is odd and not a multiple of 13. Otherwise no inverse exists and the tool says so.
Padding
If the text does not fill the last block, the letter X is added at the end.
Example key
GYBNQKURP is the classic 3x3 key, and it turns the word ACT into POH.
Questions
Is my message uploaded?
Everything happens in your browser, and nothing you enter is sent anywhere.
Is the Hill cipher secure?
No. It is a good way to learn linear algebra in cryptography, but known plaintext attacks break it easily.
Can I enter numbers as the key?
Yes. Enter the numbers separated by spaces, row by row.