Groups, Modular Arithmetic, and Cryptography: Jean Mark Gawron
Groups, Modular Arithmetic, and Cryptography: Jean Mark Gawron
Cryptography
2004 July 24
2
Preface
The inspiration for this compilation of mathematical material comes from
W. W. Sawyer’s Prelude to Mathematics, an eclectic and beautiful tour of some
of the most important ideas in mathematics, among them, matrices, groups,
and non-Euclidean geometry. The book is unique both in the sophistication
of its presentation and in the little background it assumes. Basically what is
assumed is a reader willing to work a little.
The topics Sawyer discusses are chosen in part on aesthetic grounds. They
all represent areas of what mathematicians call great mathematical beauty. To
acheive that status a mathematical idea requires a certain amount of purity,
distance from any of those crude particulars that infect mathematical applica-
tions. Yet in another sense what endows Sawyer’s diverse ideas with their power
is precisely that they have applications. It is the fact that these simple struc-
tural elments plug into so many diverse apparently unrelated areas that makes
the mathematics beautiful. Non-Euclidean geometry is the root of a body of
work that shows that geometries other than Euclidean are both coherent and
conceptually fruitful. Both of Einstein’s theories of relativity may be understood
as such alternative geometries. Matrices have numerous mathematical lives. To
mention just a random sample: they are used as operators in 3D geometry, as
representations of Hidden Markov Models, as representations of permutations
(discussed in Chapter 1).
[3 factors in the growth of PK crypto: (a) processing power (old days: chips)
(b) dsitributed computing [Lotic: Iris: Notes] (c)internet ]
Contents
1 Introduction 7
2 Groups 9
2.1.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.2 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.2.3 Roots of x3 − 1 = 0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.2.4 Permutations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.2.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.3 Subgroups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.3.1 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2.3.2 Morphisms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3 Modular Arithmetic 31
3.1.1 Remainders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3
4 CONTENTS
3.1.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.2 Grouphood . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.2.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
3.3.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
3.3.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
4.1.1 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
4.4.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.2.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
5.2.10 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
6 Appendix 81
Introduction
7
8 CHAPTER 1. INTRODUCTION
Groups
A group (G, ◦) begins with a set of objects G that can be combined with some
binary operation ◦. There are two main intuitions connected with the operation.
First what we’ll call completeness or closure. The operation is defined for
every pair of objects in the set and always produces another member of the set.
Second, there is an identity element and every member of the set has an inverse
element for that operation. As we’ll see, this second property is connected with
the idea that equations using this operation on unknowns can be solved with
familiar techniques from basic algebra.
9
10 CHAPTER 2. GROUPS
Much of our focus in this book is on groups with a finite number of members,
for which the following notion is useful:
Definition 2.1.2. Order of a Group
Note that the natural numbers ℵ are not a group under addition. The natural
numbers do not include numbers less than 0, so additive inverses are excluded.
But note that the integers under multiplication are not a group. Closure, asso-
ciativity and identity are satisfied, with 1 being the identity element. But the
inverse of an integer under multiplication is generally not an integer.
Consider the case of multiplication again. The set of integers does not give
a group under the operation of multiplication because the inverses for that op-
eration are not included in that set. If however we consider the set of rational
numbers witten Q (all numbers expressable as a ratio between natural num-
bers), then fractions and whole numbers alike are included ( 15 is included along
with its inverse 51 ) But this is not quite good enough because there is still one
element missing an inverse, 0 (what do you multiply 0 by to get 1?) So the final
requirement in defining a group under multiplication is to exclude 0:
The set of positive rationals (written P) is therefore also a group, since the
product of two positive numbers is positive and since the identity element and
inverses are included.
The next theorem gets at the notion of why groups have solvable equations.
Theorem 2.1.1. Cancellation
Proof:
12 CHAPTER 2. GROUPS
We show the proof for case (a). Case (b) is symmetric. Assume:
a◦b=a◦c
Q.E.D.
What Theorem 2.1.1 essentially tells us is that given an a and the result of
combining a with any other element b, b is recoverable (the operation can be
cancelled).
To solve: 5 · x = 20
(1) 5−1 · 5 · x = 5−1 · 20 Inverse Axiom
(2) (5−1 · 5) · x = (5−1 · 20) Associative Axiom
(3) 1 · x = 4 Inverse Axiom
(4) x = 4 Identity Axiom
Note that grouphood guarantees us that all such equations have unique
solutions as long we stick to group members on both sides. This goes along
with the idea that the set we are performing operations on has to be “big
enough” to be a group. If it is big enough to be a group it is big enough to
contain all the solutions to such equations. The set of integers was’nt big enough
to be a group under multiplication and indeed, it isn’t big enough to include
all the solutions to equations involving multiplication, even multiplication with
integers. For example, the solution to
2x = 5
isn’t an integer.
a◦a∈G
2.1. INTRODUCTION TO GROUPS 13
Note that for this notation to make sense i must be an integer. It is important
to remember that this notation doesn’t mean that the integer i is a member of
the group, or that the operation between a and i is a group operation. As
we’ll see when we look at some examples, there are lots of groups that have no
integers as members, but even for those groups it makes sense to write ai for i
repeated applications of the group operation ◦ to a.
Note also that every so often this notation will conflict with ordinary arith-
metic usage. So within (Z, +)
12 = 1 + 1 = 2
23 = 2 + 2 + 2 = 6
ai = b
(−1)2 = 1
(−1)3 = −1
11 = 1
12 = 2
..
.
1n = n
14 CHAPTER 2. GROUPS
but it does not generate the entire group because it does not generate the
negative integers.
We’ll see some more interesting cases of group generators next chapter.
2.1.2 Exercises
G = {a, b, c, d, e, f }
and ◦ is defined by the following table (note e in this case is not necessarily
the identity element):
(G, ◦)
a b c d e f
a a b c d e f
b b d f a c e
c c f b e a d
d d a e b f c
e e c a f d b
f f e d c b a
(a) Refute or verify the grouphood of (G, ◦). You may assume the
operation is associative.
(b) Compute e5 .
(c) Refute or verify the grouphood of (G’, ◦) where
G’ = {a, b, d}
3. Show that
−1
a−1 =a
4. Show that
If a−1 = b−1 then a = b
2.2. EXAMPLES 15
2.2 Examples
We needed to expand our view from the natural numbers to all integers to form
a group under addition, from integers to all rationals excluding 0 to get a group
under multiplication.
If we continue to expand our view to real and complex numbers, < and C,
still excluding 0, we still have groups under multiplication.
p⊕q
We can represent the exact definition in the form of what is called a truth
table:
This is the way the logician would represent the definition of ⊕. This way
of representing the information will be important later on in the course. To
an algebraist all this talk of ps and qs and things that bear truth values is
unnecessary clutter. The meat of the matter may be expressed in the following
table:
Algebraist’s Exclusive Or (2.2)
T F
T F T
F T F
Note that (2.1) and (2.2) define the same operation on truth values.
2.2.3 Roots of x3 − 1 = 0
One of these roots is 1,which will be the identity element and therefore its
own inverse. The other two are complex numbers.
To see this, the formula for solving a quadratic equation of the form:
ax2 + bx + c = 0
is: √
b2 − 4ac
−b ±
x= (2.4)
2a
The parameters a,b, and c in (2.3) are all equal to 1. PLugging those values
into (2.4), we get:
√
−1 ± 1 − 4
x = (2.5)
2
√
−1 ± −3
= (2.6)
2√
−1 ± 3i
= (2.7)
2
(2.8)
2.2. EXAMPLES 17
The fact that these numbers are also cube roots of 1 follows from (2.12) and
from the very peculiar fact that these numbers are each other’s square roots as
well! That is:
√ !2 √
−1 + 3i −1 − 3i
=
2 2
and
√ !2 √
−1 − 3i −1 + 3i
=
2 2
It turns out that there is only one way for things to work out in a 3-element
group. If a and b are the two non-identity elements then it has to turn out that
a2 = b
b2 = a
and it has to turn out that a and b are each other’s inverses. Therefore it has
to be the case that:
a3 = b3 = e
The reader should verify that:
a b e
a b e a
b e a b
e a b e
is the only possible definition for the operation ◦ if h{a, b, c }, ◦i is a group and
the set really has 3 distinct members. In particular consider how the following
operation table is excluded:
a b e
a e ? a
b ? e b
e a b e
18 CHAPTER 2. GROUPS
This is the case where a and b are their own inverses. The ?’s can be replaced
with any of the 3 elements. In all cases, the resulting system will not be a
3-member group. HINT: Consider what the Cancellation theorem has to say
about how the ‘?’ s must be filled in.
2.2.4 Permutations
A → B
B → C
D → E
..
.
Y → Z
Z → A
This cipher would transform the message, ”hello world” as follows:
H E L L O W O R L D
⇓ ⇓
I F M M P X P S M E
This kind of cipher, where each letter is shifted a constant amount, is called a
shift cipher.
A → D
B → E
D → F
..
.
Y → B
Z → C
Readers interested in keeping their communications secure are counseled not to
use a shift cipher. After all there are only 26 of them and it wouldn’t take a
2.2. EXAMPLES 19
computer very long to figure out which one encodes any particular message. In
fact, though it might take a few cycles longer, no cipher is secure.
Then the above function σ can be turned into a matrix with the following
convention:
aij = 1 only if σ(i) = j
Otherwise, aij = 0
For ease of display let’s use for our first example an alphabet with only five
letters to permute. Thus our σ is entirely given by:
σ(0) = 3
σ(1) = 4
σ(2) = 0
σ(3) = 1
σ(4) = 2
means 0 gets mapped to 3. Reading the next row, which tells us what 1 gets
mapped to: 1 gets mapped to 4. And so on. Note that the fact this is a shift
cipher (the symbols are shifted by a constant amount) is reflected by the fact
that on succesive rows the 1s are shifted 1 column over (putting them on a
diagonal).
As a second example, the shift that shifts letters just one value (call it S) is:
0 1 0 0 0
0 0 1 0 0
S= 0 0 0 1 0 (2.14)
0 0 0 0 1
1 0 0 0 0
The shift that goes to opposite extreme and shifts everything 4 letters (call it
X) is:
0 0 0 0 1
1 0 0 0 0
X= 0 1 0 0 0 (2.15)
0 0 1 0 0
0 0 0 1 0
Note that in a properly drawn permutation matrix each row and each column
should have exactly one 1. That is, each input symbol (row) should get mapped
to some output symbol and to only one output symbol. And each output symbol
(column) should come from some input symbol and only one input symbol.
The intuition of the definition, to the extent there is one at this point, can
be stated by the following procedure. Consider A, an m by n matrix, and B,
an n by l matrix, We fill cell cij of C by taking the ith row of A and combining
it with the jth column of B. The ith row of A can be thought of as an 1 by n
matrix and the jth column of B as an n by 1 matrix:
b1j
b2j
..
ai1 ai2 . . . ai(n−1) ain ·
.
b(n−1)j
bnj
Now multiply each cell of the A row with the corresponding cell of the B column.
This gives us n products. The value of cij is the sum of these n products.
For example,
0
0
00010 · 1 =
0
0
= (0 · 0) + (0 · 0) + (0 · 1) + (1 · 0) + (0 · 0)
=0+0+0+0+0
=0
to the character 3:
A= 00010
To compute the encoding of A by the shift cipher B in (2.13) we simply matrix
multiply A by B. That is, we compute C = A · B:
A · B =C (2.17)
0 0 0 1 0
0 0 0 0 1
00010 ·
1 0 0 0 0 = 01000
0 1 0 0 0
0 0 1 0 0
This says character 3 gets mapped to character 1 by the shift-3 permutation.
Figure 2.1 shows the step-by-step multiplication with the relevant column in
bold:
S · B = X
0 1 0 0 0 0 0 0 1 0 0 0 0 0 1
0 0 1 0 0
0 0 0 0 1
1 0 0 0 0
0 0 0 1 0 · 1 0 0 0 0 = 0 1 0 0 0
0 0 0 0 1 0 1 0 0 0 0 0 1 0 0
1 0 0 0 0 0 0 1 0 0 0 0 0 1 0
(2.18)
In the exercises, we informally verify that the set of n by n permutation matrices
form a group under matrix multiplication.
0 0 0 1 0
0 0 0 0 1
00010 ·
1 0 0 0 0
= 0
0 1 0 0 0
0 0 1 0 0
C00 = (0 · 0) + (0 · 0) + (0 · 1) + (1 · 0) + (0 · 0)
C00 =0
0 0 0 1 0
0 0 0 0 1
00010 ·
1 0 0 0 0
= 01
0 1 0 0 0
0 0 1 0 0
C01 = (0 · 0) + (0 · 0) + (0 · 0) + (1 · 1) + (0 · 0)
C01 =1
0 0 0 1 0
0 0 0 0 1
00010 ·
1 0 0 0 0
= 010
0 1 0 0 0
0 0 1 0 0
C02 = (0 · 0) + (0 · 0) + (0 · 0) + (1 · 0) + (0 · 1)
C02 =0
0 0 0 1 0
0 0 0 0 1
00010 ·
1 0 0 0 0
= 0100
0 1 0 0 0
0 0 1 0 0
C03 = (0 · 1) + (0 · 0) + (0 · 0) + (1 · 0) + (0 · 0)
C03 =0
0 0 0 1 0
0 0 0 0 1
00010 · 1 0 0 0 0
= 01000
0 1 0 0 0
0 0 1 0 0
C04 = (0 · 0) + (0 · 1) + (0 · 0) + (1 · 0) + (0 · 0)
C04 =0
onto. Because each row in a group Cayley table contains all the members of G
with no repetitions , each row represents a permutation of G. For example, here
is the b row in a group with 4 elements. This row maps a to c, b to e (b is its
own inverse), and so on:
a b c e
...
b c e a b
...
What we have argued in this section, using the special case of 5 by 5 matrices
in our examples, is that the set of permutations of a set is a group under
composition. We have not drawn the Cayley tables for our permutation groups
because they get rather large. There are 25 permutations of a set of 5 elements,
so the Cayley table has 625 cells (25 by 25).
2.2.5 Exercises
1. Prove the associativity, identity, and inverse axioms for ({T, F}, ⊕).
2. Here are the truth tables for some more operations on truth values. Which
form the basis of a group?
(b) Or (∨)
p q p∨q
T T T
T F T
F T T
F F F
p q p↔q
T T T
T F F
F T F
F F T
3. Compute
S·X
where S and X are as in example (2.18).
2.3 Subgroups
The set of even integers forms a subgroup of the set of integers under ad-
dition. The sum of two even numbers is even; the inverses of even numbers
are even, and the identity element, 0, is even. Notice that each subgroup must
include the identity element in order to be a group. The set of odd integers
does not form a subgroup under addition because closure fails (the sum of odd
integers is even); note also the identity element 0, is not odd. In general, the
set of numbers divisible by any integer n will form a subgroup of the integers
under addition. The reader should verify this.
ai = e
ai = e = a0
ai+1 = a = a1
ai+2 = a2
..
.
ai+n = an
and for all higher values of j, we cycle through previously encountered values.
Clearly closure is satisfied. Every power of a combined with another power of a
gives a power of a. Note also that:
We can similarly find an inverse for every other element of H. Note that H
satisfies the definition of a cyclic group given in Definition 2.1.4. Element a is
its generator.
As an example, for the exclusive-or group given in Section 2.2.2, the order
of T was 2, so T in fact generates the whole group, and the order of F is 1.
It turns out that if we restrict our attention to finite groups, all elements
generate a subgroup. There are no elements of infinite order in finite groups.
We leave the proof as an exercise, explained in more detail in Section 2.3.1.
2.3.1 Exercises
ak = a−1
Don’t think too hard about this. Given the result of the previous exercise,
this does follow pretty straightforwardly.
2.3.2 Morphisms
f : G → G0
f (a ◦ b) = f (a) ◦0 f (b)
Recall that the set of positive rationals P is a group under multiplication and
the set of rational numbers Q is a group under addition. Then the log function
2.3. SUBGROUPS 29
For example:
log 1 = 0 (2.20)
log 10 = 1 (2.21)
log(10 ∗ 1) = 1+0=1 (2.22)
log 1000 = 3 (2.23)
log(10 ∗ 1000) = 1+3=4 (2.24)
φ : n 7→ g n :
g0 = e
−1
g −n = (g n )
30 CHAPTER 2. GROUPS
φ(m + n) = g m+n = g m ◦ g n
Modular Arithmetic
3.1.1 Remainders
{x | ∃q ∈ ℵ [(q · 7) + 4 = x] }
Examples:
4, 11, 18, 25, 32, 39
Notice if we arrange these numbers in ascending order they form a series. You
add 7 to the last element to get the next. Now consider the set of numbers that
give a remainder of 3 when divided by 7.
{x | ∃q ∈ ℵ [(q · 7) + 3 = x] }
Examples:
3, 10, 17, 24, 31, 38, . . .
Notice we again have a series. And again you add 7 to the last element to get
the next.
We say that the first set the set of numbers is congruent to 4 mod 7 and that
the second the set of numbers congruent to 3 mod 7. We use the symbol ≡ to
express the congruence relation. For example we write:
4 ≡ 11 ≡ 32 mod 7
31
32 CHAPTER 3. MODULAR ARITHMETIC
39 ÷ 7 = 5 remainder 4
39 ≡ 4 mod 7
All we need is the set of remainders when dividing by 7, 0 through 6. Thus
arithmetic modulus 7 has 7 numbers.
2+3=5 mod 7
2+4=6 mod 7
2+5=0 mod 7
2+6=1 mod 7
..
.
The complete addition table for addition mod 7:
0 1 2 3 4 5 6
0 0 1 2 3 4 5 6
1 1 2 3 4 5 6 0
2 2 3 4 5 6 0 1
3 3 4 5 6 0 1 2
4 4 5 6 0 1 2 3
5 5 6 0 1 2 3 4
6 6 0 1 2 3 4 5
What we have looked at examples of thus far is modulus 7, but there are
moduli for every integer, with congruence defined exactly analogously to our
definition for modulus 7
Take a moment to ponder what equation 3.2 says: It says it doesn’t matter
where you perform the addition. You can do ordinary addition and then take the
3.1. MODULAR ARITHMETIC 33
modulus (the right-hand-side) or you can take the moduli of the two operands
first and then do the addition modulus 7 following the table in (3.1). You get
the same answer. An example. Let’s do 39 + 75 using ordinary addition first:
39 + 75 = 114
114 = 16 · 7 + 2
(39 + 75) ≡ 2 mod 7
Now the other way, modular conversion first:
39 = 5 · 7 + 4
39 ≡ 4 mod 7
75 = 7 · 10 + 5
75 ≡ 5 mod 7
5 + 4 ≡ 2 mod 7
Both computations yield 2 as the answer.
We write
g|n
when integer g divides integer n evenly. This is the same as saying:
g≡0 mod n
The set of numbers that is congruent to 0 mod 7 can also be arranged in a
series:
0, 7, 14, , 21, 28, . . .
Notice that if you subtract any member of the series from any other you get a
multiple of 7. Notice the same is true of the modulus 4 and modulus 3 series’.
The following theorem shows why this is not an accident.
Theorem 3.1.1. a ≡ b mod n if and only if n | (a − b).
(a − b) = (q1 · n − q2 · n) + r1 − r2
(a − b) = (q1 − q2 ) · n + r1 − r2
r 1 = r2
And therefore
a≡b mod n
Q.E.D.
3.1.2 Exercises
R = {hx, yi | 7 | (x − y)}
3.2 Grouphood
0 1 2 3 4 5 6
0 0 1 2 3 4 5 6
1 1 2 3 4 5 6 0
2 2 3 4 5 6 0 1
3 3 4 5 6 0 1 2
4 4 5 6 0 1 2 3
5 5 6 0 1 2 3 4
6 6 0 1 2 3 4 5
Next does each element have an inverse? What? Find the additive inverses
mod 7:
3−1 mod 7 =?
5−1 mod 7 =?
0−1 mod 7 =?
3+4=0 mod 7
−4 = −1 · 7 + 3
−4 ≡ 3 mod 7
This is all quite fortunate since this is the only way the law of modular addition
as laid out in (3.2) could be validated for (−4 + 4). Doing ordinary addition
followed by modular conversion, we have:
−4 + 4 = 0
0 ≡ 0 mod 7
−4 ≡ 3 mod 7
4 ≡ 4 mod 7
3 + 4 ≡ 0 mod 7
n ≡ x mod 7
Thus each member of the residue set R represents an equivalence class of integers
and there are enough such classes to handle all the integers. As we saw in
Exercise 1 of Section 3.1.2 the equivalence classes can be defined directly in
term of the following relation
{ha, bi | n | (a − b)}
This sorts the inters into 7 equivalence classes, each representable by a distinct
member of R.
How would you compute with R’? Well there is no doubt R is a lot more
convenient, but you can convert any integer n into a congruent member x of R’
as follows:
n ÷ 7 = y Remainder r
x = r + 35
3.2. GROUPHOOD 37
Thus in principle we can use any residue class we want. All we need is some
way of making sure that pick out one and only one member from each of the
equivalence classes to use as the representative.
So the two criteria are completeness, enough equivalence classes to cover the
integers, and minimality, no distinct elements of R are congruent. It follows
directly from the way we constructed R in the previous section that R is a
complete residue system.
The next theorem gets at the idea that certain operations on a complete
residue set like R are guaranteed to give use another complete residue set be-
cause, after performing the operation, we still have a set with one member from
each equivalence class. This means we can prove modular arithmetic properties
on “easy” set like R above and then transfer them to other sets like R’ above.
{j + x | x ∈ R}
x≡y (3.5)
R’ = {35 + x | x ∈ R}
It turns out that it’s a little trickier to find sets of integers that yield groups
under modular multiplication than it was for modular addition. We start with
an easy case. The set of numbers {1, 2, 3, 4, 5, 6} is a group under multiplication
mod 7.
Multiplication Mod 7 (3.7)
1 2 3 4 5 6
1 1 2 3 4 5 6
2 2 4 6 1 3 5
3 3 6 2 5 1 4
4 4 1 5 2 6 3
5 5 3 1 6 4 2
6 6 5 4 3 2 1
The standard notation for this group is Z∗7 The Z stands for integers, the aster-
isk and subscript 7 tell us we are interested in the operation of multiplication
mod 7.
Clearly the identity element in (3.7) is 1. Each row has a 1, so each element
has a right inverse; and each column has a 1, so each element has a left inverse.
1 2 3 4 5
3 3 0 3 0 3
S = {1, 2, 3, 4, 5 }
3x ≡ 3 mod 6
It turns out that if we restrict our attention to integers i, 0 < i < 6, and
exclude the trivial case of {1}, the only set that gives us a group under multi-
plication mod 6 is:
{1, 5 }
Not coincidentally, it turns out that 1 and 5 are the only integers in this range
that have inverses mod 6. The operation table looks like this:
1 5
1 1 5
5 5 1
5 · 5 = 25 ≡ 1 mod 6
The trick to constructing a group for each modulus is to find a set of numbers
such that all have an inverse.
Clearly for arbitrary n not every set of integers greater than 0 and less than
n yields a group. Which sets form a group? Which ones don’t? As the example
of multiplication mod 6 suggests, this question is closely related to the question
of what numbers have modular inverses. Is there an interesting answer to this
40 CHAPTER 3. MODULAR ARITHMETIC
question? [There might not be. The answer might always be: Do your times
tables.] As it turns out there is an interesting answer.
From this and some simple arithmentic, it will follow that for any modulus
n, the set of numbers relatively prime to n and less than n form a multiplicative
group we call
Z∗n .
As a special case, Z∗n for prime numbers includes all the integers from 1 to
(n − 1), which is why 1 through 6 made a group under multiplication mod 7. It
is the grouphood of this kind of system, and the implied existence of inverses
that comes with it, that will make such systems of interest for cryptography.
To show this will require some background laid out in the next few sections.
3.2.3 Exercises
1. Is:
({x | 0 ≤ x < n}, + mod n )
a sub-group of (Z, +) (the group of all integers under addition)? Why or
why not?
2. Show that the set of integers relatively prime to 9 form a group under
multiplication modulo 9.
{1, 2, 4, 5, 7, 8}
Don’t forget to verify completeness.
When
y | a and y | b
We say y is a common divisor of a and b. We call the greatest such number the
greatest common divisor of a and b. We write:
GCD(y, n) = g
Examples:
3.3. EUCLID’S ALGORITHM AND EUCLID’S EXTENDED ALGORITHM41
52 = 4 · 13 = 22 · 13
96 = 32 · 3 = 25 · 3
2. 2 is a common divisor of 52 and 96, but not the greatest common divisor.
When
GCD(y, n) = 1
we say y and n are relatively prime. This is also written:
y⊥n
There is an algorithm for discovering the GCD of two integers first written up
by Euclid but apparently known for some time before that. This puppy has
withstood the test of time. It is implemented today basically as he drew it up.
As a special case it will reveal when two integers are relatively prime, because
the GCD will then be 1.
1. Show the basic Euclid Algorithm which finds the GCD of two numbers y
and n.
Figure 3.1 shows the computations for the case of 52 and 96. The algorithm
yields the answer 4, which is correct.
dividend
quotient =
divisor
3.3. EUCLID’S ALGORITHM AND EUCLID’S EXTENDED ALGORITHM43
The last two inequalities are true in virtue of the definition of remainders: a
remainder is always smaller than the divisor that leaves it. The point here is
that in each succeeding round the values of l, s and r are smaller than they
were the round before. Since all three values are guaranteed to be integers s
will sooner or later be 0 or 1. When s is 0 we’re done. When it’s 1 we’re done
in the next round, because 1 divides any number with remainder 0.
l1 = q1 · s1 + r1
Finally we are guaranteed to reduce the problem to one of finding the greatest
integer that divides ln and sn where
ln = qn · sn + 0
The argument is clear and ultimately very simple. What is really interesting
is that after all these centuries no one has found a better shortcut for finding
GCDs. You have to go through a chain of divisions, and pretty much Euclid’s
chain, to get the right answer in general.
2. If not, set ln+1 to be sn and set sn+1 to be ln mod sn and go back to step
one.
You will often see the algorithm presented this way. This is possible because
it is the remainder and not the quotient that matters in each round and the
quotient is precisely what the modular notation throws away. Thus in place of
the calculation in round 2 of Figure 3.1 that
44 = 5 · 8 + 4
in which 5 is the quotient, we would write simply:
44 ≡ 4 mod 8
In the next section, however, we present an extended version of Euclid’s algo-
rithm in which the values of the quotients are not thrown away. To make the
relationship between the extended and unextended algorithm clearer, we present
the calculations in Figure 3.1 using quotients.
3.3.2 Exercises
them l, s and r. One problem with this is that the same number gets three
different names as we progress through the rounds. The number that plays the
remainder role in round 0 is r0 , but that same number plays the s role in round
1 (s1 ) and then the l role in round 2 (l2 ). (see Figure 3.1). For purposes of
proving something about Euclid’s algorithm it will be useful to consistently use
one name for each value. Thus, in the following discussion we look at things
only from the l point of view. The two arguments a and b will get set to be l0
and l1 and we will refer to the first remainder only as l2 . Consistent with this
policy, we will say the algorithm terminates when li = 0 and the GCD we are
computing is li−1 (Compare Figure 3.1).
Theorem 3.3.1. If g is the Greatest Common Divisor of a and b then there
exist integers λ and µ such that4
g =λ·a+µ·b (3.10)
Sketch of proof. We are going to prove for each of the li in Euclid’s algorithm
that it can be expressed in the form of Equation 3.10. Then, in particular, that
will be true for the last li but one, which is the GCD of a and b. We show it
first for the first two li s, l0 and l1 . These are what we call the base cases below.
Then we show that if it holds for li−1 and li , it must hold for li+1 .
STEP ONE: The base cases: l0 and l1 . These can be expressed in the form
of Equation 3.10 as follows:
l0 = a; l1 = b
λ µ
l0 = 1 · a + 0 · b 1 0
l1 = 0 · a + 1 · b 0 1
STEP TWO: We now need a general way to find values for λi+1 and µi+1
given values for li−1 , li and λi and µi . First we restate the procedure of Euclid’s
algorithm for finding li+1 in terms of the previous two ls:
Again, this is not supposed to be obvious, but it works. Here’s the proof.
First we are assuming that the previous two li s can already be expressed in the
4 The fancy terminology for this is that g is a linear combination of λ and µ.
46 CHAPTER 3. MODULAR ARITHMETIC
What we now need to show is that, given (3.11), (3.12), and (3.13),
g =λ·a+µ·b
Step One: Theorem 3.3.1 is a proof that g is a positive integer that can be
expressed as a linear combination of a and b.
Step Two: Suppose there were a smaller positive integer l, 0 < l < g, such
that
l = λ1 · a + µ1 · b
By assumption g | a and g | b. Therefore g divides l:
l λ1 · a µ1 · b
= +
g g g
l
g is the sum of two integers and therefore must be an integer. But then, l is a
positive integer such that g divides it. But then l < g is impossible. Therefore
there cannot exist such an l and therefore g must be the least positive integer
expressible as a linear combination of a and b. Q.E.D.
Figure 3.2 shows the calculations for Euclid’s algorithm using the example
of 96 and 52, whose GCD is 4. The step marked l1 , l2 is the initialization step
in which both l1 and l2 are set, along with their corresponding initial λs and µs.
Each succeeding section of the figure is marked with the l-value computed
in that step. In general each step shows the process of computing li+1 given li
3.3. EUCLID’S ALGORITHM AND EUCLID’S EXTENDED ALGORITHM47
l1 = 96; λ1 = 1; µ1 = 0
i l λ µ
l2 = 52; λ2 = 0; µ2 = 1
l1 , l2 1 96 1 0
96 = (1 · 96) + (0 · 52)
2 52 0 1
52 = (0 · 96) + (1 · 52)
and li−1 . In each case the first computation involves computing the quotient qi
from the rounded-down ratio of li−1 to li . Then the next li+1 is the remainder
of li−1 divided by li (or li−1 mod li ). This is computed by subtracting li · qi
from li−1 . Similarly µi+1 is computed by subtracting µi · qi from µi−1 and λi+1
by subtracting λi · qi from λi−1 .
The answer is the li that divides li−1 exactly. This is found in the l5 section
when l5 is determined to be 4. The algorithm terminates with l6 in the next step
when l6 is determined to be 0. Thus the answer is the remainder that causes
the next remainder to be 0.
The computations determining each l, λ and µ are shown in the right hand
column of Figure 3.2. The calculation below the line in figure 3.2 shows that
each li can be expressed as a linear combination of 96 and 52, using λi and µi
as the linear weights.
3.3.4 Exercises
1. Find the GCD of 108 and 42 and a linear combination that expresses it,
using Euclid’s extended algorithm.
3. Find the inverse of 53 mod 175 using Euclid’s extended algorithm. Pretty
much the same notes as in the first problem, except that this time your
answer should be a positive number i such that 0 < i < 175.
λy + µn = 1.
But then:
µn = 1 − λy
n | 1 − λy
λy ≡ 1 mod n Theorem 3.1.1
Therefore y has an inverse mod n, namely λ.
λy ≡ 1 mod n
Group Properties of
Multiplicative Groups
Recall that Z∗n is pairs the set of positive integers relatively prime to n and less
than n with the operation of multiplication mod n. In this section we prove
the following theorem.
Z∗n is a group.
4.1.1 Exercises
1. Complete the proof of Theorem 4.1.1 by showing that the modulus of the
product of two numbers relatively prime to n is relatively prime to n. In
51
52 CHAPTER 4. GROUP PROPERTIES OF MULTIPLICATIVE GROUPS
symbols:
If: i⊥n
j⊥n
Then: (i · j) mod n ⊥ n
Hint: First show i · j ⊥ n if i, j ⊥ n. Then show that p ⊥ n if and only if
p mod n ⊥ n. For this step, it may help to represent p as:
The Z∗n groups are the groups that are important for cryptographic applications.
In this section we illustrate some important structural properties of these groups,
focusing on cyclic subgroups. Recall that these groups are formed by iterated
applications of the group operation to a single element, raising to a power.
As an example let us return to Z∗7 . It turns out that Z∗7 is a cyclic group for
which 3 is a generator, since every element of the group can be expressed as a
power of 3 (Cyclic groups are introduced in definition 2.1.4):
1 = 36 mod 7
2 = 32 mod 7
3 = 31 mod 7
4 = 34 mod 7
5 = 35 mod 7
6 = 33 mod 7
Note that not every member of the group generates it. For example, 2 is not a
generator for the entire group It generates only the set {1, 2, 4 }
2 = 21 mod 7
4 = 22 mod 7
1 = 23 mod 7
2 = 24 mod 7
4 = 25 mod 7
1 = 26 mod 7
More precisely, Is it the case that for any element a of any Z∗n , ord(a), the
order of a, divides | Z∗n |?
4.2. SUBGROUPS AND COSETS OF MULTIPICATIVE GROUPS 53
Recall that for any finite group G, and any a ∈ G, the set:
The proof will hinge on the notion of a coset, which is a set that can be
constructed once a subgroup is given:
Definition 4.2.1. Coset
H = {1, 2, 4 }
3 · H = {3, 6, 5 }
Note that this coset is both the same size as the subgroup H and disjoint from
it. These properties too are not accidents.
Consider:
1 · H = {1, 2, 4} = H
2 · H = {2, 4, 1} = H
3 · H = {3, 6, 5}
4 · H = {4, 1, 2} = H
5 · H = {5, 3, 6} = 3·H
6 · H = {6, 5, 3} = 3·H
Notice there are only two cosets, the original set and one disjoint from it and
the same size.
We will prove LaGrange’s theorem by showing that any subgroup gives rise
to a family of disjoint cosets of equal size
We begin by showing that cosets have the same cardinality as the group that
generates them..
54 CHAPTER 4. GROUP PROPERTIES OF MULTIPLICATIVE GROUPS
| a ◦ H |≤| H |
a ◦ b = a ◦ c Convergence
But the cancellation theorem (Theorem 2.1.1) tells us that in this case, b and
c cannot be distinct. Therefore, the cardinality of the coset a ◦ H must be the
same as the cardinality of H.
We now show:
(a ◦ H) ∩ (b ◦ H) 6= ∅ (4.2)
a◦s=b◦t (4.3)
But then:
a = b ◦ t ◦ s−1 (4.4)
a ◦ x = b ◦ t ◦ s−1 ◦ x (4.5)
4.3. LAGRANGE’S THEOREM 55
t ◦ s−1 ◦ x ∈ H
b ◦ t ◦ s−1 ◦ x ∈ b ◦ H (4.6)
a◦x∈b◦H (4.7)
Thus
a◦H⊆b◦H (4.8)
b = a ◦ s ◦ t−1 (4.9)
b ◦ y = a ◦ s ◦ t−1 ◦ y ∈ b ◦ H (4.10)
And therefore:
b◦H⊆a◦H (4.11)
a◦H=b◦H (4.12)
So we have shown that if two cosets of H are not disjoint (4.2), the they are
equal (4.12).
a◦e=a
56 CHAPTER 4. GROUP PROPERTIES OF MULTIPLICATIVE GROUPS
Now by Lemma 4.3.1 each element can occur in at most one of the m cosets.
By Lemma 4.2.1, each of those cosets has cardinality | H |. Therefore:
m· | H |= n =| G |
There is one special case for which φ(n) is trivial. This is when n is prime.
All numbers are relatively prime to a prime, so the the number of numbers less
than n and relatively prime to n is (n − 1).
The function φ(n) is significant because, for any n, φ(n) is the order (the
number of elements) of Z∗n , the multiplicative group of integers that are relatively
prime to n,discussed in Section 3.2.2. Such groups are central to the proof of
Euler’s Theorem.
For clues on how to compute φ(n) for composite numbers, see Appendix 6.1.
4.4. FERMAT’S LITTLE THEOREM AND EULER’S THEOREM 57
ap−1 ≡ 1 mod p
This will fall out as a special case of Euler’s Theorem. We prove that in the
next section.
If a is a relatively prime to n,
aφ(n) ≡ 1 mod n
Recall that this is the group consisting of all the integers i, 0 < i < n, i
relatively prime to n. Therefore | Z∗n | is φ(n). Since a is relatively prime to n,
there is some i ∈ Z∗n such that, a ≡ i. The Corollary of Lagrange’s theorem,
Corollary 4.3.1, tells us that the order of i, ord(i), divides φ(n). So there is
some integer k, such that
ord(i) · k = φ(n)
58 CHAPTER 4. GROUP PROPERTIES OF MULTIPLICATIVE GROUPS
and
k
aφ(n) ≡ iord(i)·k = iord(i) ≡ ek ≡ 1 mod n
So this follows quite straightforwardly from Lagrange’s Theorem.
23 ∼
=1 mod 7
φ(7) = 6 and
2
26 = 23 = 12 = 1 mod 7
c = me mod n
m = cd mod n
4.4. FERMAT’S LITTLE THEOREM AND EULER’S THEOREM 59
Why does it work? Clearly, it had better be the case that cd = m. And it
is. First let’s just review how the pieces were put together:
d
cd = (me ) = me·d mod n (4.13)
Because e and d are inverses mod φ(n), there is some k such that:
e · d = k · (p − 1) + 1
Rewriting the last term in (4.13) we have:
k
me·d = mk·(p−1)+1 = m · mk·(p−1) = m · (m(p−1) ) mod n (4.14)
Because p is prime m is relatively prime to p and therefore Euler’s theorem
applies in this case. So we have:
m(p−1) = mφ(n) ≡ 1 mod n
so the last term in (4.14) reduces as follows:
k
m · (m(p−1) ) ≡ m · 1k ≡ m · 1 ≡ m mod n (4.15)
Which is what we wanted to show.
So encryption and decryption work the way they should. The security of
the algorithm is based on the fact that it is in general quite difficult to take
the e−th root of a number mod n if e is sufficiently large. One reason why no
one uses such an algorithm for encryption is that is far less efficient than most
existing symmetric algorithms, and generally speaking, efficiency is a pressing
concern for encryption software. Thus, without the extra benefits public keys
give, it is not worthwhile encrypting this way.
Example: Let’s try an example with small numbers. In fact, let’s set p
equal to mod 11 ; φ(11) = 10. For our encryption key, we choose an exponent
relatively prime to 10, 3. So to find our decryption key we need to find
3−1 mod 10
Using Euclid’s Extended Algorithm we have:
l0 = 10, l1 = 3
l λ µ
10 1 λ0 = 1, µ0 = 0; λ1 = 0, µ1 = 1;
l0 , l 1 0
10 = (1 · 10) + (0 · 3)
3 0 1
3 = (0 · 10) + (1 · 3)
q2 = b10/3c = 3
l λ µ
10 1 l2 = 10 − (3 · 3) = 1
0
l2
3
λ2 = 0 − 1 · 3 = −3
0 1
µ2 = 1 − 0 · 3 = 1
1 −3 1
1 = 1 · 10 + (−3 · 3)
60 CHAPTER 4. GROUP PROPERTIES OF MULTIPLICATIVE GROUPS
So we have
3−1 = −3 ≡ 7 mod 10
Verifying:
3 · 7 = 21 ≡ 1 mod 10
So we have encryption key 3 and decryption key 7. So let us encrypt a message
one letter long choosing d (the 4th letter, which we represent with the number
4; note that we picked a letter whose numerical representation was less than
11). Encoding then is:
43 mod 11 = 64 ≡ 9 mod 11
4.4.4 Exercises
1. Using 17 as the value for p encrypt and decrypt the letter j using Euler’s
Code. Use either 3 or 4 for your encryption key, whichever is better.
Defend your choice. Show the calculations determining your decryption
key and verify that it is an inverse of your encryption key in the right
modulus.
Chapter 5
• Confidentiality: assurance that only the participants will know the con-
tents of their communication. Business or government secrets.
• Integrity: assurance that the message sent is exactly the message received
by the intended participant.
• Authenticity: assurance that the message really comes from who it says
it comes from
• Non-repudiation: assurance that the real sender cannot deny a file was
sent.
61
62 CHAPTER 5. CRYPTOGRAPHY AND PUBLIC KEYS
With regard to the last item, a few motivating remarks may be helpful. In
certain circumstances to be discussed below, it is important for one participant
in a communication to commit him or her self to a particular piece of content,
say a bit that might be 1 or 0, without revealing what that that bit is. This
may be because of timing issues (the commitment must come early but the the
disclsoure must come late) or it may be because the content is to be revealed
only in certain extraordinary corcumstances.
Several important areas of computer security have been left out of the above
list because they do not create a need for public keys. Thus for example a
central concern for cryptographers is securing stored data or computer systems.
Both these tasks can be done with single key systems and symmetric encryption
algorithms. Thus for example authentication for almost all multi-user systems
uses password programs that protect stored passwords by encrypting them.
However it turns out that the other important idea of this chapter, a one-
way function, does play a role in ordinary system and data security.. We return
to this point below.
It also turns out that public key protocols do sometimes play a role in user
authentication for system access. We return to this point below as well.
One way functions play a central role in public key cryptrography but in this
section we try to motivate the idea within the general context of cryptographic
concerns, independently of keys.
Our first example is a simple case in which the problem is trying to secure con-
tent commitment without content disclosure. It is useful in setting the scene
because it provides a scenario in which the cryptographic problem is not stereo-
5.2. ONE-WAY FUNCTIONS 63
typical. There is no issue of secrecy per se. Thus we have a scenario involving
two characters Alice and Bob in a situation requiring information to be com-
municated, but there is no evil adversary (usually Eve) to be thwarted. Rather
there is a larger concern of trust.
Alice and Bob (the main characters of our little drama) play a game of
heads-or-tails.
Version 1: Alice flips coin. Bob calls it in the air. If Bob gets it right he
wins. If not, Alice wins.
Issues:
• Fair coin
But now add: Alice and Bob are playing over the phone.
How do we do this reliably, assuming Alice and Bob can’t trust each other
completely?
Never mind for now whether such a thing exists. Suppose we had one. Then
agree on the following:
• An even x is heads
• An odd x is tails
64 CHAPTER 5. CRYPTOGRAPHY AND PUBLIC KEYS
This simple protocol shows that one-way functions can play an important
role in securing content commitment without content disclosure.
5. Cipher text. The result of encoding the message with the key. We call
this C.
That’s all.
Convention: E(M,K) = C.
Convention: D(C,K) = M.
Another example of a key is the encryption key we used for Euler’s Code,
discussed in Section 4.4.3. There we noted that we actually needed two different
keys, an encryption key and a decryption key. But since the decryption is
directly computable from the encryption key by Euclid’s Extended Algorithm,
this was no great matter.
E(M)=C
After all, knowing the algorithm does give an adversary a head start on the
problem of cracking the code. If we just use a secret algorithm, keys would be
unnecessary.
1. Short answer: Secrets always get out. Keys are easier to change than
algorithms.
2. Longer answer: Make the algorithms public. Let the smartest mathemati-
cians in the world amuse themselves by trying to find a weakness. Makes
for the strongest possible encryption algorithms.
1. Confidentiality: Only those who know the key can read the message.
66 CHAPTER 5. CRYPTOGRAPHY AND PUBLIC KEYS
2. Authenticity: Bob wants to verify that a messsage came from Alice and
Alice and Bob share a secret key known only to them. Bob challenges Alice
to encrypt a random message, say, “2 is fun!” Only Alice can encrypt it
correctly.
Integrity and nonrepudiation each call for a little something more, but secret
keys can enter into solving these problems as well.
n(n − 1)
1∗2
meetings are neccessary to secure all pairwise communications.
The classic case of this sort is E-commerce, where the secure information
being exchanged is credit card numbers. The fact that there is typically one
merchant and many customers is not the key security feature. The key security
feature is that when a credit card number is transmitted the information must be
sealed off from any participants to any other transaction or any eavesdroppers.
Thus a single symmetric key for the merchant will not suffice. One key is
required for each customer merchant pair, and potentially for each transaction.
What we have called a one-way function allows one to combine publicly available
information with some privately available formation to learn some content which
is then private, for all practical purposes. Often the set of possible contents is
large but not infinite. What a one-way function does, then, is to help choose
from some intractably large set of alternatives. This can be done without the
help of of an actual function.
5.2. ONE-WAY FUNCTIONS 67
Figure 5.2.4 presentes what seems to be the simplest idea, due to Ralph
Merkle1
Alice has to do some work to get her key. In fact for a key 20 bits long the
task of breaking the code takes about 220 (roughly a million) steps. But our evil
eavesdropper Eve has to perform that same task for about 1,000,000 messages,
so that’s
This might be good enough. If Alice and Eve can both try 10K keys per
second, Alice can do her decoding in about a minute on average, but Eve’s
decoding takes her about a year on average.
Note that there is no function here, one way or otherwise. What there is is
a lot of values (Bob’s 1,000,000 messages) and a random choice among them.
The problem is determining what the result of that random choice is. Note that
that determination isn’t impossible, merely computationally difficult. Note that
the amount of security depends on the difficulty of the computation for Eve. If
1 The tale that is told among cryptographers about this is that Merkle took a course in
Eve works for the NSA she might have computational resources several orders of
magnitude better than Alice’s. Then the margin starts to dwindle away quickly.
Moral: A function that is difficult to undo would be better and could maybe
secure a safer security margin without increasing the hassle.
Here are three examples of one-way functions that might give us a better way to
accomplish what Merkle’s protocol was trying to accomplish in the last section.
pq = n ≈ 10200
For example:
p = 8273488995874738949376376607
q = 15263784900967433245564811
n = 126284756413553050978360366248406608817836065776277
55 ≡ 1 mod 11
5.2. ONE-WAY FUNCTIONS 69
√
is quite easy. Obviously for small n 5 x mod n can be computed just by
taking the 5-th power of all the numbers from 1 to (n − 1) until we find
x, but for large n this brute force approach is impractical.
Note that what counts here is not possibility or impossibility but the relative
amount of computing.
We want Alice and Bob to construct a key K they can use for their encryption.
We want them to construct it by communications on an insecure channel. And
of course we want K to be a secret.
Alice and Bob each contribute half the bits, we’ll call Alice’s bits x and
Bob’s bits y. Then we need some easy-to-compute function construct-key which
computes K:
construct-key(x, y) = K
Alice sends
f (x)
Bob sends
f (y)
What we now need is for Alice and Bob to both be able to construct the
same key from what each has:
Alice x f (y)
Bob y f (x)
In fact, we have already discussed functions of the sort we need in Section 5.2.5.
These were multiplication in regular arithmetic and raising to a power in mod-
ular arithmetic; both have which inverses (factoring and discrete logarithms)
which are hard to compute.
The reason these fit the bill is that we don’t need to reach the ideal of
functions that are impossible to run backwards. We just need a function that,
given the complexity of the particular inputs we use, will take an impractical
amount of computing time to compute, say 1000 years.
In fact, the protocol we have just described is the Diffie-Hellman protocol for
key exchange. The one-way function used there is the discrete power function
(inverse: (discrete log function). Details to be given in the next section.
First, Alice and Bob publically agree on on a large prime p and a generator g
of Z∗p (see Section 3.2.2). The protocol goes like this:
X = gx mod p
Y = gy mod p
3. Alice computes
K=Yx mod p
4. Bob computes
K = Xy mod p
5.2. ONE-WAY FUNCTIONS 71
Note that Alice can do her key computation because she knows x, and Bob can
do his because he knows y, but evil eavesdropper Eve doesn’t know either of
those numbers. Moreoever Alice and Bob compute the same key because:
X y = Y x = g xy
f (y) = g y mod p
What we needed next was for Alice and Bob to both be able to construct
the same key from what each has:
Alice x f (y) = Y
Bob y f (x) = X
alt-construct-key(X, y) X y mod p
alt-construct-key(Y, x) Y x mod p
construct-key(x, y) g xy mod p
X y = g x y = Y x = g y x = g xy mod p
72 CHAPTER 5. CRYPTOGRAPHY AND PUBLIC KEYS
5.2.8 Exercises
1. In the Diffie Hellman protocol, Alice and Bob start with a prime p. They
then pick another number g which is a generator of Z∗p . Why must g be
a generator? HINT: The reasons don’t have to do with making the math
correct. They have to do with security.
The RSA protocol (named for its creators, Ron Rivest, Adi Shamir, and Leonard
Adleman) goes as follows:
1. Choose two large random prime numbers p and q and multiply them to-
gether to give n
n=p·q
2. Randomly choose an encryption key e such that e and φ(n) are relatively
prime. Recall that φ(n), Euler’s Totient function, is the number of integers
relatively prime to n. It turns out that for an integer that is the product
of two primes φ(n) is easy to compute when you know the two primes.
3. Use the extended Euclidean Algorithm to compute the inverse of e mod φ(n),
d. That is, find d, 1 < d < φ(n), such that:
d is the decryption key. Note that d and φ(n) are also relatively prime.
Why?
c = me mod n
m = cd mod n
5.2. ONE-WAY FUNCTIONS 73
Why does it work? Clearly, it had better be the case that cd = m. And it
is. First let’s just review how the pieces were put together:
d
cd = (me ) = me·d mod n (5.1)
Because e and d are inverses mod φ(n), there is some k such that:
e · d = k · φ(n) + 1
Now Euler’s theorem applies in this case because we have assumed m is relatively
prime to n. That is:
mφ(n) ≡ 1 mod n
so the last term in (5.2) reduces as follows:
k
m · (mφ(n) ) ≡ m · 1k ≡ m · 1 ≡ m mod n (5.3)
So encryption and decryption work the way they should. The security of the
algorithm is based on the fact that φ(n) is easy to compute for n = p · q if you
know p and q, and very difficult otherwise.
φ(n) = (p − 1)(q − 1)
Since p and q are prime, any integer not relatively prime to n must be a
multiple of p or q. For the same reason, the smallest integer that is a multiple
74 CHAPTER 5. CRYPTOGRAPHY AND PUBLIC KEYS
of both p and q is pq, so there is no overlap between the set of multiples of p that
are less than n and the set of multiples of q that are less than n. The multiples
of p less than n are:
{p, 2p, 3p, . . . (q − 1)p}
There are (q − 1) such multiples. The set of multiples of q less than n is:
There are (q − 1) such multiples. So the size of the set of integers less than n
that are multiples of either p or q is:
(p − 1) + (q − 1) = p + q − 2
φ(n) = (p · q) − 1 − (p + q − 2) (5.4)
= (p · q) − p − q + 1 (5.5)
= (p − 1)(q − 1) (5.6)
To compute φ(n), then all you have to do is factor n. But factoring large
numbers is computationally very difficult; so the security of the algorithm will
also be based on choosing very large p and q and getting an even larger n.
There is of course another way to retrieve m, without figuring out φ(n). This
is to take the eth root of me mod n. But there are no known good algorithms
for doing this either. The nth root problem in modular arithmetic appears to
be at least as hard as if not equivalent to the factoring problem.
First let’s try an example with small numbers. In fact, let’s encrypt one
letter, s (= 19 numerically) using mod 55. We need to find φ(55). Well, it’s
φ(11) · φ(5) = 10 · 4 = 40. For our public key, we choose an exponent relatively
prime to 40, 3. So to find our private key we need to find
3−1 mod 40
2 Note that Since p is a prime all integers less than p are relatively prime to p, so φ(p) is
The appendix shows that this is true whenever p and q are relatively prime.
5.2. ONE-WAY FUNCTIONS 75
So we have
3−1 = −13 ≡ 27 mod 40
Verifying:
3 · 27 = 81 ≡ 1 mod 40
So we have public key 3 and private key 27. So let us encrypt a message one
letter long choosing s (the 19th letter, which we represent with the number 19).
Encoding then is:
As an example with larger numbers suppose Alice two large primes at ran-
dom (There are good algorithms for testing the primality of a number; but
that’s a subject for another text):
(p − 1)(q − 1) = 264 099 224 369 484 953 699 345 893 111 410 100
and uses Euclid’s algorithm to find some e relatively prime to (p − 1)(q − 1):
Let e = 1009
76 CHAPTER 5. CRYPTOGRAPHY AND PUBLIC KEYS
This is Alice’s encryption key, to be made public along with n. Then Alice
computes the inverse of d, using Euclid’s Extended Algorithm:
Bob who wants to send Alice a peculiar message looks up e and n (this pair
is called Alice’s public key) on the internet3 He chooses the following peculiar
message:
m = 33 333 333 333 333 333 333 333 333 333 333 333
Then he encrypts his peculiar message as follows:
c = me mod n = 54 423 731 721 403 481 610 392 517 373 097 210
Alice gets the message and uses her private key, d, to decode it:
m = cd = 33 333 333 333 333 333 333 333 333 333 333 333
This means the same cryptographic tools can also be used to do signatures which
assure authenticity of the message. Here’s how that would work.
If she gets something that looks like a real message that’s good evidence that
it was signed using Bob’s secret key, because only such a message would make
sense when decoded using Bob’s public key. If she wants further assurance she
can send Bob a specific challenge text, such as “Hello, world!”, instructing him
to encode it, and if the encoded version she receives back decodes to “Hello,
3 He might find it on her web-site (see for example [Link] gawron)
world!” using Bob’s public key, then she has very good evidence indeed that it
is really Bob on the other end of the channel.
In real life things are actually more complicated but this presents the main
ideas of the original RSA paper and conveys the key breakthough of public key
cryptography. So this is as good a place as any to stop.
5.2.10 Exercises
1. Consider what has been called the iterated encryption attack on RSA.
The basic idea is to continously re-encrypt the encrypted message c = me
mod n, using the same encryption key, until you have c again:
Now in some cases you will eventually reach a step k such that:
k
Step k c = c(e ) mod n
At this point we can stop encrypting. The attack is complete. The original
message can be recovered. Your mission for this problem is to determine
what m is given that you have reached step k successfully.
The more interesting question of when this can happen and how the iter-
ated encryption attack can be blocked is a matter for another text.
The two public key protocols been presented in this book are the RSA and
Diffie-Hellman protocols. For quite a while these were the two most important
protocols in the area of public key cryptography; arguably they still are though
competitors exist. The important point to make here is that a number of simpli-
fications have been made in the presentations in this chapter. To start with the
versions presented are in both cases textbook versions. A number of practical
issues have been finessed or ignored entirely. This is less of a problem than it
might be because the goal of this book is to explore the relationships between
the applications and the mathematical ideas
78 CHAPTER 5. CRYPTOGRAPHY AND PUBLIC KEYS
The result is that “signed message” he sends Eve is the orginal plain text m.
Moreover it isn’t enough to just be on the lookout for previously encrypted ci-
phertexts. There are numerous undoable transformations that can be performed
on me so as not to make it identical to a previous messaage. There are two ways
to prevent this attack. First, never sign an entire message; rather sign a digest
of a message, where a digest is a number returned by something called a hash
function, which is sensitive to the smallest changes in the message and whose
variation for any given change is very hard to predict. A hash function is thus
another one-way function. Thus if a signed digest is authenticated, one can sure
both that the message is really from the purported sender and that it has not
been altered. The second, equally important practice is never to use the same
publicket/secret key pair for both signature and content encryption.
The original advertised difference between RSA and Diffie-Hellman was that
Diffie-Hellman was a protocol for key exchange and that RSA was a protocol
5.3. PRACTICE VERSUS TEXTBOOK 79
for message encryption and digital signatures. Looking at the textbook ver-
sions, the two protocols ought not to be in competition. But in practice, for
the efficiency reasons just cited, RSA becomes a key-exchange protocol too, and
thus, to acheive secure efficient communication, both protocols need to be sup-
plemented with ordinary symmetric encryption. The underlying mathematics
remains quite distinct as presented here, but the two protocols often fill quite
similar roles in their realizations in actual systems. It is thus not that surprising
that, as a matter of of historical fact, the two companies holding the now-expired
RSA and Diffie-Hellman patents, with different algorithms with different pur-
poses, with their respective MIT and Stanford roots, were ultimately joined
under a single corporate umbrella PKP (Public Key Partners).
Real systems are also built to ensure that failures of one module have as
little effect as possible on other modules. For example knowledge of pairs of
messages and signatures can sometimes be used to predict the signatures on
other messages. Thus it increases security to insulate plain-text/encrypted text
pairs as much as possible from discovery. In this spirit, Ferguson and Schneier
(Ferguson and Schneier 2003) recommend that the actual symmetric session
key K in RSA practice be the result of applying a hash function to the key K’
that is encrypted using RSA. Thus, if the session key K is compromised, and
the message that transmitted it is known, the sequence K’ that gave rise to
K is still unknown (since hash functions are one-way). Let K’ be the original
randomly chosen key and K’e be its RSA encoding, which is transmitted and
made public. Now let h be the hash function. Then:
K = h(K’)
So the computation for getting from the transmitted message K’e to K is:
d
K = h( (K’e ) )
Considering that all we are talking about here is the session key part of the
protocol, before a single word of content has been transmitted, things are already
getting pretty complicated.
Another huge area of practical concern which has gone undiscussed here is
how public keys are to be made available. The whole point of public keys is
— well, that they are public. Accessability is what makes public keys useful,
but it is also what makes them vulnerable. How is Alice to know when she
looks up Bob’s key that the key she finds is authentic? For example, if Alice
downloads the public key from Bob’s web-site, how can she verify that the
site she was linked to at download time was really Bob’s, and not some spoof
site prepared by Eve? There are a variety of answers to such questions and a
useful discussion is beyond the scope of this book., but two general points are
of interest. First, some trusted entity is needed, either a central key authority
or a web of trusted users, from which key information can be obtained and/or
verified. Second, and independently of the first point, there needs to be some
80 CHAPTER 5. CRYPTOGRAPHY AND PUBLIC KEYS
way of verifying keys over a secure channel. A typical choice is that keys are
hashed, producing a manageable sized “fingerprint” which Bob can read over
the phone to Alice; Alice then matches what she hears over the phone to the
fingerprint she generates from Bob’s downloaded key, and is reassured that that
key is authentic. In the end, though, public key infrastructure (PKI) raises a
whole host of new issues that are still being worked out. For instance, when
Alice’s private key is compromised the situation is a good deal more serious than
it is when a symmetric key is compromised, because there is a whole community
of users who still believe they can send Alice secure communications using her
public key.
The point of this section is to underscore that the theory sketched here
is a long way from being practice. Yet as these examples also suggest, the
mathematical ideas discussed here, rooted deeply in the purest branches of pure
mathematics, still play a central role in making the final system secure.
Appendix
1 2 3 4 ... q (6.1)
q+1 q+2 q+3 q+4 ... 2q
2q + 1 2q + 2 2q + 3 2q + 4 ... 3q
.. .. .. .. .. ..
. . . . . .
(p − 1)q + 1 (p − 1)q + 2 (p − 1)q + 3 (p − 1)q + 4 . . . pq
81
82 CHAPTER 6. APPENDIX
prime to q. We then show that every column contains exactly φ(p) numbers
relatively prime to p, so of those φ(q) columns that contain numbers relatively
prime to q, each contains exactly φ(p) numbers also relatively prime to p, so
there are φ(q) · φ(p) numbers that satisfy our criteria. And we are done.
We now turn to our column lemmas. We can rewrite the number x in the
ith row and jth column as:
(i − 1)q + j
The first lemma is about how a number that can be written this way can be
relatively prime to q:
x = (i − 1)q + j (6.2)
Proof: Note first of all that if q and j have a factor greater than 1 in
common, then x also has that factor. If if q and j have a factor in common,
thewn there exists f, r1 , r2 such that:
If j 6⊥ q then x 6⊥ q
Or equivalently:
If x ⊥ q then j ⊥ q
x = f · r1 and q = f · r2
f · r1 = (i − 1)f · r2 + j
f · r 1 − f · r2 = j
f (r1 − r2 ) = j
Therefore j 6⊥ q
So we have:
If x 6⊥ q then j 6⊥ q
Or equivalently:
If j ⊥ q then x ⊥ q
Which is what we wanted to show.
From this lemma it follows that that each column with a j relatively prime
to q consists entirely of integers relatively prime to q. There are φ(q) such j
with 1 ≤ j < q. Therefore.
Column lemma 1: There are φ(q) columns in (6.1) that consist en-
tirely of numbers relatively prime to q.
This is the first of our two column lemmas. The second of our column lemmas
is:
Column lemma 2: Every column in (6.1) has φ(p) numbers that are
relatively prime to p.
It will be easiest to get to this lemma by way of a theorem that concerns the
notion of a complete residue system of integers mod n (this concept was defined
in definition 3.2.1, repeated here).
This lemma taken together with Theorem 3.2.1 immediately leads to the
following theorem:
Theorem 6.1.2. Linear Combination Theorem for Complete Residue Systems
It follows from Theorem 6.1.2 that each column of (6.1) is a complete residue
system mod p. First R is a complete residue system mod p:
R = {0, 1, 2, 3, 4, . . . (p − 1)}
6.2. RSA ALGORITHM: WHAT IF M IS NOT RELATIVELY PRIME TO N 85
q · R + j = {q · i + j | i ∈ R}
Since p ⊥ q, Theorem 6.1.2 applies and q ·R+j is also a complete residue system
mod p.
Any complete residue system mod p has exactly the same modular arith-
metic properties as R. In particular it has the same number of integers with
inverses, φ(p) (recall that any integer with an inverse must be relatively prime
to p, by Theorem 3.4.1).
Thus we have now established both our column lemmas. There are φ(q)
columns consisting entirely of numbers relatively prime to q and for any column,
there are φ(p) integers in it that are relatively prime to p. Since any integer
relatively prime to p · q must be relatively prime to both p and q, there are
φ(q)φ(p) such integers. Which was what needed to be proved.
1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18
19 20 21 22 23 24 25 26 27
28 29 30 31 32 33 34 35 36
Given that n is the product of two primes, the only way m can not be
relatively prime to n is if m is a multiple of one of the two primes. We will take
the case where p | m. The other is symmetric. Note that we cannot also have
that q | m because the smallest number x such that p | x and q | x is p · q and
we assume m < p · q. Since q is a prime it is relatively prime to all numbers
except its multiples and we have just shown m is not a multiple. So q ⊥ m.
First we show (6.5). From Theorem 5.2.1, we know φ(n) = (p − 1)(q − 1).
Recall the e and d are inverses mod φ(n). Therefore e · d ≡ 1 mod φ(n) and
we may represent e · d as:
k(p − 1)(q − 1) + 1
We then have
me·d = m1+(p−1)(q−1)k mod q (6.7)
= m · m(p−1)(q−1)k mod q (6.8)
k(p−1)
= m · (m(q−1) ) mod q (6.9)
k(p−1)
≡ m · (1) = m mod q (6.10)
Step (6.10) invokes Euler’s Theorem, which is justified, since m ⊥ q, q is prime,
and φ(q) = (q − 1).
y ≡ m mod p · q. We have:
(y − m) ≡ 0 mod (p · q)
y ≡ m mod (p · q)
We have have now shown that any y that has the two properties in (6.13) is
congruent to m mod p · q. Since med is one such y , it follows that:
med ≡ m mod (p · q)
med ≡ m mod n
1 Note: The proof given here is actually a special case of what is known as the Chinese
Remainder Theorem, for those following along in other texts. The Theorem states that if
m ⊥ n, then the pair of equations:
x ≡ a mod m
x ≡ b mod n
has a solution and that any two solutions are congruent modulo m · n. The theorem can be
formulated even more generally using the notions GCD and least common multiple, but that
is a matter for another text.
88 CHAPTER 6. APPENDIX
Bibliography
Ferguson, Niels, and Bruce Schneier. 2003. Practical Cryptography. New York:
John Wiley & Sons.
Mel, H X, and Doris Baker. 2001. Cryptography Decrypted. New York: Addison-
Wesley.
Schneier, Bruce. 1996. Applied Cryptography. New York: John Wiley & Sons.
89