EECS 203: Discrete Mathematics
Winter 2019
Discussion 13 - Notes
1 Definitions
• Modular Addition
• Modular Subtraction
• Modular Multiplication
• Modular Inverse
• Chinese Remainder Theorem
• Fermat’s Little Theorem
• Extended Euclidean Algorithm
• RSA
Solution:
• Modular Addition: Given a ≡ b (mod m) and c ≡ d (mod m), then
a + c ≡ b + d (mod m)
• Modular Subtraction: Given a ≡ b (mod m) and c ≡ d (mod m), then
a − c ≡ b − d (mod m)
• Modular Multiplication: Given a ≡ b (mod m) and c ≡ d (mod m),
then ac ≡ bd (mod m)
1
• Modular Inverse: If a and m are relatively prime integers and m > 1,
then there is an integer a−1 such that a · a−1 ≡ 1 (mod m). This value is
called an inverse of a modulo m. Furthermore, this inverse is unique modulo
m. (That is, every other inverse of a modulo m is congruent to a−1 modulo
m.)
• Chinese Remainder Theorem:
For m1 , m2 , ..., mn that are relatively prime and integers a1 , ..., an , the system
of congruences
x ≡ a1 mod m1
..
.
x ≡ an mod mn
has a unique solution modulo m1 m2 ..mn .
• Fermat’s Little Theorem: For a prime p and integer a not divisible by p,
ap−1 ≡ 1 mod p. For every integer a, we have ap ≡ a (mod p).
• Extended Euclidean Algorithm: The extended Euclidean algorithm is
an extension to the Euclidean algorithm, which computes, in addition to the
greatest common divisor of integers a and b, also the coefficients of Bezout’s
identity, which are integers x and y such that
ax + by = gcd(a, b)
• RSA: What is RSA? Who knows....
1. Exercise 4.1.18 a, c, e, f
Suppose that a and b are integers, a ≡ 11 (mod 19), and b ≡ 3 (mod 19). Find the
integer c with 0 ≤ c ≤ 18 such that
(a) c ≡ 13a (mod 19).
(c) c ≡ a − b (mod 19).
(e) c ≡ 2a2 + 3b2 (mod 19).
(f) c ≡ a3 + 4b3 (mod 19).
Solution:
(a) 13 · 11 = 143 ≡ 10 (mod 19)
2
(c) 11 − 3 ≡ 8 (mod 19)
(e) 2 · 112 + 3 · 32 = 269 ≡ 3 (mod 19)
(f) 113 + 4 · 33 = 1439 ≡ 14 (mod 19)
2. Exercise 4.1.26
Evaluate these quantities.
(a) −17 mod 2
(b) 144 mod 7
(c) −101 mod 13
(d) 199 mod 19
Solution: In each case we just carry out the division to obtain the quotient and
remainder. However, if the dividend is negative, we must make sure to make the
remainder positive, which may involve a quotient 1 less than might be expected.
(a) Since -17 = 2 · (-9) + 1, the remainder is 1. That is, -17 mod 2 = 1. Note
that we do not write -17 = 2 · (-8) -1 with -17 mod 2 = -1 since we’re
wanting a positive remainder.
(b) Since 144 = 7 · 20 + 4, the remainder is 4. That is, 144 mod 7 = 4.
(c) Since -101 = 13 · (-8) + 3, the remainder is 3. That is, -101 mod 13 = 3.
Note that we do not write -101 = 13 · (-7) - 10; we can’t have -101 mod 13
= -10, because a mod b always evaluates to a nonnegative number (though
a mod b is equivalent to everything in its equivalence class which includes
negative numbers).
(d) Since 199 = 19 · 10 + 9, the remainder is 9. That is, 199 mod 19 = 9.
3. Exercise 4.1 Theorem 3
Prove that a ≡ b (mod m) ⇐⇒ a mod m = b mod m
3
Solution:
• Prove a ≡ b (mod m) → a mod m = b mod m
Assume a ≡ b (mod m) true
a = b + km for some integer k (by Theorem 4)
Say a mod m = r
For some integer q, a = mq + r where 0 ≤ r < m (Division Algorithm)
mq + r = b + km
mq − mk = b − r
m(q − k) = b − r
b = m(q − k) + r
b mod m = r = a mod m
b mod m = a mod m
• Prove a mod m = b mod m → a ≡ b (mod m)
Assume a mod m = b mod m
r = a mod m = b mod m
a = mq + r and b = mk + r where 0 ≤ r < m (Division Algorithm)
a − b = (mq + r) − (mk + r) = mq − mk
a − b = m(q − k)
So, m|(a − b)
a ≡ b (mod m)
4. Exercise 4.3.6
How many zeros are there at the end of 100! ?
Solution: A 0 appears at the end of a number for every factor of 10 (= 2 · 5)
the number has. Now 100! certainly has more factors of 2 than it has factors of
5, so the number of factors of 10 it has is the same as the number of factors of 5.
Each of the twenty numbers 5, 10, 15, . . . , 100 contributes a factor of 5 to 100!.
In addition the four numbers 25, 50, 75, and 100 each contribute one more factor
of 5. Therefore there are 20 + 4 = 24 factors of 5 in 100!, so 100! ends in exactly
24 0s.
5. Not in Book 1
Find this value of 5203203 (mod 21) without using a calculator. Show all your work !!!!
Hint: Start by looking at small powers of 5n (mod 21) until you find one that equals
1 or -1.
4
Solution: We can see that 52 ≡ 25 ≡ 4 (mod 21). Then, 53 ≡ 4 · 5 ≡ 20 ≡ −1
(mod 21). Therefore we compute
5203203 ≡ 5 · 5203202 (mod 21)
≡ 5 · (53 )67734 (mod 21)
≡ 5 · (−1)67734 (mod 21)
≡ 5 · 1 (mod 21)
≡ 5 (mod 21)
6. Exercise 4.3.50
Show that if a, b, and m are integers such that m ≥ 2 and a ≡ b(mod m), then
gcd(a, m) = gcd(b, m).
Solution: From a ≡ b(mod m) we know that b = a + sm for some integer s. Now
if d is a common divisor of a and m, then it divides the right-hand side of this
equation, so it also divides b. We can rewrite the equation as a = b − sm, and
then by similar reasoning, we see that every common divisor of b and m is also a
divisor of a. This shows that the set of common divisors of a and m is equal to
the set of common divisors of b and m, so certainly gcd(a, m) = gcd(b, m).
7. Not in Book 2
Solve the linear congruence 62x ≡ 41 (mod 135).
Solution: We first verify that gcd(62, 135) = 1 which will ensure that this linear
congruence has a unique solution modulo 111. Using the Euclidean Algorithm, we
can find gcd(62, 135).
135 = 2(62) + 11
62 = 5(11) + 7
11 = 1(7) + 47 = 1(4) + 34 = 1(3) + 13 = 3(1) + 0
Hence, gcd(62, 135) = 1 and therefore there is a unique solution for x modulo
111. The next step is to write 1 as a linear combination of 4 and 111 by going
5
backwards through our above equations.
1=4−3
1 = 4 − (7 − 1(4)) = 2(4) − 7
1 = 2(11 − 1(7)) − 7 = 2(11) − 3(7)
1 = 2(11) − 3(62 − 5(11)) = 17(11) − 3(62)
1 = 17(135 − 2(62)) − 3(62) = 17(135) − 37(62)
Taking mod 135 on both sides gives
−37(62) mod 135 = 1 mod 135
−37(62) ≡ 1 (mod 135)
We are given that
62x ≡ 41 (mod 135)
−37 · 62x ≡ (−37)41 (mod 135)
x ≡ (−37)41 (mod 135)
x ≡ −1517 (mod 135)
x ≡ 103 (mod 135)
Hence, our solution x ≡ 103 (mod 135).
8. Exercise 4.4.12 c
Solve the following congruence
(c) 200x ≡ 13 (mod 1001)
Solution: c) We first verify that gcd(200, 1001) = 1 which will ensure that this
linear congruence has a unique solution modulo 111. Using the Euclidean Algo-
rithm, we can find gcd(200, 1001).
1001 = 5(200) + 1
200 = 200(1) + 0
Hence, gcd(200, 1001) = 1 and therefore there is a unique solution for x modulo
111. The next step is to write 1 as a linear combination of 200 and 1001 by going
6
backwards through our above equations.
1 = 1001 − 5(200)
Taking mod 1001 on both sides gives
−5(200) mod 1001 = 1 mod 1001
−5(200) ≡ 1 (mod 1001)
200x ≡ 13 (mod 1001)
−5 · 200x ≡ (−5)13 (mod 1001)
x ≡ (−65) (mod 1001)
x ≡ 936 (mod 1001)
Hence, our solution x ≡ 936 (mod 1001).
9. 4.4.33
Use Fermat’s Little Theorem to find 7121 mod 13.
Solution: We know 712 ≡ 1 mod 13, so (712 )10 = 7120 ≡ 1 mod 13. This reduces
our problem to 7 mod 13, which is 7.
10. Exercise 4.6.3
Encrypt the message WATCH YOUR STEP by translating the letters into numbers,
applying the given encryption function, and then translating the numbers back into
letters.
a) f (p) = (p + 14) mod 26
c) f (p) = (7p + 1) mod 26
Solution: a) KOHQV MCIF GHSD
c) ZBYNE PHRM FYZA
7
11. Not in Book 3
Use the Chinese Remainder Theorem construction that was demonstrated in class to
find all solutions to the system of congruences
x≡1 mod 5
x≡2 mod 7
x≡3 mod 9
Note: inverses may be found using any method you want, but should be simplified to
an integer. No further simplification of x is necessary.
Solution: To solve the system of congruences, let m = 5 · 7 · 9 = 315 , M1 = 63,
M2 = 45, M3 = 35.
We see 2 is an inverse of M1 = 63 mod 5, because 63 · 2 ≡ 1 mod 5.
We see 5 is an inverse of M2 = 45 mod 7, because 45 · 6 ≡ 1 mod 7
We see 8 is an inverse of M3 = 35 mod 9, because 35 · 8 ≡ 1 mod 9
The solution to this system are those x such that x ≡ 1 · 63 · 2 + 2 · 45 · 5 + 3 · 35 · 8 ≡
1416 ≡ 156 mod 315
12. Not in Book 4
Suppose that we intercepted a suspicious encrypted text:
FVB OHCL ILLU HKKLK AV AOL DHPASPZA
And we suggest to try deciphering it as a shift-cipher encrypted English message.
What is the original text?
Solution: The most frequent English letter is E, and the most frequent letters
in the encrypted message are A, K, and L. So, it is highly likely that one of A,
K, or L is the cipher letter corresponding to E. If E is indeed encrypted to L,
then the all letters should be shifted by 7, then we shift all ciphertext letters by
subtracting 7 (or add 19) from their numeric values (0-25), modulo 26. We find
that the original message is:
YOU HAVE BEEN ADDED TO THE WAITLIST
8
13. Not in Book 5
Anna and Captain America are trying to send messages to each other without Volde-
mort understanding so they decide to use the RSA encryption method. Anna wants
to send Captain America the following message:
Hans shot first
If Captain America’s private key, d is 17, and the n used in this RSA system is 21,
a) Find the public key Anna needs to encrypt the message
b) Encrypt the message using the above RSA scheme, 1 letter at a time
Solution: a) To find the encryption key we need to first prime factorize n. If
n = 21, then the only possible values for p and q are 3 and 7.
Now that we have p and q, we can find what φ is. φ = (p−1)(q −1) = (2)(6) = 12.
We know that e and d are modular inverses of each other with regards to
φ, 12. This means that 17(e) ≡ 1 mod 12. Using the Extended Euclidean
Algorithm or otherwise, we find that e = 5.
b) First we convert each letter to a number. So, the message
HANS SHOT FIRST becomes: 8 1 14 19 19 8 15 20 6 9 18 19 20.
To encrypt each number separately, we take the number, m, and compute
me mod n. This translates to m5 mod 21.
85 mod 21 ≡ 8
15 mod 21 ≡ 1
145 mod 21 ≡ 14
195 mod 21 ≡ 10
195 mod 21 ≡ 10
85 mod 21 ≡ 8
155 mod 21 ≡ 15
205 mod 21 ≡ 20
65 mod 21 ≡ 6
95 mod 21 ≡ 18
185 mod 21 ≡ 9
195 mod 21 ≡ 10
205 mod 21 ≡ 20
9
The encrypted message now looks like this:
8 1 14 10 10 8 15 20 6 18 9 10 20
To convert the numbers to letters we find their alphabet equivalent which
gives us the following encrypted message:
HANJJHOTFRIJT
10