Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1 Modular Arithmetic
1.1 Introduction
Modulus: Two numbers a and b are equivalent modulo n. If n|(a b), intuitively, if a
and b have the same remainder when divided by n.
In this case, we write a ⌘ b mod n.
Modular Arithmetic: All operations that work on integers also work the same way
when done under a fixed modulus n. Here are a few examples:
Inverse: a and b are said to be multiplicative inverses mod n if a⇤b ⌘ 1 mod n. In this
case, we write that b ⌘ a 1 . When n is prime, every number a has a unique inverse.
1.2 Questions
Solution: What this question is really asking is to find 1000 (mod 24). Using our
formula for modulus, we have 1000 (mod 24) = 1000 24⇤b 1000 24
c ⌘ 1000 984 = 16.
Thus, it will be 4 pm after 1000 hours.
Solution: What this question is really asking is to find 1000 (mod 7). Using our
formula for modulus, we have 1000 (mod 7) = 1000 7 ⇤ b 1000 7
c ⌘ 1000 994 = 6.
Thus, it will be Sunday after 1000 days.
Solution: Since we’re only looking for the tens and units digits, we can just find
the 71900 mod 100, the remainder when 71900 is divided by 100. We write down
the first few powers of 7 mod 100 and see that 74 = 2401 = 1( mod 100). So, 71900
mod 100 = 74⇥475 = 1475 = 1 mod 100. So, our units digit is 1 and tens digit is 0.
Solution: For this solution, instead of trying to factor the exponent nicely, we’ll
use the approach of writing the exponent as a binary number and multiplying
together the corresponding exponents. Since we have 71 = 64 + 4 + 2 + 1, we know
by the properties of exponents that 371 = (364 )(34 )(32 )(31 )
Putting each of these (mod 25), we get the following.
31 = 3 (mod 25)
3 2 = 32 = 9 (mod 25)
4 2
3 = 9 = 81 ⌘ 6 (mod 25)
38 = 62 = 36 ⌘ 11 (mod 25)
316 = 112 = 121 ⌘ 21 (mod 25)
32 2
3 = 21 = 441 ⌘ 16 (mod 25)
64 2
3 = 16 = 256 ⌘ 6 (mod 25)
Thus we have:
371 (mod 25) = (364 )(34 )(32 )(31 ) (mod 25)
371 (mod 25) = 6 ⇤ 6 ⇤ 9 ⇤ 3 (mod 25)
71
3 (mod 25) = 972 ⌘ 22
Solution: 2 1
mod 7 = 4 so x = 3(2 1 ) = 12 = 5 mod 7.
15
7. (Bonus) What is 712 (mod 29)
Solution: Challenging problem. Note that 72 ⌘ 20 mod 29, 74 ⌘ 23 mod 29, and
78 ⌘ 7 mod 29. Since 29 is prime, we can divide both sides by 7 to get that 77 ⌘ 1
mod 29. Thus, we can take 1215 mod 7 and use that as the exponent. 1215 ⌘ 6
15
mod 7, so 712 ⌘ 76 ⌘ 23 ⇤ 20 ⌘ 25 mod 29.
2 Euclid’s Algorithm
2.1 Questions
3 Bijections
3.1 Introduction
2. Describe a function that is injective but not surjective and the set over which this
applies. How about a function that is surjective but not injective?
Solution: Yes: the mapping works. Since 7 is coprime to 12, there exists a
multiplicative inverse to 7 in Z12 (7 ⇥ 7 = 49 mod 12 = 1, so f 1 (x) = 7x),
which only occurs if the function is a bijection.
b. f (x) = 3x
c. f (x) = x 6
Solution: Yes: any two x1 and x2 will not equal each other as long as x1 6= x2 .
b. f (x) = 6x
c. f (x) = 2x + 4
3. Are the following functions surjections from Z12 to Z6 ? (Note that bxc is the floor
operation on x.)
a. f (x) = b x2 c
b. f (x) = x
c. f (x) = b x4 c
Solution: No; the largest value we can get is f (12) which equals 3.
4. Why can we not have a surjection from Z12 to Z24 or an injection from Z12 to Z6 ?
Solution: Because there are more values in Z24 than Z12 , it is impossible to cover
all the values in Z24 by mapping from Z12 . Similarly, because there are more values
in Z12 than Z6 , there are not enough unique elements in Z6 to assign one to every
element in Z12 .
4.1 Introduction
Fermat’s Little Theorem: For any prime p and any a 2 {1, 2, . . . , p 1}, we have ap 1 ⌘ 1
mod p.
Proof: Claim: The function a ⇤ x mod p is a bijection where x 2 {1, 2, . . . , p 1.}
The domain and range of the function are the same set, so it is enough to show that if
x 6= x0 then a ⇤ x mod p 6= a ⇤ x0 mod p.
Assume that a ⇤ x mod p ⌘ a ⇤ x0 mod p.
Since gcd(a, p) = 1, a must have an inverse: a 1 ( mod p)
a 1
⇤a⇤x mod p ⌘ a 1
⇤ a ⇤ x0 mod p
x mod p ⌘ x0 mod p
This contradicts our assumption that x 6= x0 mod p. Therefore the function is a bijection.
We want to use the above claim to show that ap 1 ⌘ 1 mod p. Note that now we have
the following picture:
So if we multiply all elements in the domain together, this should equal the product of
all the elements in the image:
Solution:
(310 )500 mod 11 = 1500 mod 11 = 1.
Solution: By FLT:
26 ⌘ 1 mod 7
36 ⌘ 1 mod 7
46 ⌘ 1 mod 7
56 ⌘ 1 mod 7
66 ⌘ 1 mod 7
Apply the above facts to simplify each portion of the equation:
5.1 Introduction
Chinese Remainder Theorem: The Chinese Remainder theorem says that a sequence
of remainders with pairwise coprime divisors defines a unique remainder modulo the
product of those divisors. Formally, if x can be expressed as
x ⌘ a1 ( mod m1 )
x ⌘ a2 ( mod m2 )
where m1 and m2 are relatively prime to each other, CRT tells us that there is an unique
number mod m1 m2 that satisfies this equation.
In simple cases, we can often use extended Euclid’s algorithm to find x. However, a
failsafe equation is given by:
P ⇣ ⌘⇣ ⌘ 1
x = ki=1 ai bi mod N , where bi are defined as nNi N
ni
and N = n1 · n2 ... · nk .
mod ni
5.2 Questions
x⌘3 mod 4
x⌘5 mod 9
where 4 and 9 are relatively prime to each other. We write the congruence with
the largest modulus as an equation, x = 9t + 5. We substitute into the other con-
gruence and solve for t. 9t + 5 ⌘ 3 mod 4, which means 9t ⌘ 2 mod 4 and t ⌘ 2
mod 4. We write this congruence as an equation, t = 4s + 2, and substitute into
the equation for x. x = 9(4s + 2) + 5 = 36s + 23. So x = 23 mod 36 is the solution.
Note that lcm(4, 9) = 36.
2. The supermarket has a lot of eggs, but the manager is not sure exactly how many he
has. When he splits the eggs into groups of 5, there are exactly 3 left. When he splits
the eggs into groups of 11, there are 6 left. What is the minimum number of eggs at
the supermarket?
Solution: We have that x ⌘ 3 mod 5 and x ⌘ 6 mod 11. We can use the Chinese
Remainder Theorem to solve for x.
Recall from the note on modular arithmetic,⇣ ⌘the
⇣ solution
⌘ 1 to x is defined as x =
Pk
i=1 ai bi mod N , where bi are defined as ni and N = n1 · n2 ... · nk .
N N
ni
mod ni
n7 ⌘ n mod 7
n3 ⌘ n mod 3
n2 ⌘ n mod 2
We are interested in n7 so let’s modify the bottom two equations to write n7 in
mod 3 and mod 2.
n7 ⌘ n3 ⇤ n3 ⇤ n ⌘ n ⇤ n ⇤ n ⌘ n3 ⌘ n mod 3
n7 ⌘ n mod 3
n7 ⌘ n2 ⇤ n2 ⇤ n2 ⇤ n ⌘ n ⇤ n ⇤ n ⇤ n ⌘ n2 ⇤ n2 ⌘ n ⇤ n ⌘ n2 ⌘ n mod 2
n7 ⌘ n mod 2
So now we have that:
n7 ⌘ n mod 7
n7 ⌘ n mod 3
n7 ⌘ n mod 2
By CRT, we can say that n7 ⌘ n mod 7 ⇤ 3 ⇤ 2 ⌘ n mod 42.
6 RSA
6.1 Introduction
Main idea: Given two large primes, p and q, and a message x (an integer), find an
encryption function E and an decryption function D such that D(E(x)) = x. In other
words, two people can encrypt and decrypt a message if they know E and D.
Mechanism:
N = pq
E(x) = xe mod N
D(x) = xd mod N, where d = e 1 mod(p 1)(q 1)
The pair (N, e) is the recipient’s public key, and d is the recipient’s private key. The
sender sends E(x) to the recipient, and the recipient uses D(x) to recover the origi-
nal message. The security of RSA relies on the assumption that given N , there is no
efficient algorithm to determine (p 1)(q 1).
6.2 Questions
Solution:
51 = 5 mod 26
2
5 = 25 mod 26
= 1 mod 26
54 = ( 1)2 mod 26
=1 mod 26
8
5 = 1 mod 26
511 = 58 ⇤ 52 ⇤ 51 mod 26
=1⇤ 1⇤5 mod 26
= 5 mod 26
= 21 mod 26
b. What is the value of d (Bob’s private key) in this scheme? Note that traditional
2. In RSA, if Alice wants to send a confidential message to Bob, she uses Bob’s public
key to encode it. Then Bob uses his private key to decode the message. Suppose that
Bob chose N = 77. And then Bob chose e = 3 so his public key is (3, 77). And then
Bob chose d = 26 so his private key is (26, 77).
Will this work for encoding and decoding messages? If not, where did Bob first go
wrong in the above sequence of steps and what is the consequence of that error? If it
does work, then show that it works.