Professional Documents
Culture Documents
David Arnold
Abstract
1 Modular Arithmetic
The numbers 1, 2, 3, ::: are called the natural numbers 1
N = f1 g
; 2; 3; : : :
The dots (: : :) indicate that the pattern established by the
rst few natural
numbers continues forever. Hence, 617 is a natural number as is 1,213,456.
The whole numbers include all of the natural numbers and the number zero.
W = f0 ; 1; 2; 3; : : : g
The integer b divides the integer a if and only if there exists another integer
k such that a = kb.
j
b a if and only if there exists an integer k such that a = kb
The notation j
b a is read b divides a.
² 2j12 because 12 = 6 ¢ 2.
² The integer 5 does not divide the integer 12 because it is not the case that
there exists an integer k such that 12 = k ¢ 5.
1
1.1 The Congruence Relation
Two whole numbers a and b are said to be congruent modulo n if and only if n
¹
a = fb : b ´ a(mod n)g
The notation ¹
a is read the equivalence class of a.
¹
3 = fx : x ´ 3(mod 6)g
= fx : 6j(x ¡ 3)g
= fx : x ¡ 3 = 6k, for some integer kg
= fx : x = 3 + 6k, for some integer kg
= f: : : ; 3; 9; 15; : : :g
The equivalence class of the integer 4 is the set of all integers that are congruent
to 4 modulo 6.
¹
4 = fx : x ´ 4(mod 6)g
= fx : 6j(x ¡ 4)g
= fx : x ¡ 4 = 6k, for some integer k g
= fx : x = 4 + 6k, for some integer k g
= f: : : ; 4; 10; 16; : : :g
The equivalence class concept is more easily understood in terms of a con-
struct called clock arithmetic. Lets continue to work with congruence relation
modulo 6. Arrange the numbers 0 through 5 at equidistant arcs around a circle,
as shown in Figure 1.
2 A binary relation is called an equivalence relation if it is reexive, symmetric, and trasivi-
tive. It is not di¢ cult to show that congruence m odulo n is reexive, symm etric, and trasitive,
but we will refrain from doing so here. It is not needed for what we will be doing. See any
numb er theory text for further explanation of equivalence relations.
2
Figure 1 A modulo 6 clock.
2 1
3 0
4 5
3
a particular positive integer belongs. Simply divide the positive integer by n
and note the remainder. For example, when you divide 8 by 6, the remainder
is 2. To perform this operation in Matlab, execute the following instruction.
>> mod(8,6)
ans =
2
Start at 8 on the clock in Figure 2 and make full revolutions in both the
clockwise and counterclockwise directions. This produces the following set of
¹ = : : : ; ¡4; 2; 8; 14; 20; : : :. Of course, these are same integers that
integers: 8
belong to the equivalence class 2. ¹ Therefore, 8 ¹=¹ 2.
If you divide 15 by 6, the remainder is 3.
>> mod(15,6)
ans =
3
Start at 15 on the clock in Figure 2 and take full revolutions in the clockwise
and counterclockwise directions: 15 = : : : ; ¡3; 3; 9; 15; 18; : : :. These are the
Zn = f¹0 ;¹
1; ¹
2; : : : n ¡ 1g
¹
a +¹
b = a +b
¹¹
a b = ab
For example, ¹
3+¹
5=¹
8=¹ 3£¹
2 and ¹ 5 = 15 = ¹
3.
4
Lets drop the bar notation and represent the residue classes ¹
0, ¹
1, ¹
2, ¹
3, ¹
4, and
¹
5 by 0,1,2,3,4, and 5. In other words, the bar over each number is understood.
Next, lets create the following addition and multiplication tables for the residue
classes modulo 6.
+ 0 1 2 3 4 5 £ 0 1 2 3 4 5
0 0 1 2 3 4 5 0 0 0 0 0 0 0
1 1 2 3 4 5 0 1 0 1 2 3 4 5
2 2 3 4 5 0 1 2 0 2 4 0 2 4
3 3 4 5 0 1 2 3 0 3 0 3 0 3
4 4 5 0 1 2 3 4 0 4 2 0 4 2
5 5 0 1 2 3 4 5 0 5 4 3 2 1
>> mod(5*2,6)
ans =
4
Therefore, 5 £ 2 = 4.
5
2 Hill Ciphers
In the world of secret codes an uncoded message is called plaintext. The coded
message is called ciphertext 5 . One way to encode plaintext is with a simple
substitution cipher.
Plain N O P Q R S T U V W X Y Z
Cipher U V W X Y Z A B C D E F G
LINEARALGEBRA
becomes
SPULHYHSNLIYH
N O P Q R S T U V W X Y Z
13 14 15 16 17 18 19 20 21 22 23 24 25
Note that the numbers 0 through 25 are actually the residue classes of the
congruence relation modulo 26. Next, break the plaintext into pairs of letters,
so that
LINEARALGEBRA
becomes
5 For a b eautiful treatm ent of cryptanalysis, read the m onograph Elementary
CryptanalysisA Mathematical Approach, by Abraham Sinkov. Also, Howard Anton and
Chris Rorres give a superb explanation of Hill Ciphers in Elementary Linear Algebra
Applications Version, Wiley.
6
LI NE AR AL GE BR AZ
I have placed a dummy letter Z just to
ll out the last pair. Replace each
letter of each pair of plaintext with the corresponding number from Table 2. If
you place each numerical pair in a 2 £ 1 vector, then the following set of vectors
represents the paired plaintext message.
½· ¸ · ¸ · ¸ · ¸ · ¸ · ¸ · ¸¾
11 13 0 0 6 1 0
P = ; ; ; ; ; ;
8 4 17 11 4 17 25
Because the plaintext is now represented by numbers you can use numeri-
cal operations to encode the message. Weve chosen to pair the letters of the
plaintext message because we intend to use the following 2 £ 2 matrix to do the
encoding. · ¸
2 3
E =
3 4
If you divide 46 and 65 by 26, the remainders are 20 and 13, respectively.
Therefore, · ¸· ¸ · ¸
2 3 11 20
=
3 4 8 13
ans =
46
65
>> mod(E*p,26)
ans =
20
13
7
Code the entire message by multiplying each vector in P by the encoding
matrix E. This results in the following set of cipher vectors.
½· ¸ · ¸ · ¸ · ¸ · ¸ · ¸ · ¸¾
20 12 25 7 24 1 23
C = ; ; ; ; ; ;
13 3 16 18 8 19 22
UN MD ZQ HS YI BT XW
When we used the straight substitution cipher from Table 1, the plaintext
LINEARALGEBRA
became
SPULHYHSNLIYH
LINEARALGEBRA
UNMDZQHSYIBTX
The
rst occurrence of the letter A in the plaintext is replaced by the letter
Z in the ciphertext, the second occurrence of A by the letter H, and the third
occurrence of the letter A by the letter X. This strategy defeats the frequency
analysis of the straight substitution from Table 1.
Method 1. If you use the vectors in P to create a 2 £ 7 matrix, you can speed
up the encoding.
8
>> plaintext=[11 13 0 0 6 1 0;8 4 17 11 4 17 25]
plaintext =
11 13 0 0 6 1 0
8 4 17 11 4 17 25
E =
2 3
3 4
>> ciphertext=mod(E*plaintext,26)
ciphertext =
20 12 25 7 24 1 23
13 3 16 18 8 19 22
It is interesting to note that the
rst column of ciphertext is obtained
by multiplying the
rst column of plaintext by the encoding matrix E. The
second column of ciphertext is obtained by multiplying the second column of
plaintext by E, and so on.
Method 2. You can also use Table 2 to create a single row vector so that
the plaintext
LINEARALGEBRAZ
Note the dummy letter at the end ensures that the length of the vector is
divisible by 2. Use Matlabs reshape command to change the 1 £ 14 row vector
into the previously seen 2 £ 7 matrix6 .
plaintext =
11 13 0 0 6 1 0
8 4 17 11 4 17 25
6 reshape(X,m,n) returns the m-by-n matrix whose elem ents are taken columnwise from X.
An error results if X does not have m*n elem ents.
9
Now you can encode the plaintext as before.
>> ciphertext=mod(E*plaintext,26)
ciphertext =
20 12 25 7 24 1 23
13 3 16 18 8 19 22
3 Potential Project
If you have read your syllabus, then you know that each of you must create a
project that demonstrates the usefulness of linear algebra. This project takes
the place of a
nal exam in this course. During the last week of school you will
make a presentation of your project to the class. This presentation should make
innovative use of technology.
This paper on Hill ciphers has the potential to be expanded into such a
project. If you and your partner could develop a Matlab program that can read
a text
le and encrypt it, then the
le could be sent by email over the internet.
Of course, your project should also design a Matlab program to decipher the
le when it arrives.
4 Homework
1. Consider the congruence relation a ´ b(mod 12). The residue classes mod-
ulo 12 are Z12 = f0 ; 1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11 g.
(a) Construct addition and multiplication tables for the residue classes
modulo 12.
2. Consider the congruence relation a ´ b(mod 8). The residue classes mod-
ulo 8 are Z 8 = f0 ; 1; 2; 3; 4; 5; 6; 7 g.
(c) Under what conditions will a residue class modulo 8 have a multiplica-
tive inverse? Check that your conjecture is true for the remaining
residue classes of Z8 .
3. Use the numerical associations in Table 2 to encrypt the message ITHINKMAT-
LABISGREAT with each of the following encoding matrices.
10
· ¸
8 9
(a) E =
7 8
2 3
1 0 2
(b) F =4 0 3 1 5
0 0 1
4. Add the space character to Table 2 and use the resulting table to code the
message I THINK MATLAB IS GREAT with the following encoding ma-
trix. Hint: Your table no longer has 26 characters. It has 27 characters.
· ¸
4 5
E =
5 2
11