Lecture 4 4
Lecture 4 4
Lecture 4 4
Anna-Simone Frank1
MNF130
Spring 2024
1
Slides created by Tom Michoel and modified by Erik Maartensson and
Anna-Simone Frank
Relatively prime
Definition
The greatest common divisor of two integers m and n not both zero,
written gcd(m, n), is the largest integer d such that d | m and d | n.
Definition
Two integers m and n are relatively prime if they have no common
positive divisor other than 1, that is, if gcd(m, n) = 1.
Theorem
For a positive integer m and integers a, b, n; if an ≡ bn (mod m) and
gcd(m, n) = 1, then a ≡ b (mod m).
3
Lemma
If a, b, c are positive integers such that gcd(a, b) = 1 and a | bc, then
a | c.
Proof.
I If gcd(a, b) = 1 then there exist integers s, t such that
sa + tb = 1
sac + tbc = c
4
Theorem
For a positive integer m and integers a, b, n; if an ≡ bn (mod m) and
gcd(m, n) = 1, then a ≡ b (mod m).
Proof.
I If an ≡ bn (mod m), then by definition m | (an − bn) = (a − b)n.
I By the previous lemma, gcd(m, n) = 1 and m | (a − b)n implies that
m | (a − b), and hence a ≡ b (mod m).
5
Linear congruences
A linear congruence is an equation
ax ≡ b (mod m) (1)
Example
The linear congruence with 2x ≡ 1 (mod 3) has the solution
x ≡ 2 (mod 3).
b b+m b + 2m b + 3m b + 4m b + 5m b + 6m
0 a 2a 3a 4a 5a 6a 7a 8a 9a 10a
6
Inverse modulo m
Definition
An inverse of an integer a modulo m is an integer ā such that
aā ≡ 1 (mod m).
Theorem
If integers a, m are relatively prime, gcd(a, m) = 1, then there exists a
unique inverse of a modulo m.
Proof.
I If gcd(a, m) = 1, then there exist integers s, t such that
sa + tm = 1, and hence sa + tm ≡ 1 (mod m).
I Because tm ≡ 0 (mod m), it follows that sa ≡ 1 (mod m), and s is
an inverse of a modulo m.
I Assume there exists another inverse r of a modulo m. Because
sa ≡ 1 (mod m), there exists q such that sa = qm + 1. Likewise
there exists p such that ra = pm + 1.
I Hence sa − ra = (s − r )a = (q − p)m and m | (s − r )a.
I Because gcd(a, m) = 1 it follows that m | (s − r ), or s ≡ r
(mod m). That is, s is unique modulo m.
7
Inverses modulo prime numbers
Corollary
For a prime p, all integers a, with a 6≡ 0 (mod p) have a modular inverse.
Another way of putting this is that all numbers a ∈ Zp , a 6= 0 have a
multiplicative inverse!
8
Example
Do 7 and 6 have inverses modulo 8?
I Test all possible values for an inverse:
7 mod 8 = 7 6 mod 8 = 6
2 · 7 mod 8 = 6 2 · 6 mod 8 = 4
3 · 7 mod 8 = 5 3 · 6 mod 8 = 2
4 · 7 mod 8 = 4 4 · 6 mod 8 = 0
5 · 7 mod 8 = 3
6 · 7 mod 8 = 2
7 · 7 mod 8 = 1
8 · 7 mod 8 = 0
I Once we reach 0, the numbers repeat.
Intuition
If gcd(a, m) = 1, all values 0 ≤ r < m, including r = 1, are encountered
in this process, but if gcd(a, m) > 1 the process terminates early and
r = 1 is not encountered.
9
How to compute modular inverses?
1 = gcd(a, m) = sa + tm
3. We obtain
ā ≡ s (mod m)
10
Example
We have
8 = 7 + 1 ↔ −1 · 7 = 1 + (−1) · 8.
Thus, -1 and also 7 are inverses of 7 modulo 8. Also, 7−1 = 7 in Z8 .
Example
Let us find the inverse of 101 modulo 4620 (example 2 in Section 4.4.2).
By applying the extended Euclidean algorithm we find that
11
Theorem
If a has an inverse ā modulo m, then the solutions to the linear
congruence ax ≡ b (mod m) are all integers x such that x ≡ āb
(mod m).
Proof.
I Let x be a solution to ax ≡ b (mod m). Then
or x ≡ āb (mod m)
12
The Chinese remainder theorem
13
The Chinese remainder theorem
er Theory and Cryptography
x ≡ a1 (mod m1 ),
x ≡ a2 (mod m2 ),
·
·
·
x ≡ an (mod mn )
Proof: To establish this theorem, we need to show that a solution exists and that it is unique
modulo m. We will show that a solution exists by describing a way to construct this solution;
showing that the solution is unique modulo m is Exercise 30.
To construct a simultaneous solution, first let
Mk = m/mk 14
Constructive proof.
Introduce the notation Mk = m/mk . By construction gcd(Mk , mk ) = 1.
Thus there are integers yk such that
Mk yk ≡ 1 (mod mk ). (2)
Now, consider
x = a1 M1 y1 + · · · + an Mn yn . (3)
For all mk we get
x ≡ a1 M1 y1 + · · · + an Mn yn ≡ ak Mk yk ≡ ak (mod mk ) (4)
Thus x is a solution to the system of linear congruences!
The proof that x is unique modulo m is exercise 4.4.30 in the course
book.
15
The Sun-Tsu example
x ≡2 (mod 3)
x ≡3 (mod 5)
x ≡2 (mod 7)
35y1 ≡ 1 (mod 3)
21y2 ≡ 1 (mod 5)
15y3 ≡ 1 (mod 7)
are y1 ≡ 2 (mod 3), y2 ≡ 1 (mod 5), y3 ≡ 1 (mod 7). Thus, the final
solution is (the solution can easily be verified!)
17