1
$\begingroup$

I am learning about Hill Cipher and know that it is a block cipher where each block of n letters (considered as an $n$-component vector) is multiplied by an invertible $n \times n$ matrix, again modulus $26$.

The article did not touch on what happens if the the block of letters is less than length $n$.

Eg: Assume I am supposed to encrypt 100 letters – how do I encrypt the last 22 letters?

I was thinking of padding similar to MD5, or are there other methods to resolve this issue? If so, what are those methods?

$\endgroup$
2
  • $\begingroup$ try this, en.wikipedia.org/wiki/Padding_%28cryptography%29#PKCS7 $\endgroup$ Oct 15, 2014 at 14:45
  • $\begingroup$ In the Hill Cipher, the number of components in the vector (that you note $n$) is not usually the same as the modulus you set at $26$. $n=3$ is typical, and makes the padding issue less relevant. Notice that the cipher is slightly less vulnerable if the modulus is prime. $\endgroup$
    – fgrieu
    Oct 27, 2014 at 15:34

1 Answer 1

2
$\begingroup$

Since it's a linear cipher, you should be wary about a guessable padding, otherwise if your last block is only one char long, you will reveal almost your whole matrix on this last block. If you're too afraid of mangling the last word, use something like 'Z'+(random chars). But I really would not use any predictable padding with such a cipher.

$\endgroup$
1
  • $\begingroup$ Yes. If the implementation is manual, we can pad with haphazard (non-constant) characters chosen such that a human will understand they are not part of the real plaintext. E.g. ATTACKATDAWNWVK. If a computer is used, why use the Hill Cipher when we have incomparably safer options? $\endgroup$
    – fgrieu
    Oct 27, 2014 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.