For a project, I want to encode the word "MEMBRANOPHONES" with the key "MULTITONE". I try spliting "MEMBRANOPHONES" into groups of 3, but then I get "MEM", "BRA", "NOP", "HON", leaving me with a 2 letter "ES". I can't multiply a 3 by 3 matrix by a 2 by 1 matrix, so what do I do in this case?
This is a standard problem in modern cryptography (eg for CBC-mode).
The standard solution is to use Padding or some other agreed-upon mechanism to encode variable-length messages as a multiple of the blocksize.
The most common padding is PKCS#7 padding: If one byte is left, append
0x01, if two are left append
0x02 0x02 and so on. Note that this requires you to also pad on messages which are a multiple of the blocksize (in case your message ends on eg
As you are more concerned with letters than bytes, you can probably adapt the above scheme to use
A instead of
B instead of
0x02 and so on for the full alphabet. So in your particular case you would pad the message with a single A.