number theory
number theory
number theory
Cryptography
Chapter 4
© 2019 McGraw-Hill Education. All rights reserved. Authorized only for instructor use in the classroom. No reproduction or further distribution permitted without the prior written consent of McGraw-Hill Education.
Chapter Motivation
Number theory is the part of mathematics devoted to the study of
the integers and their properties.
Key ideas in number theory include divisibility and the primality of
integers.
Representations of integers, including binary and hexadecimal
representations, are part of number theory.
Number theory has long been studied because of the beauty of its
ideas, its accessibility, and its wealth of open questions.
We’ll use many ideas developed in Chapter 1 about proof methods
and proof strategy in our exploration of number theory.
Mathematicians have long considered number theory to be pure
mathematics, but it has important applications to computer
science and cryptography studied in Sections 4.5 and 4.6.
© 2019 McGraw-Hill Education
Chapter Summary
Divisibility and Modular Arithmetic
Integer Representations and Algorithms
Primes and Greatest Common Divisors
Solving Congruences
Applications of Congruences
Cryptography
Division
Division Algorithm
Modular Arithmetic
Integer Representations
• Base b Expansions
• Binary Expansions
• Octal Expansions
• Hexadecimal Expansions
Base Conversion Algorithm
Algorithms for Integer Operations
Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F
Octal 0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17
Binary 0 1 10 11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 1111
If an integer n is a
composite integer, then
it has a prime divisor
less than or equal to √n.
To see this, note that if
n = ab, then a ≤ √n or b
≤√n.
Trial division, a very
inefficient method of
determining if a number
n is prime, is to try
every integer i ≤√n and
see if n is divisible by i.
© 2019 McGraw-Hill Education
Infinitude of Primes
Theorem: There are infinitely many primes. (Euclid) Euclid
Proof: Assume finitely many primes: p1, p2, ….., pn (325 B.C.E. – 265 B.C.E.)
• Let q = p1p2∙∙∙ pn + 1
• Either q is prime or by the fundamental theorem of arithmetic, it is a
product of primes.
• But none of the primes pj divides q since if pj | q, then pj divides
q − p1p2∙∙∙ pn = 1 .
• Hence, there is a prime not on the list p1, p2, ….., pn. It is either q, or if q is
composite, it is a prime factor of q. This contradicts the assumption that p1, p2,
….., pn are all the primes.
• Consequently, there are infinitely many primes.
This proof was given by Euclid in The Elements. The proof is
considered to be one of the most beautiful in all mathematics. It
is the first proof in The Book, inspired by the famous
mathematician Paul Erdős’ imagined collection of perfect proofs Paul Erdős
maintained by God. (1913-1996)
© 2019 McGraw-Hill Education
Representing Functions
Definition: Prime numbers of the form 2p − 1 ,
where p is prime, are called Mersenne primes. Marin Mersenne
• 22 − 1 = 3, 23 − 1 = 7, 25 − 1 = 37 , and 27 − 1 = 127 (1588-1648)
are Mersenne primes.
• 211 − 1 = 2047 is not a Mersenne prime since 2047 = 23∙89.
• There is an efficient test for determining if 2p − 1 is prime.
• The largest known prime numbers are Mersenne primes.
• As of mid 2011, 47 Mersenne primes were known, the largest is
243,112,609 − 1, which has nearly 13 million decimal digits.
• The Great Internet Mersenne Prime Search (GIMPS) is a distributed
computing project to search for new Mersenne Primes.
http://www.mersenne.org/
© 2019 McGraw-Hill Education
Distribution of Primes*
Mathematicians have been interested in the distribution
of prime numbers among the positive integers. In the
nineteenth century, the prime number theorem was
proved which gives an asymptotic estimate for the
number of primes not exceeding x.
Prime Number Theorem: The ratio of the number of
primes not exceeding x and x/ln x approaches 1 as x
grows without bound. (ln x is the natural logarithm of x)
• The theorem tells us that the number of primes not exceeding
x, can be approximated by x/ln x.
• The odds that a randomly selected positive integer less than n
is prime are approximately (n/ln n)/n = 1/ln n.
© 2019 McGraw-Hill Education
Primes and Arithmetic Progressions
(optional)*
Euclid’s proof that there are infinitely many primes can be easily adapted
to show that there are infinitely many primes in the following 4k + 3, k =
1,2,… (See Exercise 55)
In the 19th century G. Lejuenne Dirichlet showed that every arithmetic
progression ka + b, k = 1,2, …, where a and b have no common factor
greater than 1 contains infinitely many primes. (The proof is beyond the
scope of the text.)
Are there long arithmetic progressions made up entirely of primes?
• 5,11, 17, 23, 29 is an arithmetic progression of five primes.
• 199, 409, 619, 829, 1039,1249,1459,1669,1879,2089 is an
arithmetic progression of ten primes.
In the 1930s, Paul Erdős conjectured that for every positive
integer n greater than 1, there is an arithmetic progression
of length n made up entirely of primes. This was proven in Terence Tao
2006, by Ben Green and Terrence Tau. (Born 1975)
© 2019 McGraw-Hill Education
Generating Primes
The problem of generating large primes is of both theoretical and
practical interest.
We will see (in Section 4.6) that finding large primes with hundreds of
digits is important in cryptography.
So far, no useful closed formula that always produces primes has been
found. There is no simple function f(n) such that f(n) is prime for all
positive integers n.
But f(n) = n2 − n + 41 is prime for all integers 1,2,…, 40. Because of this,
we might conjecture that f(n) is prime for all positive integers n. But f(41)
= 412 is not prime.
More generally, there is no polynomial with integer coefficients such that
f(n) is prime for all positive integers n. (See supplementary Exercise 23.)
Fortunately, we can generate large integers which are almost certainly
primes. See Chapter 7.
© 2019 McGraw-Hill Education
Conjectures about Primes
Even though primes have been studied extensively for centuries, many
conjectures about them are unresolved, including:
Goldbach’s Conjecture: Every even integer n, n > 2, is the sum of two
primes. It has been verified by computer for all positive even integers up
to 1.6 ∙1018. The conjecture is believed to be true by most
mathematicians.
There are infinitely many primes of the form n2 + 1, where n is a positive
integer. But it has been shown that there are infinitely many primes of
the form n2 + 1, where n is a positive integer or the product of at most
two primes.
The Twin Prime Conjecture: The twin prime conjecture is that there are
infinitely many pairs of twin primes. Twin primes are pairs of primes that
differ by 2. Examples are 3 and 5, 5 and 7, 11 and 13, etc. The current
world’s record for twin primes (as of mid 2011) consists of numbers
65,516,468,355∙2333,333 ±1, which have 100,355 decimal digits.
© 2019 McGraw-Hill Education
Greatest Common Divisor 1
gcd ( a, b ) = p1
min ( a1 ,b1 ) min ( a2 ,b2 ) min ( an ,bn )
p2 pn ,
This formula is valid since the integer on the right (of the equals sign)
divides both a and b. No larger integer can divide both a and b.
Example: 120 = 23 ∙3 ∙5 500 = 22 ∙53
gcd(120,500) = 2min(3,2) ∙3min(1,0) ∙5min(1,3) = 22 ∙30 ∙51 = 20
Finding the gcd of two positive integers using their prime factorizations
is not efficient because there is no efficient algorithm for finding the
prime factorization of a positive integer.
© 2019 McGraw-Hill Education
Least Common Multiple
Definition: The least common multiple of the positive integers a and b is
the smallest positive integer that is divisible by both a and b. It is
denoted by lcm(a,b).
The least common multiple can also be computed from the prime
factorizations.
lcm ( a, b ) = p1
max ( a1 ,b1 ) max ( a2 ,b2 ) max ( an ,bn )
p2 pn ,
This number is divided by both a and b and no smaller number is divided
by a and b.
Example: lcm(233572, 2433) = 2max(3,4) 3max(5,3) 7max(2,0) = 24 35 72
The greatest common divisor and the least common multiple of two
integers are related by:
Theorem 5: Let a and b be positive integers. Then
ab = gcd(a,b) ∙lcm(a,b)
(proof is Exercise 31)
© 2019 McGraw-Hill Education
Euclidean Algorithm 1
Linear Congruences
The Chinese Remainder Theorem
Computer Arithmetic with Large Integers (not
currently included in slides, see text)
Fermat’s Little Theorem
Pseudoprimes
Primitive Roots and Discrete Logarithms
To construct a solution first let Mk=m/mk for k = 1,2,…,n and m = m1m2 ∙ ∙ ∙ mn.
Since gcd(mk ,Mk ) = 1, by Theorem 1, there is an integer yk , an inverse of Mk
modulo mk, such that
Mk yk ≡ 1 ( mod mk ).
Form the sum
x = a1 M 1 y 1 + a 2 M 2 y 2 + ∙ ∙ ∙ + a n M n y n .
Note that because Mj ≡ 0 ( mod mk) whenever j ≠k , all terms except the kth
term in this sum are congruent to 0 modulo mk .
Because Mk yk ≡ 1 ( mod mk ), we see that x ≡ ak Mk yk ≡ ak( mod mk), for k =
1,2,…,n.
Hence, x is a simultaneous solution to the n congruences.
x ≡ a1 ( mod m1)
x ≡ a2 ( mod m2)
∙
∙
∙
x ≡ an ( mod mn)
© 2019 McGraw-Hill Education
The Chinese Remainder Theorem * 4
(optional)* Carmichael
(1879-1967)
There are composite integers n that pass all tests with bases
b such that gcd(b,n) = 1.
Definition: A composite integer n that satisfies the congruence bn-1 ≡ 1 (mod n)
for all positive integers b with gcd(b,n) = 1 is called a Carmichael number.
Example: The integer 561 is a Carmichael number. To see this:
• 561 is composite, since 561 = 3 ∙ 11 ∙ 13.
• If gcd(b, 561) = 1, then gcd(b, 3) = 1, then gcd(b, 11) = gcd(b, 17) =1.
• Using Fermat’s Little Theorem: b2 ≡ 1 (mod 3), b10 ≡ 1 (mod 11), b16 ≡ 1 (mod 17).
• Then 560
b = (b
2 280
) 1( mod 3) ,
b560 = (b )
10 56
1( mod 11) ,
b560 = (b )
16 35
1( mod 17 ) .
• It follows (see Exercise 29) that b560 ≡ 1 (mod 561) for all positive integers b with
gcd(b,561) = 1. Hence, 561 is a Carmichael number.
Even though there are infinitely many Carmichael numbers, there are other tests
(described in the exercises) that form the basis for efficient probabilistic
primality testing. (see Chapter 7)
© 2019 McGraw-Hill Education
Primitive Roots*
Definition: A primitive root modulo a prime p is an integer r in Zp
such that every nonzero element of Zp is a power of r.
Example: Since every element of Z11 is a power of 2, 2 is a
primitive root of 11.
Powers of 2 modulo 11: 21 = 2, 22 = 4, 23 = 8, 24 = 5, 25 = 10, 26 = 9,
27 = 7, 28 = 3, 210 = 2.
Example: Since not all elements of Z11 are powers of 3, 3 is not a
primitive root of 11.
Powers of 3 modulo 11: 31 = 3, 32 = 9, 33 = 5, 34 = 4, 35 = 1, and the
pattern repeats for higher powers.
Important Fact: There is a primitive root modulo p for every prime
number p.
© 2019 McGraw-Hill Education
Discrete Logarithms*
Suppose p is prime and r is a primitive root modulo p. If a is an integer between
1 and p −1, that is an element of Zp, there is a unique exponent e such that re =
a in Zp, that is, re mod p = a.
Definition: Suppose that p is prime, r is a primitive root modulo p, and a is an
integer between 1 and p −1, inclusive. If re mod p = a and 1 ≤ e ≤ p − 1, we say
that e is the discrete logarithm of a modulo p to the base r and we write logr a =
e (where the prime p is understood).
Example 1: We write log2 3 = 8 since the discrete logarithm of 3 modulo 11 to
the base 2 is 8 as 28 = 3 modulo 11.
Example 2: We write log2 5 = 4 since the discrete logarithm of 5 modulo 11 to
the base 2 is 4 as 24 = 5 modulo 11.
There is no known polynomial time algorithm for computing the discrete
logarithm of a modulo p to the base r (when given the prime p, a root r modulo
p, and a positive integer a ∊Zp). The problem plays a role in cryptography as will
be discussed in Section 4.6.
© 2019 McGraw-Hill Education
Applications of
Congruences
Section 4.5
Hashing Functions
Pseudorandom Numbers
Check Digits
The validity of an ISBN-10 number can be evaluated with the equivalent ix i 0 ( mod 11) .
i =1
a. Suppose that the first 9 digits of the ISBN-10 are 007288008. What is the check digit?
b. Is 084930149X a valid ISBN10?
X is used
Solution:
for the
a. X10 ≡ 1∙0 + 2∙0 + 3∙7 + 4∙2 + 5∙8 + 6∙8 + 7∙ 0 + 8∙0 + 9∙8 (mod 11). digit 10.
X10 ≡ 0 + 0 + 21 + 8 + 40 + 48 + 0 + 0 + 72 (mod 11).
X10 ≡ 189 ≡ 2 (mod 11). Hence, X10 = 2.
b. 1∙0 + 2∙8 + 3∙4 + 4∙9 + 5∙3 + 6∙0 + 7∙ 1 + 8∙4 + 9∙9 + 10∙10 =
0 + 16 + 12 + 36 + 15 + 0 + 7 + 32 + 81 + 100 = 299 ≡ 2 ≢ 0 (mod 11)
Hence, 084930149X is not a valid ISBN-10.
A single error is an error in one digit of an identification number and a transposition error is the
accidental interchanging of two digits. Both of these kinds of errors can be detected by the check
digit for ISBN-10. (see text for more details)
© 2019 McGraw-Hill Education
Cryptography
Section 4.6
Classical Cryptography
Cryptosystems
Public Key Cryptography
RSA Cryptosystem
Cryptographic Protocols
Primitive Roots and Discrete Logarithms
Julius Caesar created secret messages by shifting each letter three letters forward in the
alphabet (sending the last three letters to the first three letters.) For example, the letter
B is replaced by E and the letter X is replaced by A. This process of making a message
secret is an example of encryption.
Here is how the encryption process works:
• Replace each letter by an integer from Z26, that is an integer from 0 to 25 representing one less
than its position in the alphabet.
• The encryption function is f(p) = (p + 3) mod 26. It replaces each integer p in the set
{0,1,2,…,25} by f(p) in the set {0,1,2,…,25} .
• Replace each integer p by the letter with the position p + 1 in the alphabet.
Example: Encrypt the message “MEET YOU IN THE PARK” using the Caesar cipher.
Solution: 12 4 4 19 24 14 20 8 13 19 7 4 15 0 17 10.
Now replace each of these numbers p by f(p) = (p + 3) mod 26.
15 7 7 22 1 17 23 11 16 22 10 7 18 3 20 13.
Translating the numbers back to letters produces the encrypted message
“PHHW BRX LQ WKH SDUN.”
© 2019 McGraw-Hill Education
Caesar Cipher 2
To recover the original message, use f−1(p) = (p−3) mod 26. So,
each letter in the coded message is shifted back three letters in
the alphabet, with the first three letters sent to the last three
letters. This process of recovering the original message from the
encrypted message is called decryption.
The Caesar cipher is one of a family of ciphers called shift
ciphers. Letters can be shifted by an integer k, with 3 being just
one possibility. The encryption function is
f(p) = (p + k) mod 26
and the decryption function is
f−1(p) = (p−k) mod 26
The integer k is called a key.
© 2019 McGraw-Hill Education
Shift Cipher 1
A public key cryptosystem, now known as the RSA system was introduced in
1976 by three researchers at MIT.
It is now known that the method was discovered earlier by Clifford Cocks,
working secretly for the UK government.
With the decryption key d, we can decrypt each block with the computation M = Cd
mod p∙q. (see text for full derivation)
RSA works as a public key system since the only known method of finding d is based on
a factorization of n into primes. There is currently no known feasible method for
factoring large numbers into primes.
Example: The message 0981 0461 is received. What is the decrypted message if it was
encrypted using the RSA cipher from the previous example.
Solution: The message was encrypted with n = 43∙ 59 and exponent 13. An inverse of
13 modulo 42∙ 58 = 2436 (exercise 2 in Section 4.4) is d = 937.
• Since 0981937 mod 2537 = 0704 and 0461937 mod 2537 = 1115, the decrypted message is
0704 1115. Translating back to English letters, the message is HELP.
Example: Suppose Alice’s RSA cryptosystem is the same as in the earlier example with
key(2537,13), 2537 = 43∙ 59, p = 43 and q = 59 are primes and
gcd(e,(p−1)(q −1)) = gcd(13, 42∙ 58) = 1.
Her decryption key is d = 937.
She wants to send the message “MEET AT NOON” to her friends so that they can be
certain that the message is from her.
Solution: Alice translates the message into blocks of digits 1204 0419 0019 1314 1413.
1. She then applies her decryption transformation D(2537,13) (x)= x937 mod 2537 to each
block.
2. She finds (using her laptop, programming skills, and knowledge of discrete
mathematics) that 1204937 mod 2537 = 817, 419937 mod 2537 = 555 , 19937 mod
2537 = 1310, 1314937 mod 2537 = 2173, and 1413937 mod 2537 = 1026.
3. She sends 0817 0555 1310 2173 1026.
When one of her friends receive the message, they apply Alice’s encryption
transformation E(2537,13) to each block. They then obtain the original message which they
translate back to English letters.