BobG
Science Advisor
- 352
- 88
Set yourself up a square matrix that has a determinant of 1 (that way, it's inverse will be all integers, as well). A larger matrix is harder to crack but also harder to construct. Code your letters as A=1, B=2, C=3, etc. Cycle them through by a set number each time. (If you're using a 5 x 5 matrix, cycle in 5 letters to make a 5 x1 matrix, for example). Multiply your encoding matrix by the sequence of letters you're encoding. Your message is coded.
To decode, mutliply the inverse of your matrix by the coded letters (5 at a time if you're using 5x5 matrix, 6 if you're using 6x6, etc).
As a simple example, using a 3 x 3 matrix:
\left(\begin{array}{ccc}3&4&2\\5&3&8\\4&5&3\end{array}\right)
Encode A, B, C where A=1, B=2, C=3 by multiplying
\left(\begin{array}{ccc}3&4&2\\5&3&8\\4&5&3\end{array}\right)\ast\left(\begin{array}{c}1\\2\\3\end{array}\right) = \left(\begin{array}{c}17\\35\\23\end{array}\right)
To decode, multiply the inverse of your encoder matrix by the coded text:
\left(\begin{array}{ccc}-31&-2&26\\17&1&-14\\13&1&-11\end{array}\right)\ast\left(\begin{array}{c}17\\35\\32\end{array}\right) = \left(\begin{array}{c}1\\2\\3\end{array}\right)
Obviously, you'd want to use a larger matrix than just a 3x3. With a 3x3 matrix, 1/3 of all your 'the's would be encrypted together, making it pretty easy to spot them. Once a person decrypted the word 'the', they'd have the whole key and could figure out the rest of the message.
To decode, mutliply the inverse of your matrix by the coded letters (5 at a time if you're using 5x5 matrix, 6 if you're using 6x6, etc).
As a simple example, using a 3 x 3 matrix:
\left(\begin{array}{ccc}3&4&2\\5&3&8\\4&5&3\end{array}\right)
Encode A, B, C where A=1, B=2, C=3 by multiplying
\left(\begin{array}{ccc}3&4&2\\5&3&8\\4&5&3\end{array}\right)\ast\left(\begin{array}{c}1\\2\\3\end{array}\right) = \left(\begin{array}{c}17\\35\\23\end{array}\right)
To decode, multiply the inverse of your encoder matrix by the coded text:
\left(\begin{array}{ccc}-31&-2&26\\17&1&-14\\13&1&-11\end{array}\right)\ast\left(\begin{array}{c}17\\35\\32\end{array}\right) = \left(\begin{array}{c}1\\2\\3\end{array}\right)
Obviously, you'd want to use a larger matrix than just a 3x3. With a 3x3 matrix, 1/3 of all your 'the's would be encrypted together, making it pretty easy to spot them. Once a person decrypted the word 'the', they'd have the whole key and could figure out the rest of the message.
Last edited: