HillCipher.mws

The Hill Cipher

İMike May, S. J., 2002, maymk@slu.edu

>    restart:

The worksheets we have done so far look at techniques that encrypt a message one character at a time.  These encryption method are insecure for a variety of reason:

This makes the initial monoalphabetic ciphers we used very weak.  Recall that an affine cipher is completely cracked if we know how almost any two letters are replaced.

>   

One solution to developing a stronger system is to encode blocks of characters at a time.  This effectively increases the size of our alphabet and reduces the usefulness of much of the data on the structure of English.  The easiest way to encode blocks of characters is to convert blocks to vectors of numbers and then to multiply the vector by an invertible matrix.  

Technical details I - Alphabets

One of our objectives is to mask the beginning and ending of words to keep an attacker from using that information for an attack on our code.  This could be done by removing spaces and punctuation before we encode, but that also confuses the message after it has been decoded by the person we are sending it to.  The other strategy is to consider special characters as part of a larger alphabet.  Since Maple has a command to convert characters in a string to ASCII equivalents, it is easiest to simply use the normal ASCII character set for our alphabet.  That means that our alphabet has 127 letters in it.  In keeping with the numbering conventions of ASCII, we will also be using clock arithmetic rather than modular arithmetic.  (Our numbers will go from 1 to 127 rather than from 0 to 126.)  We notice as a bonus that 127 is prime.  We start by defining a command that adjust numbers from modular notation to clock arithmetic.

>    clock127 := x -> ((x-1) mod 127) + 1:

Exercises:

1) With an aphine cipher acting on an alphabet of 26 characters, some encryption keys cannot be decrypted.  Characterize those keys.

>   

2)  For cracking an affine cipher, it was noted that it sufficed to find the substitution rule for almost any two letters.  Explain what pairs of characters don't give enough information and why.  (Notice for example, that the keys (1,0), (3, 24), and (5, 22) both fix the letters represented by 1 and 14 in an alphabet of 26 characters.)

>   

3)  I mentioned that it was a bonus that we would be using an alphabet whose size is prime.  If we are to work over mod n, where n is the size of our alphabet, why is it a bonus to have n be a prime number?

>   

Initial Variables and Message Length

We next need a message and an encrypting key.  Our initial key will be a 3 by 3 invertible matrix over Z[127] .  For the next several worksheets, our messages will begin and end with know strings.  Our beginning string is "az AZ - Good morning, Mr. Phelps.

The secret message for today is:"

The ending string is "az AZ".  Notice that the beginning string has a newline character in the middle of it.

Our secret message for today is a poem by Ogden Nash.

>    mess1 := `az AZ - Good morning, Mr. Phelps.
The secret message for today is:
I objurgate the centipede,
A bug we realy do not need.
At sleepy time he beats a path
Straight to bedroom or the bath.
You always wollop where he's not,
Or if he is, he leaves a spot.
az AZ`:
nums1 := convert(mess1, bytes);
mykey := matrix([[1,2,3],[0,5,7],[0,0,11]]);

nums1 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums1 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums1 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums1 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums1 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums1 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums1 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums1 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums1 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums1 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums1 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...

mykey := matrix([[1, 2, 3], [0, 5, 7], [0, 0, 11]])

We want to check the determinant of mykey and that mykey is invertible over Z[127] .

>    Det(mykey) mod 127;
unkey := Inverse(mykey) mod 127;

55

unkey := matrix([[1, 25, 30], [0, 51, 83], [0, 0, 104]])

Since we are encrypting the message in blocks of three characters, the next detail is to make sure that the message  has a length divisible by three (the size of the encrypting matrix).  Evensize is a procedure that takes a list of decimal numbers and pads it out with 32's to make the message a length divisible by the size of the key.  (the ASCII equivalent of 32 is a blank space.)

>    linalg[vectdim](nums1);

257

>    evensize := proc(decvec,bsize)
local charLength, paddingLength, j, temp;
temp := decvec;
charLength :=linalg[vectdim](decvec);
paddingLength := (bsize - irem(charLength, bsize)) mod bsize;
temp := [op(temp),seq(32, j=1..paddingLength)]:
#temp;
end:

>    nums2 := evensize(nums1,3);

nums2 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums2 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums2 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums2 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums2 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums2 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums2 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums2 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums2 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums2 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums2 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...

Encoding by Matrix Multiplication

Next we want to define the procedure that multiplies the matrix by appropriate vectors from the decimal list.

>    matmult := proc(decvec, key, keysize)
local l1, l3, i, j, k, temp, temp2, temp3;
temp2 := linalg[vector](keysize);
temp := convert(decvec,array);
l1 :=linalg[vectdim](temp);
l3 := l1/keysize;
for j from 0 to (l3 -1) do
   for i from 1 to keysize do
     temp2[i] := temp[j*keysize+i]:
   od;
   temp2 := map(clock127,linalg[multiply](key,temp2)):
   for i from 1 to keysize do
     temp[j*keysize + i] := temp2[i]:      
   od:
od;
convert(temp,list);
end:

Now we apply the transformation, then convert back to ASCII and print the message.

>    nums3 := matmult(nums2,mykey,3);
mess2 := convert(nums3,bytes);

nums3 := [56, 72, 98, 87, 39, 98, 68, 22, 19, 125, 112, 84, 75, 52, 78, 14, 15, 12, 67, 61, 103, 20, 40, 111, 96, 85, 118, 122, 118, 45, 99, 8, 125, 50, 3, 35, 21, 94, 98, 106, 55, 73, 29, 47, 6, 45, 1...
nums3 := [56, 72, 98, 87, 39, 98, 68, 22, 19, 125, 112, 84, 75, 52, 78, 14, 15, 12, 67, 61, 103, 20, 40, 111, 96, 85, 118, 122, 118, 45, 99, 8, 125, 50, 3, 35, 21, 94, 98, 106, 55, 73, 29, 47, 6, 45, 1...
nums3 := [56, 72, 98, 87, 39, 98, 68, 22, 19, 125, 112, 84, 75, 52, 78, 14, 15, 12, 67, 61, 103, 20, 40, 111, 96, 85, 118, 122, 118, 45, 99, 8, 125, 50, 3, 35, 21, 94, 98, 106, 55, 73, 29, 47, 6, 45, 1...
nums3 := [56, 72, 98, 87, 39, 98, 68, 22, 19, 125, 112, 84, 75, 52, 78, 14, 15, 12, 67, 61, 103, 20, 40, 111, 96, 85, 118, 122, 118, 45, 99, 8, 125, 50, 3, 35, 21, 94, 98, 106, 55, 73, 29, 47, 6, 45, 1...
nums3 := [56, 72, 98, 87, 39, 98, 68, 22, 19, 125, 112, 84, 75, 52, 78, 14, 15, 12, 67, 61, 103, 20, 40, 111, 96, 85, 118, 122, 118, 45, 99, 8, 125, 50, 3, 35, 21, 94, 98, 106, 55, 73, 29, 47, 6, 45, 1...
nums3 := [56, 72, 98, 87, 39, 98, 68, 22, 19, 125, 112, 84, 75, 52, 78, 14, 15, 12, 67, 61, 103, 20, 40, 111, 96, 85, 118, 122, 118, 45, 99, 8, 125, 50, 3, 35, 21, 94, 98, 106, 55, 73, 29, 47, 6, 45, 1...
nums3 := [56, 72, 98, 87, 39, 98, 68, 22, 19, 125, 112, 84, 75, 52, 78, 14, 15, 12, 67, 61, 103, 20, 40, 111, 96, 85, 118, 122, 118, 45, 99, 8, 125, 50, 3, 35, 21, 94, 98, 106, 55, 73, 29, 47, 6, 45, 1...
nums3 := [56, 72, 98, 87, 39, 98, 68, 22, 19, 125, 112, 84, 75, 52, 78, 14, 15, 12, 67, 61, 103, 20, 40, 111, 96, 85, 118, 122, 118, 45, 99, 8, 125, 50, 3, 35, 21, 94, 98, 106, 55, 73, 29, 47, 6, 45, 1...
nums3 := [56, 72, 98, 87, 39, 98, 68, 22, 19, 125, 112, 84, 75, 52, 78, 14, 15, 12, 67, 61, 103, 20, 40, 111, 96, 85, 118, 122, 118, 45, 99, 8, 125, 50, 3, 35, 21, 94, 98, 106, 55, 73, 29, 47, 6, 45, 1...

mess2 :=
mess2 :=
mess2 :=
mess2 :=

The printed ciphertext is not very manageable.  By using the larger alphabet, we now have special characters sprinkled throughout the ciphertext.  It makes retyping the ciphertext impossible, and we also could not include the ciphertext in a mail message.  Before we look at that problem, let us make sure that we can decipher the message.  Decryption should be done by the same process of matrix multiplication with a key that is the inverse of the original key.

>    unkey := Inverse(mykey) mod 127;

unkey := matrix([[1, 25, 30], [0, 51, 83], [0, 0, 104]])

>    nums4 := matmult(nums3, unkey, 3);
mess3 := convert(nums4, bytes);
convert(mess3,name);

nums4 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums4 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums4 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums4 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums4 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums4 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums4 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums4 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums4 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums4 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums4 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...

mess3 :=
mess3 :=
mess3 :=
mess3 :=
mess3 :=
mess3 :=
mess3 :=
mess3 :=
mess3 :=

`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...
`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...
`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...
`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...
`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...
`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...
`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...
`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...
`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...

Cleaning up the Ciphertext

Now we get to worry about presenting the encoded message.  The easiest solution seems to be to go back to hex representation, then store the code in blocks corresponding to 3 (the size of the key) characters.  We need to recall the procedures defined in the Type Conversions worksheet for blocking and unblocking hex vectors.

>    blocker := proc(hexvec,bsize)
local numCharacters, paddingNum, numWords, i, j, temp, hexblock;
temp := hexvec;
numCharacters :=linalg[vectdim](hexvec);
numWords := ceil(numCharacters/bsize);
paddingNum := numWords*bsize - numCharacters;
temp := [op(temp),seq(`00`,j = 1..paddingNum)];
hexblock :=  
   [seq( cat(seq(temp[bsize*i + j], j = 1..bsize)), i=0..numWords-1)]:
end:
unblocker := (hexblock,bsize) ->
  map(hexString -> seq(substring(hexString,2*j-1..2*j), j = 1..bsize),hexblock):

We have one more problem to be aware of.  Our use of the procedure blocker assumes that every ASCII character has a two digit hex representation.  However Maple's conversion to hex follows the usual math convention and leaves off leading zeroes.  With normal ASCII text, this only give us problems if a newline (ASCII equivalent of 13) is included, since that would be represented by a single hex character.  After we have used the Hill cipher, the characters are distributed, so it should give us a problem for 1 character out of 8.  We solve this problem by recalling a procedure converts to 2 character hex strings.

>    intTo2dHex := intValue -> substring(convert(intValue+256,hex), 2..3):

Now we can convert our output to hex blocked words.

>    nums5 := map(intTo2dHex, nums3);
nums6 := blocker(nums5,3);

nums5 := [`38`, `48`, `62`, `57`, `27`, `62`, `44`, `16`, `13`, `7D`, `70`, `54`, `4B`, `34`, `4E`, `0E`, `0F`, `0C`, `43`, `3D`, `67`, `14`, `28`, `6F`, `60`, `55`, `76`, `7A`, `76`, `2D`, `63`, `08`,...
nums5 := [`38`, `48`, `62`, `57`, `27`, `62`, `44`, `16`, `13`, `7D`, `70`, `54`, `4B`, `34`, `4E`, `0E`, `0F`, `0C`, `43`, `3D`, `67`, `14`, `28`, `6F`, `60`, `55`, `76`, `7A`, `76`, `2D`, `63`, `08`,...
nums5 := [`38`, `48`, `62`, `57`, `27`, `62`, `44`, `16`, `13`, `7D`, `70`, `54`, `4B`, `34`, `4E`, `0E`, `0F`, `0C`, `43`, `3D`, `67`, `14`, `28`, `6F`, `60`, `55`, `76`, `7A`, `76`, `2D`, `63`, `08`,...
nums5 := [`38`, `48`, `62`, `57`, `27`, `62`, `44`, `16`, `13`, `7D`, `70`, `54`, `4B`, `34`, `4E`, `0E`, `0F`, `0C`, `43`, `3D`, `67`, `14`, `28`, `6F`, `60`, `55`, `76`, `7A`, `76`, `2D`, `63`, `08`,...
nums5 := [`38`, `48`, `62`, `57`, `27`, `62`, `44`, `16`, `13`, `7D`, `70`, `54`, `4B`, `34`, `4E`, `0E`, `0F`, `0C`, `43`, `3D`, `67`, `14`, `28`, `6F`, `60`, `55`, `76`, `7A`, `76`, `2D`, `63`, `08`,...
nums5 := [`38`, `48`, `62`, `57`, `27`, `62`, `44`, `16`, `13`, `7D`, `70`, `54`, `4B`, `34`, `4E`, `0E`, `0F`, `0C`, `43`, `3D`, `67`, `14`, `28`, `6F`, `60`, `55`, `76`, `7A`, `76`, `2D`, `63`, `08`,...
nums5 := [`38`, `48`, `62`, `57`, `27`, `62`, `44`, `16`, `13`, `7D`, `70`, `54`, `4B`, `34`, `4E`, `0E`, `0F`, `0C`, `43`, `3D`, `67`, `14`, `28`, `6F`, `60`, `55`, `76`, `7A`, `76`, `2D`, `63`, `08`,...
nums5 := [`38`, `48`, `62`, `57`, `27`, `62`, `44`, `16`, `13`, `7D`, `70`, `54`, `4B`, `34`, `4E`, `0E`, `0F`, `0C`, `43`, `3D`, `67`, `14`, `28`, `6F`, `60`, `55`, `76`, `7A`, `76`, `2D`, `63`, `08`,...
nums5 := [`38`, `48`, `62`, `57`, `27`, `62`, `44`, `16`, `13`, `7D`, `70`, `54`, `4B`, `34`, `4E`, `0E`, `0F`, `0C`, `43`, `3D`, `67`, `14`, `28`, `6F`, `60`, `55`, `76`, `7A`, `76`, `2D`, `63`, `08`,...

nums6 := [`384862`, `572762`, `441613`, `7D7054`, `4B344E`, `0E0F0C`, `433D67`, `14286F`, `605576`, `7A762D`, `63087D`, `320323`, `155E62`, `6A3749`, `1D2F06`, `2D6D5F`, `016F33`, `145E62`, `1F536F`, `...
nums6 := [`384862`, `572762`, `441613`, `7D7054`, `4B344E`, `0E0F0C`, `433D67`, `14286F`, `605576`, `7A762D`, `63087D`, `320323`, `155E62`, `6A3749`, `1D2F06`, `2D6D5F`, `016F33`, `145E62`, `1F536F`, `...
nums6 := [`384862`, `572762`, `441613`, `7D7054`, `4B344E`, `0E0F0C`, `433D67`, `14286F`, `605576`, `7A762D`, `63087D`, `320323`, `155E62`, `6A3749`, `1D2F06`, `2D6D5F`, `016F33`, `145E62`, `1F536F`, `...
nums6 := [`384862`, `572762`, `441613`, `7D7054`, `4B344E`, `0E0F0C`, `433D67`, `14286F`, `605576`, `7A762D`, `63087D`, `320323`, `155E62`, `6A3749`, `1D2F06`, `2D6D5F`, `016F33`, `145E62`, `1F536F`, `...
nums6 := [`384862`, `572762`, `441613`, `7D7054`, `4B344E`, `0E0F0C`, `433D67`, `14286F`, `605576`, `7A762D`, `63087D`, `320323`, `155E62`, `6A3749`, `1D2F06`, `2D6D5F`, `016F33`, `145E62`, `1F536F`, `...
nums6 := [`384862`, `572762`, `441613`, `7D7054`, `4B344E`, `0E0F0C`, `433D67`, `14286F`, `605576`, `7A762D`, `63087D`, `320323`, `155E62`, `6A3749`, `1D2F06`, `2D6D5F`, `016F33`, `145E62`, `1F536F`, `...
nums6 := [`384862`, `572762`, `441613`, `7D7054`, `4B344E`, `0E0F0C`, `433D67`, `14286F`, `605576`, `7A762D`, `63087D`, `320323`, `155E62`, `6A3749`, `1D2F06`, `2D6D5F`, `016F33`, `145E62`, `1F536F`, `...
nums6 := [`384862`, `572762`, `441613`, `7D7054`, `4B344E`, `0E0F0C`, `433D67`, `14286F`, `605576`, `7A762D`, `63087D`, `320323`, `155E62`, `6A3749`, `1D2F06`, `2D6D5F`, `016F33`, `145E62`, `1F536F`, `...

As always, we want to test that this final encoded message can be decoded.

>    nums7 := unblocker(nums6,3);
nums8 := map(convert,nums7,decimal,hex);
nums9 := matmult(nums8,unkey,3);
mess4 := convert(nums9,bytes);
convert(mess4, name);

nums7 := [`38`, `48`, `62`, `57`, `27`, `62`, `44`, `16`, `13`, `7D`, `70`, `54`, `4B`, `34`, `4E`, `0E`, `0F`, `0C`, `43`, `3D`, `67`, `14`, `28`, `6F`, `60`, `55`, `76`, `7A`, `76`, `2D`, `63`, `08`,...
nums7 := [`38`, `48`, `62`, `57`, `27`, `62`, `44`, `16`, `13`, `7D`, `70`, `54`, `4B`, `34`, `4E`, `0E`, `0F`, `0C`, `43`, `3D`, `67`, `14`, `28`, `6F`, `60`, `55`, `76`, `7A`, `76`, `2D`, `63`, `08`,...
nums7 := [`38`, `48`, `62`, `57`, `27`, `62`, `44`, `16`, `13`, `7D`, `70`, `54`, `4B`, `34`, `4E`, `0E`, `0F`, `0C`, `43`, `3D`, `67`, `14`, `28`, `6F`, `60`, `55`, `76`, `7A`, `76`, `2D`, `63`, `08`,...
nums7 := [`38`, `48`, `62`, `57`, `27`, `62`, `44`, `16`, `13`, `7D`, `70`, `54`, `4B`, `34`, `4E`, `0E`, `0F`, `0C`, `43`, `3D`, `67`, `14`, `28`, `6F`, `60`, `55`, `76`, `7A`, `76`, `2D`, `63`, `08`,...
nums7 := [`38`, `48`, `62`, `57`, `27`, `62`, `44`, `16`, `13`, `7D`, `70`, `54`, `4B`, `34`, `4E`, `0E`, `0F`, `0C`, `43`, `3D`, `67`, `14`, `28`, `6F`, `60`, `55`, `76`, `7A`, `76`, `2D`, `63`, `08`,...
nums7 := [`38`, `48`, `62`, `57`, `27`, `62`, `44`, `16`, `13`, `7D`, `70`, `54`, `4B`, `34`, `4E`, `0E`, `0F`, `0C`, `43`, `3D`, `67`, `14`, `28`, `6F`, `60`, `55`, `76`, `7A`, `76`, `2D`, `63`, `08`,...
nums7 := [`38`, `48`, `62`, `57`, `27`, `62`, `44`, `16`, `13`, `7D`, `70`, `54`, `4B`, `34`, `4E`, `0E`, `0F`, `0C`, `43`, `3D`, `67`, `14`, `28`, `6F`, `60`, `55`, `76`, `7A`, `76`, `2D`, `63`, `08`,...
nums7 := [`38`, `48`, `62`, `57`, `27`, `62`, `44`, `16`, `13`, `7D`, `70`, `54`, `4B`, `34`, `4E`, `0E`, `0F`, `0C`, `43`, `3D`, `67`, `14`, `28`, `6F`, `60`, `55`, `76`, `7A`, `76`, `2D`, `63`, `08`,...
nums7 := [`38`, `48`, `62`, `57`, `27`, `62`, `44`, `16`, `13`, `7D`, `70`, `54`, `4B`, `34`, `4E`, `0E`, `0F`, `0C`, `43`, `3D`, `67`, `14`, `28`, `6F`, `60`, `55`, `76`, `7A`, `76`, `2D`, `63`, `08`,...

nums8 := [56, 72, 98, 87, 39, 98, 68, 22, 19, 125, 112, 84, 75, 52, 78, 14, 15, 12, 67, 61, 103, 20, 40, 111, 96, 85, 118, 122, 118, 45, 99, 8, 125, 50, 3, 35, 21, 94, 98, 106, 55, 73, 29, 47, 6, 45, 1...
nums8 := [56, 72, 98, 87, 39, 98, 68, 22, 19, 125, 112, 84, 75, 52, 78, 14, 15, 12, 67, 61, 103, 20, 40, 111, 96, 85, 118, 122, 118, 45, 99, 8, 125, 50, 3, 35, 21, 94, 98, 106, 55, 73, 29, 47, 6, 45, 1...
nums8 := [56, 72, 98, 87, 39, 98, 68, 22, 19, 125, 112, 84, 75, 52, 78, 14, 15, 12, 67, 61, 103, 20, 40, 111, 96, 85, 118, 122, 118, 45, 99, 8, 125, 50, 3, 35, 21, 94, 98, 106, 55, 73, 29, 47, 6, 45, 1...
nums8 := [56, 72, 98, 87, 39, 98, 68, 22, 19, 125, 112, 84, 75, 52, 78, 14, 15, 12, 67, 61, 103, 20, 40, 111, 96, 85, 118, 122, 118, 45, 99, 8, 125, 50, 3, 35, 21, 94, 98, 106, 55, 73, 29, 47, 6, 45, 1...
nums8 := [56, 72, 98, 87, 39, 98, 68, 22, 19, 125, 112, 84, 75, 52, 78, 14, 15, 12, 67, 61, 103, 20, 40, 111, 96, 85, 118, 122, 118, 45, 99, 8, 125, 50, 3, 35, 21, 94, 98, 106, 55, 73, 29, 47, 6, 45, 1...
nums8 := [56, 72, 98, 87, 39, 98, 68, 22, 19, 125, 112, 84, 75, 52, 78, 14, 15, 12, 67, 61, 103, 20, 40, 111, 96, 85, 118, 122, 118, 45, 99, 8, 125, 50, 3, 35, 21, 94, 98, 106, 55, 73, 29, 47, 6, 45, 1...
nums8 := [56, 72, 98, 87, 39, 98, 68, 22, 19, 125, 112, 84, 75, 52, 78, 14, 15, 12, 67, 61, 103, 20, 40, 111, 96, 85, 118, 122, 118, 45, 99, 8, 125, 50, 3, 35, 21, 94, 98, 106, 55, 73, 29, 47, 6, 45, 1...
nums8 := [56, 72, 98, 87, 39, 98, 68, 22, 19, 125, 112, 84, 75, 52, 78, 14, 15, 12, 67, 61, 103, 20, 40, 111, 96, 85, 118, 122, 118, 45, 99, 8, 125, 50, 3, 35, 21, 94, 98, 106, 55, 73, 29, 47, 6, 45, 1...
nums8 := [56, 72, 98, 87, 39, 98, 68, 22, 19, 125, 112, 84, 75, 52, 78, 14, 15, 12, 67, 61, 103, 20, 40, 111, 96, 85, 118, 122, 118, 45, 99, 8, 125, 50, 3, 35, 21, 94, 98, 106, 55, 73, 29, 47, 6, 45, 1...

nums9 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums9 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums9 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums9 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums9 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums9 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums9 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums9 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums9 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums9 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...
nums9 := [97, 122, 32, 65, 90, 32, 45, 32, 71, 111, 111, 100, 32, 109, 111, 114, 110, 105, 110, 103, 44, 32, 77, 114, 46, 32, 80, 104, 101, 108, 112, 115, 46, 32, 10, 84, 104, 101, 32, 115, 101, 99, 11...

mess4 :=
mess4 :=
mess4 :=
mess4 :=
mess4 :=
mess4 :=
mess4 :=
mess4 :=
mess4 :=

`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...
`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...
`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...
`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...
`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...
`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...
`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...
`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...
`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...

Exercises:

4)  Find the key that scrambles 5 letter blocks, taking "abcde" to "ecadb".  Use that key to encrypt message1 above.

>   

5)  Enter a 10 line message of your choice with the name prob1.  Produce a nontrivial key of size 4.  Use your key to encrypt  prob1, saving the result as prob2.

>   

6)  Find the inverse to your key above and use it to decrypt prob 2.  

>   

Cleaning up our procedures

Since we will be storing our cyphertext in hex blocks we can rewrite our procedures to make them a bit more compact and portable.  This will also make them easier to copy and paste if we want to use them on another worksheet.

Our first two procedures are for housekeeping.  The next two are procedures to convert a string into a list of blocked hex words and back again.   We give these procedures the names stringtoblocks and blockstostring.

>   

>    clock127 := x -> ((x-1) mod 127) + 1:
intTo2dHex := intValue -> substring(convert(intValue+256,hex), 2..3):
stringtoblocks := proc(charstring,bsize)
   local declist, hexlist, hexblock, i, j, numChars, numBlocks, paddingLength:
  #First we convert string to decimals and padd out with spaces
   declist := convert(charstring,bytes):
   numChars :=linalg[vectdim](declist);
   numBlocks := ceil(numChars/bsize):
   paddingLength := numBlocks*bsize - numChars:
   declist := [op(declist),seq(32, j=1..paddingLength)];
  #Now we convert to hex and block into words
   hexlist := map(intTo2dHex,declist):
   hexblock := [seq(cat(seq(hexlist[bsize*i + j], j = 1-bsize..0)),i=1..numBlocks)];
end:
blockstostring := proc(hexblock,bsize)
   local declist, hexlist, charstring, i, j, l1:
  #First we back to a list of hex characters
   hexlist := map(hexString ->
      seq(substring(hexString,2*j-1..2*j), j = 1..bsize), hexblock);
  #Then we convert back to a decimal list, then to a string.
   declist := map(convert,hexlist,decimal,hex):
   charstring := convert(declist,bytes):
end:

We also need a procedure for multiplying a matrix times a hex word.

>    matmultbloc := proc(word,key,bsize)
   local i, j, decvect, hexvect, hexword:
   decvect := linalg[vector]([seq(
     convert(substring(word,(2*i-1)..(2*i)),decimal,hex),i=1..bsize)]):
   decvect := map(clock127, linalg[multiply](key,decvect)):
   hexvect := map(intTo2dHex,decvect):
   hexword := cat(seq(hexvect[j],j=1..bsize)):
end:

We want to define a key and use these procedures to uncrypt a message, then decrypt it to check our work.

>    key5 := matrix(5,5,[[1,2,3,4,5],[7,0,0,0,0],[0,0,0,12,0],[0,0,13,0,0], [0,11,0,0,0]]);
a:= stringtoblocks(mess1,5);
secret1 := map(matmultbloc,a,key5,5);
unkey5 := Inverse(key5) mod 127;
b := map(matmultbloc,secret1,unkey5,5);
test1 := blockstostring(b,5);
convert(test1,name);

key5 := matrix([[1, 2, 3, 4, 5], [7, 0, 0, 0, 0], [0, 0, 0, 12, 0], [0, 0, 13, 0, 0], [0, 11, 0, 0, 0]])

a := [`617A20415A`, `202D20476F`, `6F64206D6F`, `726E696E67`, `2C204D722E`, `205068656C`, `70732E200A`, `5468652073`, `6563726574`, `206D657373`, `6167652066`, `6F7220746F`, `6461792069`, `733A0A4920`,...
a := [`617A20415A`, `202D20476F`, `6F64206D6F`, `726E696E67`, `2C204D722E`, `205068656C`, `70732E200A`, `5468652073`, `6563726574`, `206D657373`, `6167652066`, `6F7220746F`, `6461792069`, `733A0A4920`,...
a := [`617A20415A`, `202D20476F`, `6F64206D6F`, `726E696E67`, `2C204D722E`, `205068656C`, `70732E200A`, `5468652073`, `6563726574`, `206D657373`, `6167652066`, `6F7220746F`, `6461792069`, `733A0A4920`,...
a := [`617A20415A`, `202D20476F`, `6F64206D6F`, `726E696E67`, `2C204D722E`, `205068656C`, `70732E200A`, `5468652073`, `6563726574`, `206D657373`, `6167652066`, `6F7220746F`, `6461792069`, `733A0A4920`,...
a := [`617A20415A`, `202D20476F`, `6F64206D6F`, `726E696E67`, `2C204D722E`, `205068656C`, `70732E200A`, `5468652073`, `6563726574`, `206D657373`, `6167652066`, `6F7220746F`, `6461792069`, `733A0A4920`,...
a := [`617A20415A`, `202D20476F`, `6F64206D6F`, `726E696E67`, `2C204D722E`, `205068656C`, `70732E200A`, `5468652073`, `6563726574`, `206D657373`, `6167652066`, `6F7220746F`, `6461792069`, `733A0A4920`,...
a := [`617A20415A`, `202D20476F`, `6F64206D6F`, `726E696E67`, `2C204D722E`, `205068656C`, `70732E200A`, `5468652073`, `6563726574`, `206D657373`, `6167652066`, `6F7220746F`, `6461792069`, `733A0A4920`,...

secret1 := [`042C122348`, `29615A2372`, `010F262354`, `5024325F43`, `0936627062`, `3361455276`, `1716035A7A`, `1C50032B01`, `6548455549`, `40616E2B38`, `652C032B75`, `390F7A236F`, `2841033133`, `4E2B72...
secret1 := [`042C122348`, `29615A2372`, `010F262354`, `5024325F43`, `0936627062`, `3361455276`, `1716035A7A`, `1C50032B01`, `6548455549`, `40616E2B38`, `652C032B75`, `390F7A236F`, `2841033133`, `4E2B72...
secret1 := [`042C122348`, `29615A2372`, `010F262354`, `5024325F43`, `0936627062`, `3361455276`, `1716035A7A`, `1C50032B01`, `6548455549`, `40616E2B38`, `652C032B75`, `390F7A236F`, `2841033133`, `4E2B72...
secret1 := [`042C122348`, `29615A2372`, `010F262354`, `5024325F43`, `0936627062`, `3361455276`, `1716035A7A`, `1C50032B01`, `6548455549`, `40616E2B38`, `652C032B75`, `390F7A236F`, `2841033133`, `4E2B72...
secret1 := [`042C122348`, `29615A2372`, `010F262354`, `5024325F43`, `0936627062`, `3361455276`, `1716035A7A`, `1C50032B01`, `6548455549`, `40616E2B38`, `652C032B75`, `390F7A236F`, `2841033133`, `4E2B72...
secret1 := [`042C122348`, `29615A2372`, `010F262354`, `5024325F43`, `0936627062`, `3361455276`, `1716035A7A`, `1C50032B01`, `6548455549`, `40616E2B38`, `652C032B75`, `390F7A236F`, `2841033133`, `4E2B72...
secret1 := [`042C122348`, `29615A2372`, `010F262354`, `5024325F43`, `0936627062`, `3361455276`, `1716035A7A`, `1C50032B01`, `6548455549`, `40616E2B38`, `652C032B75`, `390F7A236F`, `2841033133`, `4E2B72...

unkey5 := matrix([[0, 109, 0, 0, 0], [0, 0, 0, 0, 104], [0, 0, 0, 88, 0], [0, 0, 53, 0, 0], [51, 29, 110, 125, 60]])

b := [`617A20415A`, `202D20476F`, `6F64206D6F`, `726E696E67`, `2C204D722E`, `205068656C`, `70732E200A`, `5468652073`, `6563726574`, `206D657373`, `6167652066`, `6F7220746F`, `6461792069`, `733A0A4920`,...
b := [`617A20415A`, `202D20476F`, `6F64206D6F`, `726E696E67`, `2C204D722E`, `205068656C`, `70732E200A`, `5468652073`, `6563726574`, `206D657373`, `6167652066`, `6F7220746F`, `6461792069`, `733A0A4920`,...
b := [`617A20415A`, `202D20476F`, `6F64206D6F`, `726E696E67`, `2C204D722E`, `205068656C`, `70732E200A`, `5468652073`, `6563726574`, `206D657373`, `6167652066`, `6F7220746F`, `6461792069`, `733A0A4920`,...
b := [`617A20415A`, `202D20476F`, `6F64206D6F`, `726E696E67`, `2C204D722E`, `205068656C`, `70732E200A`, `5468652073`, `6563726574`, `206D657373`, `6167652066`, `6F7220746F`, `6461792069`, `733A0A4920`,...
b := [`617A20415A`, `202D20476F`, `6F64206D6F`, `726E696E67`, `2C204D722E`, `205068656C`, `70732E200A`, `5468652073`, `6563726574`, `206D657373`, `6167652066`, `6F7220746F`, `6461792069`, `733A0A4920`,...
b := [`617A20415A`, `202D20476F`, `6F64206D6F`, `726E696E67`, `2C204D722E`, `205068656C`, `70732E200A`, `5468652073`, `6563726574`, `206D657373`, `6167652066`, `6F7220746F`, `6461792069`, `733A0A4920`,...
b := [`617A20415A`, `202D20476F`, `6F64206D6F`, `726E696E67`, `2C204D722E`, `205068656C`, `70732E200A`, `5468652073`, `6563726574`, `206D657373`, `6167652066`, `6F7220746F`, `6461792069`, `733A0A4920`,...

test1 :=
test1 :=
test1 :=
test1 :=
test1 :=
test1 :=
test1 :=
test1 :=
test1 :=

`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...
`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...
`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...
`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...
`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...
`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...
`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...
`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...
`az AZ - Good morning, Mr. Phelps. \nThe secret message for today is:\nI objurgate the centipede,\nA bug we realy do not need.\nAt sleepy time he beats a path\nStraight to bedroom or the bath.\nYou alw...

Exercises:

7)  The message

[`4273713B7C`, `1B5E151D5A`, `2A665C2B7F`, `7338671277`, `38637C2704`, `04751D4D73`, `4653531D1D`, `752B7B2A5F`, `742B3D5247`, `743C231736`, `751D5E3E5F`, `6C047A3E31`, `4444232B5F`, `320B711328`, `5E59091622`, `686D434407`, `5476586A65`, `250D0C337D`, `5255253059`, `2557295949`, `7852387820`, `6E40285C58`, `234A2E1C70`, `4A5320524D`, `5105215901`, `7B395F6F1B`, `3607053D0F`, `5A60412E2F`, `441B7E3F3B`, `2E7F1F1564`, `7A35576A73`, `0A47385F62`, `7648485C0F`, `7065726D35`, `7A42560E7C`, `7663753770`, `2F712F6744`, `2B2F18287E`, `54407A715A`, `2C29343F0D`, `3F254E2056`, `242348373C`, `4243073F70`, `2B7E560C75`, `29590B7460`, `707E1D5136`, `282E5E3E5F`, `3E71756A5F`, `18460D120F`, `02266E1976`, `71557C6D79`, `7C6D625C21`, `5E51185230`, `5009422005`, `5639053D0F`, `01436B503B`, `4D42673844`, `6A554C2B45`, `7F33722867`, `5340726A6C`, `03770B7534`, `5D284C3367`, `1332434407`]

was uncrypted with key

seckey := MATRIX([[2, 3, 5, 11, 17], [19, 23, 29, 31, 37], [0, 0, 41, 43, 47], [0, 0, 0, 7, 11], [0, 0, 101, 0, 113]]).

Decode the message

>   

8)  Produce a key of size 5 to encrypt a message of 10 lines.  Post the key and the encrypted message to the bulletin board.

>   

9)  Decrypt somone else's posted message.

>   

10)  Create a shorter worksheet to use to do matrix encryption and decryption.  (The shorter worksheet would be a collection of just the procedures needed.  It could more easily be used for other assignments.

>   

>