Most public key systems rely on number-theoretic results. Before we can discuss the implementation of one, we need to quickly go over the necessary background. We have already used a tiny amount of number theory (in our discussion of computing mod p and of the greatest common divisor). Of course, this must be done briefly, and we will only touch on a small part of a large and ancient field-- the interested reader would do well to consult a text on number theory for more information.
We have already met the greatest common divisor, or gcd, which is the largest integer which divides both of a pair of numbers. Two numbers are said to be relatively prime if their greatest common divisor is 1. As we have already seen, finding two relatively prime numbers has important applications in many cryptosystems.
How can we determine the gcd of two numbers? If the numbers are not too large, just looking at their factors does the trick. For example,
One such algorithm is the Euclidean algorithm, which has been around for thousands of years. It works by computing successive differences-- to compute gcd(a, b), where a > b, we first compute r1 = a - k1b, where k1b is the largest multiple of b that is less than a. Then we repeat this, finding r2 = b - k2r1, r3 = r1 - k3r2, and so on until the remainder is zero. The last nonzero remainder is the gcd. For example, to calculate gcd(138, 126),
a | = | 138 | |
b | = | 126 | |
a | - b | = | 12 |
-10a | +11b | = | 6 |
21a | -23b | = | 0 |
This not only gives gcd(138, 126), but expresses it as a difference of multiples of the two numbers: 6 = 11 . 126 - 10 . 138. We can write this procedure more formally as a theorem.
k1b | + | r1 | = | a | 0 < r1 < b | |
k2r1 | + | r2 | = | b | 0 < r2 < r1 | |
k3r2 | + | r3 | = | r1 | 0 < r3 < r2 | |
k4r3 | + | r4 | = | r2 | 0 < r4 < r3 | |
![]() |
||||||
knrn - 1 | + | rn | = | rn - 2 | 0 < rn < rn - 1 | |
kn + 1rn | = | rn - 1 |
We have already seen that the Euclidean algorithm also gives us the following:
Before proving Thm. 10.1, we will need a lemma.
Proof. Let d = gcd(a, b). Then since d is a divisor of a and a divisor of b, it is also a divisor of b - aq. Since r = b - aq, we have d a divisor of r. So it must divide gcd(a, r).
Now, in order to prove equality, we want to show that also gcd(a, r) is a divisor of d. Certainly gcd(a, r) divides b, since b = r + aq. It also divides a, and so we have gcd(a, r) as a divisor of gcd(a, b).
Thus,
gcd(a, r) = gcd(a, b).
Now we are ready to prove Thm. 10.1:
Proof. Notice that the sequence b > r1 > r2 > r3 >... is a strictly decreasing sequence of positive integers, so it must eventually terminate with some rn > 0. The last equation, kn + 1rn = rn - 1 says that rnis a divisor of rn - 1, so certainly rn = gcd(rn, rn - 1). Applying the lemma to the equation above it gives gcd(rn, rn - 1) = gcd(rn - 1, rn - 2). We can construct the following chain in this way:
Recall that if r is such that ar = 1, then r is called the
multiplicative inverse of a. We have already dealt with such objects
extensively. We now state a theorem which tells us exactly when such
inverses exist. Note that this is really just
Prop. 7.1 slightly reworded.
Proof. First, suppose that a has an inverse modulo n. Then there is a k so that
Now suppose that gcd(a, n) = 1. Then by Cor. 10.2, there are integers r and s with ar + ns = 1. This means ar - 1 is divisible by n, so
Notation.
We haven't yet used this notation, but it is common to denote the
set of integers modulo n as
n. That is,
Notation. We will use
n* to denote the elements of
n which that
have multiplicative inverses. In light of the last theorem, we have
In this section, we state a very old theorem about simultaneous solutions to congruences. This theorem may have been known to the eight-century Buddhist monk I-Hsing, and certainly appears in Ch'in Chiu-shao's Mathematical Treatise in Nine Sections, written in 1247. It is sometimes (rarely) referred to as the ``Formosa Theorem''.
x ![]() |
mod m |
x ![]() |
mod n |
Proof. Since m and n are relatively prime, there are integers k and t so that mk + nt = 1. Then
To check uniqueness, suppose there are two solutions c and d. Since
c
a mod m and
d
a mod m. We have
c - d
0 mod m and
c - d
0 mod n. Since both m and n divide c - d, and m and nare relatively prime, we have that mn divides c - d. Thus
c - d
0 mod mn, that is,
c
d mod mn.
Notation.
In this and future sections, we shall use the notation
to denote
a mod b.
First, let's take a look at a few examples of what happens when we reduce
the sequence
a, a2, a3, a4,... modulo n.
Consider
:
The sequence consists of 4 numbers 3, 9, 7, 1 and then it repeats. Now consider the powers of 11:
This sequence is periodic of period 2. What about 4? We have
This is periodic, but the sequence does not contain 1. Finally, let us consider the powers of 6:
The first two examples give rise to the following definition:
We can readily categorize the elements with finite order. If you look at the examples above, 3 and 11 have finite order mod 20, while 4 and 6 do not. You probably have already guessed that this is because gcd(3, 20) = 1 and gcd(11, 20) = 1, while gcd(4, 20) = 4 and gcd(6, 20) = 2.
Proof. First, suppose a has finite order mod n. Then there is some k so that
Now we suppose gcd(a, n) = 1, and we want to find the inverse of a. Consider the sequence
So, we have seen that any invertible element of
n has finite order. In
particular, if p is a prime number, every element except 0 is
invertible and so has finite order. What are the possible orders? A
theorem of Pierre de Fermat gives a result in that direction.
Among other things, this theorem says that if p is prime, then the order of a mod p always divides p - 1. Note that it doesn't say the order is p - 1, just that it is a divisor of it. Also, it says nothing about order with modulo a non-prime. We won't give the proof of this theorem here. Rather, we will give a proof of a more general result in the next section.
Recall that we denote the set of invertible elements of
n by
n*.
That is,
We can compute a few values of
(n) just by counting.
![]() |
since | ![]() ![]() ![]() |
![]() |
since | ![]() ![]() ![]() |
![]() |
since | ![]() ![]() ![]() |
![]() |
since | ![]() ![]() ![]() |
![]() |
since | ![]() ![]() ![]() |
![]() |
since | ![]() ![]() ![]() |
![]() |
since | ![]() ![]() ![]() |
![]() |
since | ![]() ![]() ![]() |
![]() |
since | ![]() ![]() ![]() |
![]() |
since | ![]() ![]() ![]() |
![]() |
since | ![]() ![]() ![]() |
Of course, maple also knows about the function
in the
numtheory
package, so we could generate more values by asking maple.
But let's try to understand a bit more. We can readily prove some
properties of .
Proof.
(a) This is immediate, since all non-zero elements of
0, 1,..., p-1
are invertible.
(b)
We prove this part just by counting. Since p is prime, the only numbers
in
p which are not relatively prime to pn are multiples of p. These
are
0, p, 2p, 3p,..., p2,(p + 1)p,...,(pn - 1 - 1)p. Note that
pn - 1p = pn, so there are exactly pn - 1 multiples of p less than
pn (including 0). All the others are relatively prime to p-- this
gives the result.
(c)
We need to show that the number of elements in
ab* is the same as the
product of the size of
a* and
b*. We do that by showing that for
each
t
ab*, there is exactly one pair (r, s) with
r
a*and
s
b*.
So, let
r
a* and
s
b*. Then, by the Chinese Remainder Theorem
(Thm. 10.5), there is an integer t < ab with
Now take
t
ab*, and we must find a corresponding r and s. Let
r =
. Now, since
gcd(t, ab) = 1, certainly
gcd(t, a) = 1. Since
r
t mod a, there is an integer k so that t = r + ka, so we have
gcd(r, a) = 1. Thus
r
a*. Similarly, we let
s =
, and
we see that
s
b*.
Since we have paired each
t
ab* with a unique pair
(r, s)
a* x Zb*, they have the same cardinality. The first set has
(ab) elements, and the latter has
(a)
(b).
We now come to Euler's generalization of Fermat's result. This result is the central idea underlying the RSA public key cryptosystem.
Proof. Let a be relatively prime to n, and consider the set
Now, multiply all the elements of
n* together; call the result N.
Then
n*. If we multiply all the elements of
a
n*together, we get
a
(n)N, and since the two sets are the same, we
have