Senior CryptographyAndNumberTheory Feb12-Hndt
Senior CryptographyAndNumberTheory Feb12-Hndt
Theory Week 2
Dale Brydon
Feb. 9, 2014
1
r. Now suppose e is any common divisor of b and r. In an exercise below you will
prove that e divides qb + r = a. But then, e | a and e | b and so e ≤ d by definition
of GCDs. Hence, d = gcd(b, r).
Notice that if a (mod b) = r, then we can write a = qb + r for some integer q and
hence gcd(a, b) = gcd(b, r). So provided b is positive, we can use this simplification
to help us find the GCD. It’s easy to show gcd(a, b) = gcd(a, −b), and so, in fact, we
can always use this simplification. We’ll now describe an algorithm for computing
GCDs assuming b ≥ 0.
The Euclidean Algorithm:
2. If ri = 0 then gcd(a, b) = bi .
4. Go to step 2.
135 = (1)99 + 36
99 = (2)36 + 27
36 = (1)27 + 9
27 = (3)9 + 0.
Since we see a remainder of 0 in the last equation, the remainder in the previous
equation is the GCD. Thus, gcd(135, 99) = 9.
This algorithm turns out to be very efficient. Without going into too many details
about what exactly I mean by “efficient”, I will say that it can be used to compute
the GCDs of very large numbers very quickly using a computer. For example, I was
able to compute the GCD of two 500-digit numbers in less than a second using a
completely unoptimized version of the algorithm.
Now that we have a concept of GCDs and how to compute them. We will turn
our attention back to inverses mod n. In particular, we still want to know when a
number has an inverse mod n. We’ll prove that to be invertible, a number must be
congruent to 1 mod n.
Proof. It’s not too hard to see that if ak ≡ 1 (mod n), then ak = 1 + qn for some
integer q. Hence, ak −qn = 1. Now suppose d = gcd(a, n). Once again, by an exercise
later, you will see that this means d divides the left-hand side of this equation. Thus,
d divides 1 and hence d = 1. So we have just seen that if a has an inverse mod n,
then gcd(a, n) = 1.
2
It turns out, that it’s also true that if gcd(a, n) = 1, then a has an inverse mod
n. We will look at why this is true and how to find the inverse next.
By subbing each equation generated by the Euclidean algorithm into the next
one we can find the inverse of a (mod b), when it exists. It’s easiest to see how the
extended Euclidean algorithm works by seeing an example. Earlier we saw
135 = (1)99 + 36
99 = (2)36 + 27
36 = (1)27 + 9
27 = (3)9 + 0.
We know that the GCD is 9 and from the second last equation we can see that
9 = 36 − (1)27. We can substitute into this the (rewritten) equation above to give
that
9 = 36 − (1)(99 − (2)36) = 3(36) − 99.
Further substitution gives that
In this way we can find integers x and y so that gcd(a,b) = ax + by. When gcd(a, b) =
1, x ≡ a−1 (mod b). So we have seen when a number has an inverse mod n and how
to find that inverse.
2 Primes
A prime number is an integer greater than 1 whose only positive divisors are one
and itself. Numbers that are not prime are called composite. Primes will play an
important role in the RSA cryptosystem we will talk about next time. The most
important property of primes for us has to do with factoring.
The Unique Factorization Theorem: Every positive integer can be expressed
as a unique product of primes up to ordering. That is every integer n can be written
as
pe11 pe22 · · · pekk
for some integer k, where the pi ’s are primes and there is only one choice for the pi ’s
and the exponents ei . As a brief example 100 = 22 · 52 and this is the only way to
factor 100 (every factorization will contain two 2s and two 5s). The proof of this
theorem involves a few too many details to talk about in this series and so is skipped.
So we know that every integer n can be factored, but how can it be done? Is
there anyway to do it quickly? One method you might use is trial division where you
test to see if every number less than n divides it. This can be improved significantly
√
by noticing that you only need to test numbers that are at most as big as n. This
3
√ √
works since if n = ab, then either a ≤ n or b ≤ n. But even that improvement
is not enough to create a fast algorithm. Trying this method to factor one of the
500-digit numbers whose GCD could be computed in less than a second would lead
to a computation that would take longer than the lifetime of our sun to complete.
The hardest numbers to factor are those that are the product of two primes p and
q, where p ≈ q. That is the two primes are relatively close together (have the same
number of digits or bits). The largest such well-generated number to be successfully
factored had 232-digits, took 2 years of work to complete, and used over 2000 years of
computation time. In summary, there is no known method to efficiently factor very
large numbers using a classical computer. (The problem can efficiently be solved with
a quantum computer, should anyone ever build a big enough one.) The difficulty of
factoring will play an important role in the security of RSA.
Since we will need to use very large primes in our upcoming cryptosystem, it
would be good to make sure that such numbers exist. That is, we want to guarantee
that even very large numbers can be prime. We will prove that there are, indeed,
infinitely many primes.
Proof. Suppose, by way of contradiction, that there are finitely many primes
p1 , p 2 , · · · , p k ,
n = p1 p2 · · · pk + 1.
and
a(p−1)(q−1) ≡ (aq−1 )p−1 ≡ 1p−1 ≡ 1 mod q.
Let n = a(p−1)(q−1) . We have just shown that n = 1 + k1 p and n = 1 + k2q for some
integers k1 and k2 . Hence, k1 p = k2 q. We know p | k1 p and so p | k2 q. In one of the
4
exercises below you will show that if r is prime and r | ab then r | a or r | b. Using
this fact, and the fact that p - q, we can see that p | k2 . Hence, pq | k2 q and so the
equation n = 1 + k2 q gives that n ≡ 1 (mod pq).
3 Problem Set
1. Compute gcd(539,273).
2. Prove that if a | b and a | c then a | (k1 b + k2 c) for any integers k1 and k2 . (This
is the exercise that fills in the missing gaps in the first two proofs above.)
4. Using the Extended Euclidean Algorithm, find the inverse of 42 mod 79.
5. Factoring a 300-digit number using trial division would take around 10150 di-
visions. Assuming a computer is capable of doing 1 million (106 ) divisions per
second, how many seconds would it take the computer to complete factoring
by trial division? How about if you used 1 billion (109 ) such computers to do
the computation? To give a little context, the universe is believed to be on the
order of 1017 seconds old.
6. Suppose p is prime. Show that if a 6≡ 0 (mod p), then a has an inverse mod p.
and then use this congruence together with 6. to prove the desired result.)