You are on page 1of 5

# Bruce Hearle

S00609530
3 October 2016

## How to Encrypt a Message Using Matrices

There are many reasons for keeping something a secret, and encryption is one method of
ensuring that only those with permission are able to access that secret. In particular, one method of
encryption uses a mathematical structure called a matrix to encode and decode messages.
A matrix (plural: matrices) is an array of numbers arranged in rows and columns inside square
brackets. A message can be written as a matrix and then multiplied by another matrix to produce a third
matrix that contains the encoded message. Finally, this encoded matrix can be multiplied by yet another
matrix to undo the encryption and get back to the original message.
By itself, matrix multiplication as a method of encryption is relatively easy to break, but it is
sometimes used along with other techniques in ciphers even today. The following sections explain the
basic steps involved in matrix encryption: preparing the message, choosing an encoding matrix,
performing the encryption, and decoding.

Preparing a Message for Encryption: The first step in preparation for encoding a
message is to turn that message into a matrix. This can be done by assigning each letter of the alphabet
to a number and filling a matrix with the numbers that correspond to the letters in the message. One
way to associate the letters of the alphabet with numbers is as follows (_ represents a space):
_ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

## Example: Message: Password is kimchi 16 1 19 19 23 15 18 4 0 9 19 0 11 9 13 3 8 9

Once you have replaced all the letters and spaces, you should have a, possibly long, string of
simple numbers between 0 and 26. The next thing to do is to arrange them in a matrix. However, before
you do, you must decide how many columns your matrix should have. Generally, you want your
message matrix to have either two, three, or four columns. Choose only one column and your matrix
wont encrypt well, but choose too many columns and it will become tedious to work with by hand.

## Example: Password is kimchi

16 1 19 19
23 15 18 4
0 9 19 0
11 9 13 3
8 9 0 0

Once you have decided on the number of columns, you should arrange the numbers from your
message string into a matrix with the chosen number of columns, adding as many rows as necessary.
Even if you dont have an exact number of rows, you can fill out the last row with zeros since the
spaces that they represent will not change the message.

## Creating an Encryption Matrix and Its Inverse: The fundamental principle of

matrix encryption is that some matrices have inverse versions of themselves, and that multiplying a
matrix by its inverse causes the matrices to cancel each other. So, multiplying a message matrix by an
encoding matrix and then multiplying that result by the inverse of the encoding matrix cancels it out,
leaving you right back where you started with the message matrix!
In order to proceed, we must find a matrix and its inverse matrix that will serve as our encoding
and decoding tools. While the matrix is mostly arbitrary, there are two requirements: first, it must be
square-shaped (have the same number of rows and columns); second, the number of rows must be
equal to the number of columns that we chose for our message matrix.

4 10 8 5
3 9 12 7
1 0 7 4
Example: 3 7 6 10 is an arbitrary square matrix with number of rows equal to the number of
columns in the example message matrix (4).

Next, we must find the inverse of the encoding matrix that we chose. To do this, we must use a
special type of matrix called an identity matrix and a little bit of magic. An identity matrix is just a
square shaped matrix that has ones on a diagonal line from the top left corner to the bottom right, and it
has zeros everywhere else. This special arrangement makes it so that multiplying an identity matrix by
another matrix doesnt change that matrix at all. Kind of like multiplying a number by one.
Now for the magic part. Say we chose a square encoding matrix with a certain number of rows
and columnssay n rows and columns. Then we need to take a square identity matrix with the same
dimensions and we need to attach it on the right side of the encoding matrix to obtain one single matrix
with n rows and 2n columns. To help us keep track, we can draw a dashed line down the center of this
new matrix where the encoding and identity matrices were joinedlike a stitched seem.

4 10 8 5
3 9 12 7
1 0 7 4
Example: 3 7 6 10
matrix.

1
0
0
0

0
1
0
0

0
0
1
0

0
0
0
1 encoding matrix adjoined to corresponding identity

Next, we have to play a kind of game using only three rules to accomplish a goal. Our goal is to
rewrite the combined matrix so that the side of the matrix to the left of the dashed line is an identity
matrix, and to do this we can use any of the following three rules on the entire stitched matrix as if it
were a single matrix:
1. We can swap the order of any of the rows.
2. We can multiply every entry in a row by a constant value.
3. We can add all the entries in one row to the corresponding entries in another row to create a
new row that can replace either of those two rows.
Typically, you start by multiplying one row by the reciprocal of its value, so that the first entry
in the row becomes one. Then, obtain zeros in the first entries in all the other rows by multiplying one
row by a constant that makes its first entry the negative of the first entry of another row. That way,
when you add them together, their first entries cancel. Continue this process until you have obtained
ones on the diagonal with zeros everywhere else in the left matrix. However, remember you must apply
the operations to the entire matrix.
The magic part is that if we are able to accomplish this, the other part of the adjoined matrix is now the
inverse matrix of our encoding matrix, and it can serve as our decoding matrix. However, if we were
not able to accomplish the goal of rewriting the left side as an identity matrix, then we have to choose a
new square encoding matrix and try again.

## 1 0 0 0 407/562 439/ 562 302 /562 17/562

0 1 0 0 57/562 125/562 150 /562
1/ 562
0 0 1 0 17/562
57/562
44/ 562 49/562
12 /562
90/ 562 is the final result.
Example: 0 0 0 1 72/562 10/562
Because the left side could be written as an identity matrix, it is given that the right side is the inverse
of the original matrix. Of course, this can involve an enormous amount of arithmetic, so it is highly
advisable not to exceed three columns.

## Encrypting a Message Using Matrix Multiplication: Once we have our

message matrix, encoding matrix, and decoding matrix we can encrypt our message matrix by
multiplying it by the encoding matrix. The problem is that a matrix contains multiple different
numbers, so multiplying two matrices isnt as straightforward as multiplying two individual numbers.
So, mathematicians have developed a standard definition of what it means to multiply two matrices.

First, matrix multiplication can only be applied when the number of columns in the left matrix
is the same as the number of rows in the right matrix. That is why we chose an encoding matrix with
the same number of rows as the number of columns in the message matrix. This also means that the
order of multiplication is fixed; for message encryption and decryption, always place the message on
the left and the encoder or decoder on the right.
Second, multiplication is applied in a row by column pattern. To elaborate, we multiply each
of the entries in the first row of the left matrix by each of the corresponding entries in the first column
of the right matrix, then we sum all of these products. The final result becomes the entry in the first
row and first column of the new product matrix. Then we simply repeat this process for every pair of
row from the left matrix and column from the right matrix. Needless to say, this can involve a lot of
arithmetic, but thats part of what makes it good for encrypting things.

Example:

][

][

16 1 19 19
143
4 10 8 5
23 15 18 4
167
3 9 12 7
= 46
0 9 19 0
1 0 7 4
11 9 13 3
93
3 7 6 10
8 9 0 0
59

302
393
81
212
161

387
514
241
305
172

353
332
139
200
103

Note that the number of columns in the message matrix (first) equals the number of rows in the
encoding matrix (second). The first entry 143 was calculated as the sum of the products of the entries in
the first row of the left matrix and the entries of the first column in the second matrix:
(164)+(13)+(191)+(193)=143 .

## The process is repeated for all entries.

Lastly, once we have our encrypted message matrix, we can remove the square brackets and
rewrite it as a plain string of numbers to make it even harder to decrypt. This is the final step in the
encryption process, and we now have a secret message that we can give to someone without worrying
about anyone else reading the message without permissionunless they manage to break the
encryption that is!

Example: 143 302 387 353 167 393 514 332 46 81 241 139 93 212 305 200 59 161 172 103.

## Encrypting a message wouldnt do much good if

we couldnt decrypt it when needed. In order to do this, we can use the inverse of our encoding matrix
to undo its effect and get back to our original message matrix.

First, we must rewrite our string of encoded numbers as a matrix again. If you forgot the
dimensions of the message matrix, recall that we chose the encoding matrix and decoding matrix to
have the same number of rows as the number of columns in the message matrix so that matrix
multiplication would work. So, all we need to do is arrange the string of numbers in the encoded
message into a matrix with the same number of columns as the number of rows in either the encoding
matrix or its inverse; they should have the same number.
Second, we simply perform matrix multiplication of the message matrix by the decoding matrix
(inverse of encoding). Recall, that matrix multiplication should be done with the message on the left
and the decoder on the right, and that the entry in a particular row and column of the product matrix is
found as the sum of the products of every entry in the same row of the left matrix with the entries in the
same column of the right matrix.

Example:

143
167
46
93
59

302
393
81
212
161

387
514
241
305
172

][

][

353
16 1 19 19
407/ 562 439/ 562 302/ 562 17/562
332
23 15 18 4
57/562 125/562 150/ 562
1 /562
= 0 9 19 0
139
17/562
57/562
44 /562 49 /562
200
11 9 13 3
72 /562
10/562
12/ 562
90 /562
103
8 9 0 0

Here, the encoded message matrix is multiplied by the inverse of the encoding matrix to undo the
encryption. The result is the original message matrix.

Lastly, simply take the decoded message matrix and rewrite it as a string of numbers. Then
replace the numbers with the corresponding letters from the chart above where 0 = _ and 1-26 = A-Z.
After this last step, you should have the original message intact. Since this last step of decoding can be
completed with just the decoder and the chart for translating letters to numbers, you can pass encrypted
messages to anyone you have given those two things prior, and they will be able to decode their
meaning.

## Example: Message: 16 1 19 19 23 15 18 4 0 9 19 0 11 9 13 3 8 9 Password is kimchi

This entire process can be tedious to say the least; fortunately, the operations involved do not
necessarily have to be done by hand as they can be performed by computers instead. You can easily
find websites with built-in calculators for the various parts of this encryption process. Alternatively,
you could simply use a program to automate the entire process, but where's the fun in that?