# Hill cipher: How to find an unknown key of unknown size

How would you tackle the problem of finding the key (you don't know the length) to a Hill cipher when knowing only one 12-letter word of plaintext and its corresponding ciphertext?

CONVERSATION has been encoded as SQZHUSSUDYKP with standard alphabet (A=0, Z=25). The key, as I said, is unknown with unknown size.

I am not asking for a solution, but for tips and guidance. Any help will be much appreciated.

Assuming that $$2\times2$$ matrix is used, and the encryption starts from the first letter of the plaintext, the key can be found by just calculating the "encryption" with size of $$4$$ plain- and cryptotext block.

For example, for CONV $$\rightarrow$$ SQZH, it would go as follows:
$$\begin{pmatrix} 2 & 14 \\ 13 & 21 \end{pmatrix}\begin{pmatrix} a & b \\ c & d \end{pmatrix}= \begin{pmatrix} 18 & 16 \\ 25 & 7 \end{pmatrix}\pmod{26}$$

Then solving for $$a,b,c,d$$, the key $$K$$ is found. As here the plaintext matrix is invertible, one can compute

$$\begin{pmatrix} a & b \\ c & d \end{pmatrix}=\begin{pmatrix} 2 & 14 \\ 13 & 21 \end{pmatrix}^{-1} \begin{pmatrix} 18 & 16 \\ 25 & 7 \end{pmatrix}\pmod{26}$$

• What if $3\times3$ matrix is used for encryption? Commented Jun 19, 2019 at 11:52
• You could proceed the same way, but having $9$ coefficients to be solved.
– M.P
Commented Jun 19, 2019 at 11:56