


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



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:
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
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:
Here, B is 5 × 3. Now we multiply: 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
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.