Docsity

Lecture Notes on Cryptography with Matrices | MATH 307, Study notes of Linear Algebra

Toggle sidebar
bg1
Dr. Neal, Fall 2008
MATH 307 Cryptography
with Matrices
Goals: (i) To take a message and encrypt it into a string of numbers via matrix
multiplication. (ii) Then to take the string of numbers and decrypt it back to a written
message. As an initial example, We shall use the following message:
"HI THERE BUDDY"
Alpha-Numeric Substitution
First, we must assign each letter a numeric equivalent. Here, we shall reserve the
number 0 to represent a space and use the numbers 1 – 26 to represent the 26 letters.
Rather than just making a direct substitution in order, we can permute the digits in
some way. For example:
A B C D E F G H I J K L M
2143658710 9 12 11 14
N O P Q R S T U V W X Y Z
13 16 15 18 17 20 19 22 21 24 23 26 25
Coding Matrix
Next, we choose an invertible
n
×
n
matrix
A
, for some size
n
, which will be used to
encrypt the message. Here we shall use
A
=
323
−6−5−4
987
.
Encrypting The Message
We first convert the message into the numeric script, using the alpha-numeric
substitution above (H = 7, I = 10, Blank = 0, etc).
7 10 0 19 7 6 17 6 0 1 22 3 3 26
Then we convert this script into a
m
×
3 matrix (3 columns because our
A
is 3
×
3).
The number of rows
m
depends on the length of the message. We fill out the last row
with more 0's as necessary:
B
=
7 10 0
19 7 6
17 6 0
1 22 3
3 26 0
.
pf3
pf4

Partial preview of the text

Download Lecture Notes on Cryptography with Matrices | MATH 307 and more Study notes Linear Algebra in PDF only on Docsity!

MATH 307 Cryptography

with Matrices

Goals : (i) To take a message and encrypt it into a string of numbers via matrix multiplication. (ii) Then to take the string of numbers and decrypt it back to a written message. As an initial example, We shall use the following message:

"HI THERE BUDDY"

Alpha-Numeric Substitution

First, we must assign each letter a numeric equivalent. Here, we shall reserve the number 0 to represent a space and use the numbers 1 – 26 to represent the 26 letters. Rather than just making a direct substitution in order, we can permute the digits in some way. For example:

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

Coding Matrix

Next, we choose an invertible n × n matrix A , for some size n , which will be used to encrypt the message. Here we shall use

A =

Encrypting The Message

We first convert the message into the numeric script, using the alpha-numeric substitution above (H = 7, I = 10, Blank = 0, etc).

7 10 0 19 7 6 17 6 0 1 22 3 3 26

Then we convert this script into a m × 3 matrix (3 columns because our A is 3 × 3). The number of rows m depends on the length of the message. We fill out the last row with more 0's as necessary:

B =

Here, B is 5 × 3. Now we multiply: C = BA.

C = BA =

×

Finally, we convert matrix C into a string that becomes the encrypted message:

–39 –36 –19 69 51 71 15 4 27 –102 –84 –64 –147 –124 –

H I T H E R E B U D D Y

Notice that “H” has been sent to two different values. The first H has been encrypted as –39, and the second H has been encrypted as 51. Likewise the three blanks are assigned different values, as are the two “E”s and the two “D”s.

Decrypting the message

The second party receives only the encrypted message:

–39 –36 –19 69 51 71 15 4 27 –102 –84 –64 –147 –124 –

However the receiver knows the alpha-numeric code and the coding matrix A. Thus, the encrypted script is converted back into an m × 3 matrix C and then

multiplied by A −^1 to undo the original matrix multiplication. Because C = BA , we

obtain the original matrix B by B = CA −^1 , and then we convert the string back to the alphabet.

ToCharacterCode Command

When using a software package to encode messages, we can use the built-in features that will automatically convert alphabetic symbols into numeric equivalents. With Mathematica , we can use the ToCharacterCode command.

For example, consider the following message:

Dear colleague, what is 4% of 120?

We would need alpha-numeric equivalents not only for the 26 letters, but also for the symbols % and ?, and for numbers. Rather than trying to define our own alpha- numeric substitution, we can use the built-in Mathematica command that is also case -sensitive.

First, type the message enclosed in quotes. Here we define the message to be the term script. Then apply the ToCharacterCode command.

encrypt={471,407,479,1041,860,907,657,546,657,648,541,636,141, 81,255,318,301,348,-117,-130,51,-87,-109,79,222,175,232,9, -32,149,279,232,283,285,222,285};

A={{3,2,3},{-6,-5,-4},{9,8,7}};size=n=3;

Do[Do[c[i,j]=encrypt[[n(i-1)+j]], {j,1,n}],{i,1,Length[encrypt]/n}];

Y=Table[c[i,j],{i,1,Length[encrypt]/n},{j,1,n}];

V=Y.Inverse[A];MatrixForm[V]

decrypt=Flatten[V]

FromCharacterCode[decrypt]

Dear colleague, what is 4% of 120?

Assignment

  1. Pick a partner. Together decide on a square invertible coding matrix A. Adjust the programs accordingly with this matrix A.
  2. Each student create an encrypted message to send to the other. Print out the program and outputs used to create your encrypted message. On it write "Message from 'your name' to 'partner's name'."
  3. Email your partner only your encrypted message. (Send the numbers enclosed in braces and separated by commas.)
  4. Check your email to obtain the encrypted message from your partner. Print out this email.
  5. Decrypt your received message. Print out the codes and outputs used to decrypt. On it write, "Message from 'partner's name' decoded by 'your name'."
  6. Turn in both print-outs along with the received email message.

Note : If doing this in the lab, you can first create your encrypted message with Mathematica. Then highlight and copy the final encrypted message output. Then use email on the same computer to send it by simply pasting into the body of the message. Likewise, you can check your email in the lab, highlight and copy the received message, then open your Mathematica file and paste it into the decryption codes. Otherwise, you will have to type out the numbers when you send the email, and type them out again when you decrypt.