How can we encrypt a text in Hill Cipher with a key matrix that is 3x3 when the plaintext is even like "ATTACKS"? Do we need to add padding like "x" or "z" to make the matrix equal? Thanks.
2 Answers
It's indeed standard to add pre-agreed padding characters at the end to make the plain text a multiple of $n$ when we use an $n \times n$ encryption matrix.
So your encoded plain text could be
$$\begin{bmatrix} \operatorname{enc}(A)\\ \operatorname{enc}(T) \\ \operatorname{enc}(T) \end{bmatrix} \begin{bmatrix} \operatorname{enc}(A)\\ \operatorname{enc}(C) \\ \operatorname{enc}(K) \end{bmatrix} \begin{bmatrix} \operatorname{enc}(S)\\ \operatorname{enc}(X) \\ \operatorname{enc}(X) \end{bmatrix} $$
where $\operatorname{enc}(x)$ is the encoding of the character $x$ in the number ring or field the matrix is taken over, and when we use 'X' as a padding character.
To make the plaintext matrices equal, you could use padding with a null character, such as using "X". For example with "ATTACKS", you would get the following vectors:
$$ \begin{bmatrix}A\\T\\T\end{bmatrix}\ \begin{bmatrix}A\\C\\K\end{bmatrix}\ \begin{bmatrix}S\\X\\X\end{bmatrix}\ $$