Algorithm for the Hill cipher (finding the inverse of the determinant of a $2 \times 2$ matrix modulo $26$)

1k Views Asked by At

I have a good understanding of how to do the Hill cipher on paper but putting it into program form is somewhat of a problem.

Finding the the determinant is the thing I'm having problem with. On paper if the matrix is $$\begin{pmatrix} 7 & 8 \\ 11 & 11 \end{pmatrix},$$ then you multiply $7 \times 11$ and $8 \times 11$ then subtract the $77 - 88$ which is $-11$ then add $-11$ to $26$ and you get $15$ and after that you do the $15 x \equiv 1 \pmod{26}$. It says the easiest way to do this is trial and error multiplying $15$ by $1$ though $9$ and you find that $15\cdot7$ is $105$ and divide $105$ by $26$ you get $1$ and the determinant is $7$.

This works on paper but writing a program to do this what would be a good way to do this. Is there a a different way to find the determinant or maybe doing the matrix a different way to give the determinant.

1

There are 1 best solutions below

0
On

What you have described will work very well on a computer even with numbers having several dozens of digits (at some point, you will just have to replace the exhaustive search for the modular inverse with the extended Euclidean algorithm).

The benefits of using sophisticated number-theoretic algorithms only start to kick in for very large numbers (say, a hundred of digits or more), except for hard problems like factoring.