Secret Codes With Matrices

 

Matrix multiplication can be used to encode and decode messages.

 

To encode a message:

Translate each letter in your message into a number (A=1, B=2, C=3, space=0). For example:

BEETLE becomes 2 - 5 - 5 - 20 - 12 - 5

Put the numbers into a 3x2 matrix:

2

20

5

12

5

5

Multiply our encoding matrix by this matrix:

0

2

3

2

20

25

39

1

4

7

x

5

12

=

57

103

2

3

6

5

5

49

106

Add or subtract 26 from each number in the new matrix until the result is between 0 and 26. For example:

63 - 2 x 26 = 11

-45 + 2 x 26 = 7

25

39

25

13

57

103

becomes

5

25

49

106

23

2

And finally, translate these numbers back into letters:

25 - 5 - 23 - 13 - 25 - 2 becomes YEWMYB

 

 

To decode a message:

Translate letters to numbers and put them back into a 3x2 matrix:

25

13

5

25

23

2

Multiply our decoding matrix by this matrix:

3

-3

2

25

13

106

-32

8

-6

3

x

5

25

=

239

-40

-5

4

-2

23

2

-151

31

Add or subtract 26 from each number in the new matrix until the result is between 0 and 26:

106

-32

2

20

239

-40

becomes

5

12

-151

31

5

5

And finally, translate these numbers back into letters:

2 - 5 - 5 - 20 - 12 - 5 becomes BEETLE