Chap 4
Chap 4
Chapter Summary
Divisibility and Modular Arithmetic
Integer Representations and Algorithms
Primes and Greatest Common Divisors
Solving Congruences
Applications of Congruences
Cryptography
Section 4.1
Section Summary
Division
Division Algorithm
Modular Arithmetic
Division
0, then
Definition: If a and b are integers with a ≠
a divides b if there exists an
integer c such that b = ac.
When a divides b we say that a is a factor or
divisor of b and that b is a multiple of a.
The notation a | b denotes that a divides b.
If a | b, then b/a is an integer.
If a does not divide b, we write a ∤ b.
modulus.
Two integers are congruent mod m if and only if they have
the same remainder when divided by m.
a ≢ b (mod m)
If a is not congruent to b modulo m, we write
Solution:
17 ≡ 5 (mod 6) because 6 divides 17 − 5 = 12.
24 ≢ 14 (mod 6) since 24 − 14 = 10 is not divisible by 6.
More on Congruences
Theorem 4: Let m be a positive integer. The
integers a and b are congruent modulo m if and
only if there is an integer k such that a = b + km.
Proof:
If a ≡ b (mod m), then (by the definition of
congruence) m | a – b. Hence, there is an integer k
such that a – b = km and equivalently a = b + km.
(mod m).
The Relationship between
(mod m) and mod m Notations
The use of “mod” in a ≡ b (mod m) and a
mod m = b are different.
a ≡ b (mod m) is a relation on the set of
integers.
In a mod m = b, the notation mod denotes a
function.
The relationship between these notations is
5.1.)
(We will prove this using mathematical induction in Section
The representation of n given in Theorem 1 is called the
=175627
Example: What is the decimal expansion of the
quotient is 0.
remainder. The process terminates when the
continued →
Algorithm: Constructing Base b Expansions
with b > 1)
procedure base b expansion(n, b: positive integers
k := 0
q := n
while (q ≠ 0)
ak := q mod b
k := k + 1
q := q div b
Solution:
(37274)8.
c := 0
respectively}
for j := 0 to n − 1
d := ⌊(aj + bj + c)/2⌋
sj := aj + bj + c − 2d
c := d
sn := c
return(s0,s1,…, sn){the binary expansion of the sum is (sn,sn-1,…,s0)2}
The number of additions of bits used by the
algorithm to add two n-bit integers is O(n).
Binary Multiplication of Integers
Algorithm for computing the product of two n
bit integers.
procedure multiply(a, b: positive integers)
{the binary expansions of a and b are (an-1,an-2,…,a0)2 and (bn-1,bn-2,…,b0)2,
for j := 0 to n − 1
respectively}
Note that:
{2,3,5,7,11,15,1719,23,29,31,37,41,43,47,53,
59,61,67,71,73,79,83,89, 97}
continued →
The Sieve of Erastosthenes
If an integer n is a
composite integer, then it
ab, then a ≤ √n or b
To see this, note that if n =
≤√n.
is divisible by i.
Theorem: If n is a composite integer, then n
has a prime divisor less than or equal to √n.
Proof:
If n is composite, then it has a positive integer
factor a with 1 < a < n by definition. This means
that n = ab, where b is an integer greater than 1.
Assume a > √n and b > √n. Then ab > √ n √n = n,
which is a contradiction. So either a ≤ √n or b ≤
√n.
Thus, n has a divisor less than √n.
By the fundamental theorem of arithmetic, this
divisor is either prime, or is a product of primes.
In either case, n has a prime divisor less than √n.
Infinitude of Primes (325 B.C.E. – 265 B.C.E.)
Euclid
q − p1p2∙∙∙ pn = 1 .
But none of the primes p divides q since if p | q, then p
j j j
divides
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.
This proof was given by Euclid The Elements. The proof is considered to be
one
Consequently, there
of the most beautiful are infinitely
in all mathematics. many
It is the primes.
first proof in The Book,
inspired by the famous mathematician Paul Erdős’ imagined collection of perfect
Paul Erdős
proofs maintained by God.
(1913-1996)
Mersene Primes Marin Mersenne
24 and 36?
Example:What is the greatest common divisor of
17 and 22?
Example:What is the greatest common divisor of
Solution: gcd(17,22) = 1
Greatest Common Divisor
if their greatest common divisor is 1.
Definition: The integers a and b are relatively prime
Example: 17 and 22
This formula is valid since the integer on the right (of the
equals sign) divides both a and b. No larger integer can divide
287):
remainder when a is divided by b.
287 by 91
Example: Find gcd(91,Divide
287 = 91 ∙ 3 + 14 Divide 91 by 14
91 = 14 ∙ 6 + 7
Divide 14 by 7
14 = 7 ∙ 2 + 0
Stopping
condition
while y ≠ 0
y := b
r := x mod y
x := y
y := r
return x {gcd(a,b) is x}
gcd(252,198) = 18
Solution: First use the Euclidean algorithm to show
i. 252 = 1∙198 + 54
ii. 198 = 3 ∙54 + 36
iii. 54 = 1 ∙36 + 18
iv. 36 = 2 ∙18
Now working backwards, from iii and i above
18 = 54 − 1 ∙36
36 = 198 − 3 ∙54
1(mod 7)
1.
Two integers a and b are relatively prime when gcd(a,b) =
1.
Solution: First use the Euclidian algorithm to
show that gcd(101,42620) =Backwards:
42620 = 45∙101 + 1 = 3 − 1∙2
Working
modulo 42620
The Chinese Remainder Theorem
In the first century, the Chinese mathematician Sun-
Tsu asked:
x ≡ 2 ( mod 3),
system of congruences:
x ≡ 3 ( mod 5),
x ≡ 2 ( mod 7)?
We’ll see how the theorem that is known as the
Chinese Remainder Theorem can be used to solve
Sun-Tsu’s problem.
The Chinese Remainder Theorem
Theorem 2: (The Chinese Remainder Theorem) Let m1,m2,…,mn
be pairwise relatively prime positive integers greater than one
and a1,a2,…,an arbitrary integers. Then the system
x ≡ a1 ( mod m1)
x ≡ a2 ( mod m2)
∙
∙
∙
x ≡ an ( mod mn)
has a unique solution modulo m = m1m2 ∙ ∙ ∙ mn.
(That is, there is a solution x with 0 ≤ x <m and all other solutions
are congruent modulo m to this solution.)
m is Exercise 30.
construct the solution. Showing that the solution is unique modulo
continued →
The Chinese Remainder Theorem
To construct a solution first let Mk=m/mk for k = 1,2,…,n and
m = m1m2 ∙ ∙ ∙ mn .
Mk yk ≡ 1 ( mod mk ).
, an inverse of Mk modulo mk, such that
x = a1 M1 y1 + a2 M2 y2 + ∙ ∙ ∙ + an Mn yn .
Form the sum
x ≡ a1 ( mod m1)
Hence, x is a simultaneous solution to the n congruences.
x ≡ a2 ( mod m2)
∙
∙
∙
The Chinese Remainder Theorem
Example: Consider the 3 congruences from Sun-Tsu’s
We see that
2 is an inverse of M1 = 35 modulo 3 since 35 ∙ 2 ≡ 2 ∙ 2 ≡ 1 (mod 3)
1 is an inverse of M2 = 21 modulo 5 since 21 ≡ 1 (mod 5)
Hence,
x = a 1 M 1 y1 + a 2 M 2 y 2 + a 3 M 3 y 3
= 2 ∙ 35 ∙ 2 + 3 ∙ 21 ∙ 1 + 2 ∙ 15 ∙ 1 = 233 ≡ 23 (mod 105)
that gcd(b,n) = 1.
There are composite integers n that pass all tests with bases b such
alphabet.
Example: Encrypt the message “MEET YOU IN THE PARK” using the
Solution: 12 4 4 19 24 14 20 8 13 19 7 4 15 0 17 10.
Caesar cipher.
f(p) = (p + k) mod 26
function is
69
RSA Key Setup
each user generates a public/private key pair by:
selecting two large primes at random - p,q
computing their system modulus n=p.q
-define ø(n)=(p-1)(q-1)
selecting at random the encryption key e
where 1<e<ø(n), gcd(e,ø(n))=1
solve following equation to find decryption key d
e.d=1 mod ø(n) and 0≤d≤n
publish their public encryption key: PU={e,n}
keep secret private decryption key: PR={d,n}
70
RSA Use
to encrypt a message M the sender:
obtains public key of recipient PU={e,n}
computes: C = Me mod n, where 0≤M<n
to decrypt the ciphertext C the owner:
uses their private key PR={d,n}
computes: M = Cd mod n
note that the message M must be smaller
than the modulus n (block if needed)
71
RSA Example - Key Setup
1. Select primes: p=17 & q=11
2. Compute n = pq =17 x 11=187
3. Compute ø(n)=(p–1)(q-1)=16 x
10=160
4. Select e: gcd(e,160)=1; choose e=7
5. Determine d: de=1 mod 160 and d < 160
Value is d=23 since 23x7=161= 10x160+1
6. Publish public key PU={7,187}
7. Keep secret private key PR={23,187}
72
RSA Example - En/Decryption
sample RSA encryption/decryption is:
given message M = 88
encryption:
C = 887 mod 187 = 11
decryption:
M = 1123 mod 187 = 88
73