1.3 - Modular Arithmetic

Math 373/578, Spring 2013
Ch 1.3
1
Section 1.3: Modular Arithmetic (p19)
(1.3A) “Clock arithmetic” from grade school: start at 1, highest # is 12, then back to 1.
• Ex: 6 + 10 = 4
2–5=9
• Answers need to make sense in “clock arithmetic” so we are just adding or subtracting 12
until we get to a number that is between 1 and 12.
• Ex: 6 + 10 = 16 – 12 = 4
2 – 5 = –3 + 12 = 9
(1.3B) Def: Let m ≥1 be an integer. We say integers a, b are congruent modulo m if their difference
a − b is divisible by m. We write: a ≡ b(mod m) to indicate that a and b are congruent modulo m.
The number m is called the modulus.
(1.3C) €a ≡ b(mod m) iff there is an integer u such that a = b + um.
€
proof: (⇒) Suppose a ≡ b(mod m) . Then m|(a − b) .
(def of congruence mod m)
€
Since m|(a − b) , then ∃u ∈ Z such that a − b = um .
€
So,€a = b + um .
(def of divisibility)
€
∈ Z such that a =€b + um. Then a − b = um .
(⇐)
€ Suppose ∃u €
Since a − b = um , then m|(a − b) .
€
(algebra)
(def of divisibility)
€
Since m|(a − b) , then a ≡ b(mod m)€
. (def of congruence mod m)
€
€
(1.3D) Ex: The
€ clock examples
€ written as congruences modulo m = 12:
6 +10 =16 ≡ 4(mod12)
2 − 5 = −3 ≡ 9(mod12)
• Note: The numbers a such that a ≡ 0(mod m) are the multiples of m.
€
€
(1.3E) Proposition 1.13: Let m ≥1
€ be an integer.
(a) If a1 ≡ a 2 (mod m) and b1 ≡ b2 (mod m) , then:
a ± b ≡ a ± b (mod m) and a1 ⋅ b1 ≡ a 2 ⋅ b2 (mod m) .
€ 1 1 2 2
€
(b) Let a be an integer. Then a ⋅ b ≡1(mod m) for some integer b iff gcd(a,m) =1. If such an integer b
€
exists, then we say that b is the multiplicative inverse of a mod m, and we write b ≡ a −1 (mod m) .
€
€
proof: (a) Exercise 1.14.
€
€
(b) (⇒) Suppose a has an inverse mod m: a ⋅ b ≡1(mod m) .
Then m|(ab −1) .
(def of congruence mod m)
So, ∃c ∈ Z such that ab −1
€ = cm .
€
€
€
(assumption)
€
(def of divisibility)
Math 373/578, Spring 2013
Ch 1.3
2
Rearrange: ab − cm =1 . The gcd(a,m) divides both ab and cm, so it must also divide 1.
Thus, gcd(a,m) =1.
€ gcd(a,m) = 1. Then we can find u,v ∈ Z satisfying au + mv =1. (Thm 1.11)
(⇐) Suppose
€ So, au −1 = −mv , which means m|(au −1) . (def of divisibility)
Since m|(au −1) , then au ≡1(mod
€ m) .
(def of €
congruence mod m)
Thus, a has an inverse€mod m.
€
€
€
(1.3F) Def: We write Z m = Z/mZ = {0,1,2,...,m −1} and call this set the ring of integers modulo m.
(1.3G) Def: Numbers that have inverses (mod m) are called units. We denote the set of all units by
( Z )* = {a ∈ Z m : gcd(a,m) =1} = {a ∈ Z m : a has an inverse mod m} .
€ m
€
• ( Z m )* is called the group of units modulo m.
€
€ group of units mod 18: (Z )* = {1,5,7,11,13,17} .
(1.3H) Ex: The
18
€
(1.3I)
Def: Euler’s phi function (aka, Euler’s totient function) is the function φ (m) defined by the
rule: φ (m) =# (Z m )* =# {0 ≤ a < m : gcd(a,m) =1} . So, φ (m) is the number of elements in the
€
group of units mod m.
€
(1.3J) Ex: φ (18) = 6
€
€
1.3.1: Modular Arithmetic and Shift Ciphers
€
(1.3K) A shift cipher works by shifting each letter in the alphabet a fixed number of letters. Say we
assign a to 0, b to 1, c to 2, … y to 24, z to 25.
• Encryption: (Ciphertext letter) ≡ (Plaintext letter) + (Secret key) (mod 26)
• Decryption: (Plaintext letter) ≡ (Ciphertext letter) – (Secret key) (mod 26)
(1.3L) Ex: Using the secret key k€= 11, decipher the following ciphertext: XLESCFWPD
€
1.3.2: The Fast Powering Algorithm
(1.3M) In some cryptosystems, we are required to compute large powers of a number g modulo
another number N, so g A (mod N ) , where N may have hundreds of digits. The following example
illustrates a shorter way to do this, using the binary expansion of A to turn the calculation of g A into
a succession of squarings and multiplications.
€
€
Math 373/578, Spring 2013
Ch 1.3
3
(1.3N) Ex: (Ex1.19, p24) Compute 3 218 (mod1000) .
First, write 218 as a sum of powers of 2: 218 = 27 + 26 + 2 4 + 23 + 2
So, 3 218 = 3 2+2
3
€6 +2 7
+2 4 +2
3
4
6
7
i
3
4
5
6
7
€
561
721
841
281
961
= 3 2 ⋅ 3 2 ⋅ 3 2 ⋅ 3 2 ⋅ 3 2 . Each 3 2 is just the previous value squared.
i
0
1
€2
i
€
3 2 (mod1000)
3
9
81
3 218 ≡ 9 ⋅ 561⋅ 721⋅ 281⋅ 961(mod1000) ≡ 489(mod1000) (reduce mod 1000 after each mult)
€
(1.3O) This method is called the fast-powering algorithm or the square-and-multiply algorithm.
(see pp25-26 for the formal statement of the algorithm).
€
Exercises: 1.14, 1.16, 1.17, 1.23, 1.25