SlideShare a Scribd company logo
1 of 46
Chinese Remainder Theorem
1
M.M.A. Hashem, PhD
Professor
Dept. of Computer Science and Engineering
Khulna University of Engineering & Technology
(KUET)
CSE 1107
Discrete Mathematics
Warm-up problem
Example: Solve the congruence 5x ≡ 4 (mod 17)
2
Warm-up problem
Example: Solve the congruence 5x ≡ 4 (mod 17)
Solution:
First, we check that 5 and 17 are indeed relatively prime using the Euclidean algorithm:
17 = 3 · 5 + 2
5 = 2 · 2 + 1
2 = 2 · 1 + 0
gcd(5, 17) = 1, so 5 has an inverse modulo 17. We use the EA in reverse to find it:
1 = 5 - 2 · 2
= 5 - 2 · (17 - 3 · 5)
= 7 · 5 - 2 · 17
So 7 is the inverse of 5 modulo 17, which means:
x ≡ 7 · 4 (mod 17) ≡ 28 (mod 17) ≡ 11 (mod 17) 3
Warm-Up for CRT
4
In mathematics, the Chinese remainder theorem states that if one
knows the remainders of the Euclidean division of an integer n by
several integers, then one can determine uniquely the remainder of the
division of n by the product of these integers, under the condition that
the divisors are pairwise coprime (no two divisors share a common
factor other than 1).
For example, if we know that the remainder of n divided by 3 is 2, the
remainder of n divided by 5 is 3, and the remainder of n divided by 7 is 2,
then without knowing the value of n, we can determine that the remainder
of n divided by 105 (the product of 3, 5, and 7) is 23. Importantly, this tells
us that if n is a natural number less than 105, then 23 is the only possible
value of n.
What did we do last time?
● Solving congruence relations (e.g., 5x ≡ 4 (mod 17))
● Remember how you could find a solution to
multiple linear equations?
→ A system of linear equations
● We’ll tackle the analogous task for congruence relations
→ Solving systems of congruence relations
● We’ll also learn Fermat’s Little Theorem, which helps calculate large numbers, and
● Dip our toes into the waters of cryptography
5
6
Riddle me this: Can you find a number that when divided by 3, the
remainder is 2; and when divided by 5, the remainder is 3?
Equivalent problem: Find x such that
x ≡ 2 (mod 3)
x ≡ 3 (mod 5)
This is called a system of linear congruences.
Note that the divisors 3 and 5 are relatively prime.
(We will later see that this comes in handy!)
Chinese Remainder Theorem
7
Can you find a number that when divided by 3, the remainder is 2;
when divided by 5, the remainder is 3; and when divided by 7,
the remainder is 2?
The earliest known statement of the theorem is by the Chinese mathematician Sun-tzu
in the Sun-tzu Suan-ching in the 3rd century CE.
Equivalent problem: Find x such that
x ≡ 2 (mod 3)
x ≡ 3 (mod 5)
x ≡ 2 (mod 7)
This is called a system of linear congruences.
Note that the divisors 3, 5 and 7 are relatively prime.
Sun-tzu's original formulation: x ≡ 2 (mod 3) ≡ 3 (mod 5) ≡ 2 (mod 7) with the solution x =
23 + 105k, with k an integer
Chinese Remainder Theorem
8
Back Substitution: A straightforward option for solving systems of congruences
Example: Find x such that x ≡ 2 (mod 3), x ≡ 3 (mod 5)
Chinese Remainder Theorem
9
Back Substitution: A straightforward option for solving systems of congruences
Example: Find x such that x ≡ 2 (mod 3), x ≡ 3 (mod 5)
Chinese Remainder Theorem
10
Back Substitution: A straightforward option for solving systems of congruences
Example: Find x such that x ≡ 2 (mod 3), x ≡ 3 (mod 5)
x ≡ 2 (mod 3) ⇒ x = 3t + 2 for some integer t
Then we can substitute this form for x into the next congruence, and solve for t
x = 3t + 2 ≡ 3 (mod 5) ⇒ 3t ≡ 1 (mod 5)
So we want an inverse for 3 (mod 5) ← one exists, because 3 and 5 are rel. prime!
Turns out 2 works (because 2·3 = 6 ≡ 1 (mod 5))
⇒ 3t ≡ 1 (mod 5) ⇒ 2·3t ≡ 2·1 (mod 5) ⇒ t ≡ 2 (mod 5)
And this means that t-2 is divisible by 5.
⇒ so t = 5u + 2 for some integer u
Chinese Remainder Theorem
11
Back Substitution: A straightforward option for solving systems of congruences
Example: Find x such that x ≡ 2 (mod 3), x ≡ 3 (mod 5)
x ≡ 2 (mod 3) ⇒ x = 3t + 2 for some integer t
And t = 5u + 2
Finally, we substitute this updated form for t into our expression for x (above) and that’s our
solution to the system:
⇒ x = 3t + 2 = 3(5u + 2) + 2 = 15u + 6 + 2 = 15u + 8
⇒ x ≡ 8 (mod 15)
FYOG: Use Back Substitution to find x such that: x ≡ 1 (mod 5) and x ≡ 3 (mod 7)
Chinese Remainder Theorem
12
Turns out, we have a theorem that provides a way to solve general congruence systems.
Chinese Remainder Theorem: Let m1, m2, … , mn be positive integers that are relatively
prime, and a1, a2, … , an be arbitrary integers. Then the system
x ≡ a1 (mod m1)
x ≡ a2 (mod m2)
…
x ≡ an (mod mn)
has a unique solution modulo m = m1 · m2 · ··· · mn
Let . And let yk be the inverse of Mk (mod mk )
Then the solution is: x = a1 M1 y1 + a2 M2 y2 + … + an Mn yn (mod m)
Chinese Remainder Theorem
13
Proof (FYOG): We will prove that a solution exists by construction.
Let , for k = 1, 2, …, n
Note that Mk is the product of all mi’s except for mk
Since the mi’s are all relatively prime, so are Mk and mk
Since gcd(Mk , mk) = 1, there exists an inverse of Mk modulo mk, yk , s.t.
Mk yk ≡ 1 (mod mk)
Find inverse for each Mk, then a solution is
x = a1 M1 y1 + a2 M2 y2 + … + an Mn yn (mod m)
Chinese Remainder Theorem
14
Proof (cont.):
Find inverse for each Mk, then a solution is x = a1 M1 y1 + a2 M2 y2 + … + an Mn yn (mod
m)
To see that this is a solution, note that each Mi ≡ 0 (mod mk) whenever i ≠ k
Since all of the terms in the sum except Mk are congruent to 0 modulo mk, we have,
for any k = 1, 2, … , n :
x ≡ a1 M1 y1 + a2 M2 y2 + … + an Mn yn (mod mk)
≡ ak Mk yk (mod mk)
≡ ak (mod mk)
Thus, x solves each congruence in the system.
The uniqueness proof is in #29-30 in Section 4.4 of the textbook.
Chinese Remainder Theorem
15
Back to our original example: Find x such that
x ≡ 2 (mod 3)
x ≡ 3 (mod 5)
Chinese Remainder Theorem
16
Back to our original example: Find x such that
x ≡ 2 (mod 3)
x ≡ 3 (mod 5)
So our mk are m1 = 3, m2 = 5
We define: m = 3 · 5 = 15
And M1 = 15/3 = 5, M2 = 15/5 = 3
Then we need the yk, which are the inverses of 5 modulo 3, and 3 modulo 5
Chinese Remainder Theorem
17
Chinese Remainder Theorem
Back to our original example: Find x such that
x ≡ 2 (mod 3)
x ≡ 3 (mod 5)
Then we need the yk, which are the inverse of 5 modulo 3, and 3 modulo 5
5 = 1·3 + 2
3 = 1·2 + 1
… and working in reverse …
1 = 3 - 1·2
= 3 - 1·(5 - 1·3)
= 2·3 - 1·5
⇒ So the inverse of 5 modulo 3 is y1 = -1
18
Chinese Remainder Theorem
Back to our original example: Find x such that
x ≡ 2 (mod 3)
x ≡ 3 (mod 5)
Then we need the yk, which are the inverse of 5 modulo 3, and 3 modulo 5
5 = 1·3 + 2 ← turns out, we already did this work!
3 = 1·2 + 1
… and working in reverse …
1 = 3 - 1·2
= 3 - 1·(5 - 1·3)
= 2·3 - 1·5
⇒ So the inverse of 3 modulo 5 is y2 = 2
Back to our original example: Find x such that
x ≡ 2 (mod 3)
x ≡ 3 (mod 5)
● We have our inverses: y1 = -1, and y2 = 2
● and our Mk: M1 = 5, and M2 = 3
● and the problem gives the ak: a1 = 2, and a2 = 3
● So we construct our solution:
x = a1 M1 y1 + a2 M2 y2 ≡ (2)(5)(-1) + (3)(3)(2) (mod 15)
≡ -10 + 18 (mod 15)
≡ 8 (mod 15) ← Compare to what we got by Back Substitution
19
Chinese Remainder Theorem
20
Chinese Remainder Theorem
Back to our original example: Find x such that
x ≡ 2 (mod 3)
x ≡ 3 (mod 5)
Solution: x ≡ 8 (mod 15)
Check:
8 = 2·3 + 2 ≡ 2 (mod 3) ✔
8 = 1·5 + 3 ≡ 3 (mod 5) ✔
21
FYOG: Use the Chinese Remainder Theorem to find x such that
x ≡ 1 (mod 5)
x ≡ 3 (mod 7)
Make sure you get the same answer as when you use Back Substitution!
Chinese Remainder Theorem
22
FYOG: Use the Chinese Remainder Theorem to find x such that
x ≡ 1 (mod 5)
x ≡ 2 (mod 6)
x ≡ 3 (mod 7)
FYOG: Make sure you get the same answer using Back Substitution!
Note: The Chinese remainder theorem is widely used for computing with large integers, as it
allows replacing a computation for which one knows a bound on the size of the result by
several similar computations on small integers.
Note: We are mostly concerned about whether you can solve the 2-congruence systems
(using both Chinese Remainder Theorem and Back Substitution), because that’s what you
need for RSA. These 3-congruence (or more) systems are truly just For Your Own Good.
Chinese Remainder Theorem
23
● The following theorem shows that in special cases, we can compute modular exponentials
extremely fast
● Fermat’s Little Theorem: If p is prime and a is an integer that is not divisible by p, then
ap-1 ≡ 1 (mod p)
● Example:
56 (mod 7) ≡ 15625 (mod 7)
≡ 2232·7 + 1 (mod 7)
≡ 1 (mod 7)
Fermat’s Little Theorem
24
Example: Use Fermat’s Little Theorem to calculate 7222 (mod 11)
Fermat’s Little Theorem
25
Example: Use Fermat’s Little Theorem to calculate 7222 (mod 11)
Solution:
First, note that FLT applies because p = 11 is prime and a = 7 is an integer not divisible by 11.
Now FLT tells us that 710 ≡ 1 (mod 11)
And we remember (or look up) that ak (mod m) ≡ (a mod m)k
So 7222 = 710·22 + 2 = (710)22 · 72
≡ 122 · 49 (mod 11)
≡ 5 (mod 11)
Fermat’s Little Theorem
26
Fermat’s Little Theorem
Example: Use Fermat’s Little Theorem to calculate 3302 (mod 5)
Solution:
First, note that FLT applies because p = 5 is prime and a = 3 is an integer not divisible by 5.
Now FLT tells us that 34 ≡ 1 (mod 5), and we know that 302 = 4·75 + 2,
and we remember (or look up) that ak (mod m) ≡ (a mod m)k
So 3302 = 34·75 + 2 = (34)75 · 32
≡ 175 · 9 (mod 5)
≡ 4 (mod 5)
27
FYOG: Calculate 52003 (mod 7), 52003 (mod 11), and 52003 (mod 13)
Fermat’s Little Theorem
One of the earliest known cryptographic ciphers was used by Julius Caesar. His strategy was
to shift each letter of the alphabet forward 3 places, wrapping around when you get to the end.
In this scheme, for example: A ↦ D, K ↦ N, Y ↦ B
This is often called a Caesar Cipher or a Shift Cipher.
● Mathematically, we can accomplish this by assigning to each letter a number between 0
and 25. For example:
A ↦ 0, K ↦ 10, Y ↦ 24
● The encoding can be done by passing the value through a shift function modulo 26:
f(p) = (p+3) mod 26
28
Cryptography warm-up
In general, for a shift k we can use the function
f(p) = (p+k) mod 26
We can encode a message by:
1. Convert letters to numbers between 0 and 25
2. Pass each value through f(p)
● Example: Encode HELLO WORLD using a shift=5 cipher
1. Convert to numbers: HELLO WORLD ↦ 7 4 11 11 14 22 14 17 11 3
2. Shift: 12 9 16 16 19 1 19 22 16 8
The encoded message is: MJQQT BTWQI
29
Cryptography warm-up
● How do we decode a message like MJQQT BTWQI ?
● If we know the shift, then it’s easy - just run the message through the inverse:
f -1(p) = (p - k) mod 26
● Why is this not a very secure cipher?
30
Cryptography warm-up
The Affine Cipher
● Instead of only shifting, multiply and then shift
f(p) = (ap + b) mod 26
where a and b are integers with gcd(a, 26) = 1
● S’pose we know a and b (i.e., we have the key) - how could we decode a message?
31
Cryptography warm-up
S’pose we know a and b (i.e., we have the key) - how could we decode a message?
● S’pose we have an encrypted character c that we know must satisfy
c ≡ ap + b (mod 26)
● Then we need to solve this congruence for p. So subtract b from both sides
c - b ≡ ap (mod 26)
● Now we need the inverse of a (modulo 26), which we know exists because
gcd(a, 26) = 1. Call the inverse , and we have
p ≡ (c - b) (mod 26)
32
Cryptography warm-up
Example: Use an affine cipher with a=7 and b=13 to encrypt the letter K.
Example: Find a decryption formula for this affine cipher and use it to decrypt the character F.
33
Cryptography warm-up
Example: Use an affine cipher with a=7 and b=13 to encrypt the letter K.
Solution: The numerical value for K is 10, so we have
K ↦ a · 10 + b = 7·10 + 13 = 83 ≡ 5 (mod 26) ↦ F
Example: Find a decryption formula for this affine cipher and use it to decrypt the character F.
Solution: Recall from earlier that we had the formula: p ≡ (c - b) (mod 26)
So we need the inverse of a = 7 (modulo 26)
34
Cryptography warm-up
Example: Find a decryption formula for this affine cipher and use it to decrypt the character F.
35
Cryptography warm-up
Example: Find a decryption formula for this affine cipher and use it to decrypt the character F.
So we need the inverse of a = 7 (modulo 26):
26 = 3·7 + 5
7 = 1·5 + 2
5 = 2·2 + 1
… and in reverse …
1 = 5 - 2·2
= 5 - 2·(7-1·5) = 3·5 - 2·7
= 3·(26 - 3·7) - 2·7 = 3·26 - 11·7
So the inverse of 7 (modulo 26) is -11
36
Cryptography warm-up
Example: Find a decryption formula for this affine cipher and use it to decrypt the character F.
So the inverse of 7 (modulo 26) is -11
Plugging into the decryption formula we have: (with character F ↦ 5)
p ≡ (c - b) (mod 26)
≡ -11 · (5 - 13) (mod 26)
≡ 88 (mod 26) (note: 26·3 = 78)
≡ 10 (mod 26) ↦ K
37
Cryptography warm-up
Example: Find a decryption formula for this affine cipher and use it to decrypt the character F.
So the inverse of 7 (modulo 26) is -11
Plugging into the decryption formula we have: (with character F ↦ 5)
p ≡ (c - b) (mod 26)
≡ -11 · (5 - 13) (mod 26)
≡ 88 (mod 26) (note: 26·3 = 78)
≡ 10 (mod 26) ↦ K
FYOG: Encrypt HELLO WORLD with an affine cipher with a=5 and b=17. Derive the
decryption formula and check that your encrypted message decrypts back properly.
38
Cryptography warm-up
Recap:
● Back substitution and Chinese Remainder Theorem provide two avenues to solve
systems of congruences
● Fermat’s Little Theorem offers a nice way to calculate giant numbers quickly
● Affine and shift cyphers -- two relatively simple examples for encoding/decoding
messages; based on shifting and multiplying your intended message
Next time:
● Cryptography-Heavy and bringing it all
this number theory together: RSA
39
Systems of congruences and Cryptography-Lite
Bonus
material!
40
41
FYOG: Use the Chinese Remainder Theorem (CRT) to find x such that
x ≡ 1 (mod 5)
x ≡ 2 (mod 6)
x ≡ 3 (mod 7)
Solution: CRT gives that the solution is x ≡ a1 M1 y1 + a2 M2 y2 + a3 M3 y3 (mod m)
⇒ a1 = 1, a2 = 2, and a3 = 3 are given in the problem
⇒ m = m1 ·m2 ·m3 = 5·6·7 = 210
⇒ M1 = m/m1 = 210/5 = 42, M2 = m/m2 = 210/6 = 35, M3 = m/m3 = 210/7 = 30
So now we need the yk, which are the inverses of the Mk (mod mk ).
FYOG: hints!
42
So now we need the yk, which are the inverses of the Mk (mod mk ).
M1 y1 ≡ 1 (mod m1) ⇒ 42y1 ≡ 1 (mod 5)
Euclidean Algorithm:
42 = 5·8 + 2
5 = 2·2 + 1
2 = 1·2 + 0 (gcd(5,42) = last nonzero remainder = 1, so they’re relatively prime and an inverse exists.
good!)
Reverse Euclidean Algorithm:
1 = 5 - 2·2
= 5 - 2·(42 - 8·5) = 5 - 2·42 + 16·5
= 17·5 - 2·42
⇒ So an inverse of 42 (modulo 5) is -2
Similarly, the inverses of 35 (mod 6) is -1, and an inverse of 30 (mod 7) is -3. These are our yk
FYOG: hints!
43
So putting everything together, we find:
x ≡ a1 M1 y1 + a2 M2 y2 + a3 M3 y3 (mod m)
≡ 1·42·(-2) + 2·35·(-1) + 3·30·(-3) (mod 210)
≡ -84 - 70 - 270 (mod 210)
≡ -424 (mod 210) ← note that 210·(-2) = -420
≡ -4 (mod 210)
Check: -4 ≡ 1 (mod 5) ?
-4 ≡ 2 (mod 6) ?
-4 ≡ 3 (mod 7) ?
FYOG: hints!
44
FYOG: Use Back Substitution to find x such that
x ≡ 1 (mod 5)
x ≡ 2 (mod 6)
x ≡ 3 (mod 7)
Solution: From the previous example using Chinese Remainder Theorem on this same system, you know the
answer should be x ≡ -4 (mod 210).
First congruence: x ≡ 1 (mod 5) ⇒ 5k = x-1 (some integer k) ⇒ x = 5k+1
+ Second congruence: x = 5k + 1 ≡ 2 (mod 6)
⇒ 5k ≡ 1 (mod 6) ⇒ need an inverse of 5 (mod 6)?
⇒ -1 works (because 5·(-1) = -5 = -1·6 + 1)
⇒ So (-1)·5k ≡ (-1)·1 (mod 6)
⇒ k ≡ -1 (mod 6)
⇒ 6m = k+1 (some integer m), which means k = 6m - 1
FYOG: hints!
45
⇒ x = 5k + 1 = 5(6m - 1) + 1 = 30m -5 + 1 = 30m - 4
+ Third congruence: x = 30m - 4 ≡ 3 (mod 7)
⇒ 30m ≡ 7 (mod 7) ≡ 0 (mod 7)
⇒ m ≡ 0 (mod 7)
⇒ 7n = m (some integer n)
⇒ x = 30(7n) - 4 = 210n - 4 ← this line is saying that if you divide x by 210, then the remainder is -4, so...
⇒ x ≡ -4 (mod 210)
FYOG: hints!
46
FYOG: Calculate 52003 (mod 7), 52003 (mod 11), and 52003 (mod 13)
Solution:
52003 (mod 7) = ?
p=7 is prime, and 7 does not divide a=5, so Fermat’s Little Theorem applies.
⇒ 57-1 = 56 ≡ 1 (mod 7)
And we know (probably by using a calculator) that 2003 = 6·333 + 5
⇒ 52003 = (56)333 · 55 ≡ (1)333 · 55 (mod 7) ≡ 55 (mod 7) ≡ 3125 (mod 7) ≡ 3 (mod 7)
Similarly…
52003 ≡ 4 (mod 11), and
52003 ≡ 8 (mod 13)
FYOG: hints!

More Related Content

Similar to CSE1107 Chinese Remainder Theorem in Discrete Mathmatics.pptx

modul pembelajaran 4
modul pembelajaran 4modul pembelajaran 4
modul pembelajaran 4Ajrina Pia
 
18-21 Principles of Least Squares.ppt
18-21 Principles of Least Squares.ppt18-21 Principles of Least Squares.ppt
18-21 Principles of Least Squares.pptBAGARAGAZAROMUALD2
 
U1 04 factorizacion
U1   04 factorizacionU1   04 factorizacion
U1 04 factorizacionUNEFA Zulia
 
7.2 Systems of Linear Equations - Three Variables
7.2 Systems of Linear Equations - Three Variables7.2 Systems of Linear Equations - Three Variables
7.2 Systems of Linear Equations - Three Variablessmiller5
 
Research Inventy : International Journal of Engineering and Science
Research Inventy : International Journal of Engineering and ScienceResearch Inventy : International Journal of Engineering and Science
Research Inventy : International Journal of Engineering and Scienceinventy
 
09-FermatEuler.ppt
09-FermatEuler.ppt09-FermatEuler.ppt
09-FermatEuler.pptmnadil1
 
Final presentation
Final presentationFinal presentation
Final presentationpaezp
 
Lecture 10a system of linear equations
Lecture 10a system of linear equationsLecture 10a system of linear equations
Lecture 10a system of linear equationsHazel Joy Chong
 
Maths iii quick review by Dr Asish K Mukhopadhyay
Maths iii quick review by Dr Asish K MukhopadhyayMaths iii quick review by Dr Asish K Mukhopadhyay
Maths iii quick review by Dr Asish K MukhopadhyayDr. Asish K Mukhopadhyay
 
Business Math Chapter 3
Business Math Chapter 3Business Math Chapter 3
Business Math Chapter 3Nazrin Nazdri
 
Mathnasium Presentation (1)
Mathnasium Presentation (1)Mathnasium Presentation (1)
Mathnasium Presentation (1)Muhammad Arslan
 
DIFFERENTIATION Integration and limits (1).pptx
DIFFERENTIATION Integration and limits (1).pptxDIFFERENTIATION Integration and limits (1).pptx
DIFFERENTIATION Integration and limits (1).pptxOchiriaEliasonyait
 
Synthetic and Remainder Theorem of Polynomials.ppt
Synthetic and Remainder Theorem of Polynomials.pptSynthetic and Remainder Theorem of Polynomials.ppt
Synthetic and Remainder Theorem of Polynomials.pptMarkVincentDoria1
 

Similar to CSE1107 Chinese Remainder Theorem in Discrete Mathmatics.pptx (20)

modul pembelajaran 4
modul pembelajaran 4modul pembelajaran 4
modul pembelajaran 4
 
18-21 Principles of Least Squares.ppt
18-21 Principles of Least Squares.ppt18-21 Principles of Least Squares.ppt
18-21 Principles of Least Squares.ppt
 
U1 04 factorizacion
U1   04 factorizacionU1   04 factorizacion
U1 04 factorizacion
 
14. trigo eqs.ppt
14. trigo eqs.ppt14. trigo eqs.ppt
14. trigo eqs.ppt
 
7.2 Systems of Linear Equations - Three Variables
7.2 Systems of Linear Equations - Three Variables7.2 Systems of Linear Equations - Three Variables
7.2 Systems of Linear Equations - Three Variables
 
Research Inventy : International Journal of Engineering and Science
Research Inventy : International Journal of Engineering and ScienceResearch Inventy : International Journal of Engineering and Science
Research Inventy : International Journal of Engineering and Science
 
09-FermatEuler.ppt
09-FermatEuler.ppt09-FermatEuler.ppt
09-FermatEuler.ppt
 
Lecture3
Lecture3Lecture3
Lecture3
 
Final presentation
Final presentationFinal presentation
Final presentation
 
Lecture 10a system of linear equations
Lecture 10a system of linear equationsLecture 10a system of linear equations
Lecture 10a system of linear equations
 
Maths iii quick review by Dr Asish K Mukhopadhyay
Maths iii quick review by Dr Asish K MukhopadhyayMaths iii quick review by Dr Asish K Mukhopadhyay
Maths iii quick review by Dr Asish K Mukhopadhyay
 
Business Math Chapter 3
Business Math Chapter 3Business Math Chapter 3
Business Math Chapter 3
 
Mathnasium Presentation (1)
Mathnasium Presentation (1)Mathnasium Presentation (1)
Mathnasium Presentation (1)
 
Hprec2 1
Hprec2 1Hprec2 1
Hprec2 1
 
DIFFERENTIATION Integration and limits (1).pptx
DIFFERENTIATION Integration and limits (1).pptxDIFFERENTIATION Integration and limits (1).pptx
DIFFERENTIATION Integration and limits (1).pptx
 
Solving Quadratic Equations by Factoring
Solving Quadratic Equations by FactoringSolving Quadratic Equations by Factoring
Solving Quadratic Equations by Factoring
 
Synthetic and Remainder Theorem of Polynomials.ppt
Synthetic and Remainder Theorem of Polynomials.pptSynthetic and Remainder Theorem of Polynomials.ppt
Synthetic and Remainder Theorem of Polynomials.ppt
 
Chinese
ChineseChinese
Chinese
 
Rsa example
Rsa exampleRsa example
Rsa example
 
3
33
3
 

Recently uploaded

Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxolyaivanovalion
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Delhi Call girls
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAroojKhan71
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSAishani27
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusTimothy Spann
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改atducpo
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz1
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Callshivangimorya083
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfRachmat Ramadhan H
 
Data-Analysis for Chicago Crime Data 2023
Data-Analysis for Chicago Crime Data  2023Data-Analysis for Chicago Crime Data  2023
Data-Analysis for Chicago Crime Data 2023ymrp368
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...Suhani Kapoor
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiSuhani Kapoor
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingNeil Barnes
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxolyaivanovalion
 

Recently uploaded (20)

Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFx
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
 
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in  KishangarhDelhi 99530 vip 56974 Genuine Escort Service Call Girls in  Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICS
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 
Data-Analysis for Chicago Crime Data 2023
Data-Analysis for Chicago Crime Data  2023Data-Analysis for Chicago Crime Data  2023
Data-Analysis for Chicago Crime Data 2023
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdf
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data Storytelling
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptx
 

CSE1107 Chinese Remainder Theorem in Discrete Mathmatics.pptx

  • 1. Chinese Remainder Theorem 1 M.M.A. Hashem, PhD Professor Dept. of Computer Science and Engineering Khulna University of Engineering & Technology (KUET) CSE 1107 Discrete Mathematics
  • 2. Warm-up problem Example: Solve the congruence 5x ≡ 4 (mod 17) 2
  • 3. Warm-up problem Example: Solve the congruence 5x ≡ 4 (mod 17) Solution: First, we check that 5 and 17 are indeed relatively prime using the Euclidean algorithm: 17 = 3 · 5 + 2 5 = 2 · 2 + 1 2 = 2 · 1 + 0 gcd(5, 17) = 1, so 5 has an inverse modulo 17. We use the EA in reverse to find it: 1 = 5 - 2 · 2 = 5 - 2 · (17 - 3 · 5) = 7 · 5 - 2 · 17 So 7 is the inverse of 5 modulo 17, which means: x ≡ 7 · 4 (mod 17) ≡ 28 (mod 17) ≡ 11 (mod 17) 3
  • 4. Warm-Up for CRT 4 In mathematics, the Chinese remainder theorem states that if one knows the remainders of the Euclidean division of an integer n by several integers, then one can determine uniquely the remainder of the division of n by the product of these integers, under the condition that the divisors are pairwise coprime (no two divisors share a common factor other than 1). For example, if we know that the remainder of n divided by 3 is 2, the remainder of n divided by 5 is 3, and the remainder of n divided by 7 is 2, then without knowing the value of n, we can determine that the remainder of n divided by 105 (the product of 3, 5, and 7) is 23. Importantly, this tells us that if n is a natural number less than 105, then 23 is the only possible value of n.
  • 5. What did we do last time? ● Solving congruence relations (e.g., 5x ≡ 4 (mod 17)) ● Remember how you could find a solution to multiple linear equations? → A system of linear equations ● We’ll tackle the analogous task for congruence relations → Solving systems of congruence relations ● We’ll also learn Fermat’s Little Theorem, which helps calculate large numbers, and ● Dip our toes into the waters of cryptography 5
  • 6. 6 Riddle me this: Can you find a number that when divided by 3, the remainder is 2; and when divided by 5, the remainder is 3? Equivalent problem: Find x such that x ≡ 2 (mod 3) x ≡ 3 (mod 5) This is called a system of linear congruences. Note that the divisors 3 and 5 are relatively prime. (We will later see that this comes in handy!) Chinese Remainder Theorem
  • 7. 7 Can you find a number that when divided by 3, the remainder is 2; when divided by 5, the remainder is 3; and when divided by 7, the remainder is 2? The earliest known statement of the theorem is by the Chinese mathematician Sun-tzu in the Sun-tzu Suan-ching in the 3rd century CE. Equivalent problem: Find x such that x ≡ 2 (mod 3) x ≡ 3 (mod 5) x ≡ 2 (mod 7) This is called a system of linear congruences. Note that the divisors 3, 5 and 7 are relatively prime. Sun-tzu's original formulation: x ≡ 2 (mod 3) ≡ 3 (mod 5) ≡ 2 (mod 7) with the solution x = 23 + 105k, with k an integer Chinese Remainder Theorem
  • 8. 8 Back Substitution: A straightforward option for solving systems of congruences Example: Find x such that x ≡ 2 (mod 3), x ≡ 3 (mod 5) Chinese Remainder Theorem
  • 9. 9 Back Substitution: A straightforward option for solving systems of congruences Example: Find x such that x ≡ 2 (mod 3), x ≡ 3 (mod 5) Chinese Remainder Theorem
  • 10. 10 Back Substitution: A straightforward option for solving systems of congruences Example: Find x such that x ≡ 2 (mod 3), x ≡ 3 (mod 5) x ≡ 2 (mod 3) ⇒ x = 3t + 2 for some integer t Then we can substitute this form for x into the next congruence, and solve for t x = 3t + 2 ≡ 3 (mod 5) ⇒ 3t ≡ 1 (mod 5) So we want an inverse for 3 (mod 5) ← one exists, because 3 and 5 are rel. prime! Turns out 2 works (because 2·3 = 6 ≡ 1 (mod 5)) ⇒ 3t ≡ 1 (mod 5) ⇒ 2·3t ≡ 2·1 (mod 5) ⇒ t ≡ 2 (mod 5) And this means that t-2 is divisible by 5. ⇒ so t = 5u + 2 for some integer u Chinese Remainder Theorem
  • 11. 11 Back Substitution: A straightforward option for solving systems of congruences Example: Find x such that x ≡ 2 (mod 3), x ≡ 3 (mod 5) x ≡ 2 (mod 3) ⇒ x = 3t + 2 for some integer t And t = 5u + 2 Finally, we substitute this updated form for t into our expression for x (above) and that’s our solution to the system: ⇒ x = 3t + 2 = 3(5u + 2) + 2 = 15u + 6 + 2 = 15u + 8 ⇒ x ≡ 8 (mod 15) FYOG: Use Back Substitution to find x such that: x ≡ 1 (mod 5) and x ≡ 3 (mod 7) Chinese Remainder Theorem
  • 12. 12 Turns out, we have a theorem that provides a way to solve general congruence systems. Chinese Remainder Theorem: Let m1, m2, … , mn be positive integers that are relatively prime, and a1, a2, … , an be arbitrary integers. Then the system x ≡ a1 (mod m1) x ≡ a2 (mod m2) … x ≡ an (mod mn) has a unique solution modulo m = m1 · m2 · ··· · mn Let . And let yk be the inverse of Mk (mod mk ) Then the solution is: x = a1 M1 y1 + a2 M2 y2 + … + an Mn yn (mod m) Chinese Remainder Theorem
  • 13. 13 Proof (FYOG): We will prove that a solution exists by construction. Let , for k = 1, 2, …, n Note that Mk is the product of all mi’s except for mk Since the mi’s are all relatively prime, so are Mk and mk Since gcd(Mk , mk) = 1, there exists an inverse of Mk modulo mk, yk , s.t. Mk yk ≡ 1 (mod mk) Find inverse for each Mk, then a solution is x = a1 M1 y1 + a2 M2 y2 + … + an Mn yn (mod m) Chinese Remainder Theorem
  • 14. 14 Proof (cont.): Find inverse for each Mk, then a solution is x = a1 M1 y1 + a2 M2 y2 + … + an Mn yn (mod m) To see that this is a solution, note that each Mi ≡ 0 (mod mk) whenever i ≠ k Since all of the terms in the sum except Mk are congruent to 0 modulo mk, we have, for any k = 1, 2, … , n : x ≡ a1 M1 y1 + a2 M2 y2 + … + an Mn yn (mod mk) ≡ ak Mk yk (mod mk) ≡ ak (mod mk) Thus, x solves each congruence in the system. The uniqueness proof is in #29-30 in Section 4.4 of the textbook. Chinese Remainder Theorem
  • 15. 15 Back to our original example: Find x such that x ≡ 2 (mod 3) x ≡ 3 (mod 5) Chinese Remainder Theorem
  • 16. 16 Back to our original example: Find x such that x ≡ 2 (mod 3) x ≡ 3 (mod 5) So our mk are m1 = 3, m2 = 5 We define: m = 3 · 5 = 15 And M1 = 15/3 = 5, M2 = 15/5 = 3 Then we need the yk, which are the inverses of 5 modulo 3, and 3 modulo 5 Chinese Remainder Theorem
  • 17. 17 Chinese Remainder Theorem Back to our original example: Find x such that x ≡ 2 (mod 3) x ≡ 3 (mod 5) Then we need the yk, which are the inverse of 5 modulo 3, and 3 modulo 5 5 = 1·3 + 2 3 = 1·2 + 1 … and working in reverse … 1 = 3 - 1·2 = 3 - 1·(5 - 1·3) = 2·3 - 1·5 ⇒ So the inverse of 5 modulo 3 is y1 = -1
  • 18. 18 Chinese Remainder Theorem Back to our original example: Find x such that x ≡ 2 (mod 3) x ≡ 3 (mod 5) Then we need the yk, which are the inverse of 5 modulo 3, and 3 modulo 5 5 = 1·3 + 2 ← turns out, we already did this work! 3 = 1·2 + 1 … and working in reverse … 1 = 3 - 1·2 = 3 - 1·(5 - 1·3) = 2·3 - 1·5 ⇒ So the inverse of 3 modulo 5 is y2 = 2
  • 19. Back to our original example: Find x such that x ≡ 2 (mod 3) x ≡ 3 (mod 5) ● We have our inverses: y1 = -1, and y2 = 2 ● and our Mk: M1 = 5, and M2 = 3 ● and the problem gives the ak: a1 = 2, and a2 = 3 ● So we construct our solution: x = a1 M1 y1 + a2 M2 y2 ≡ (2)(5)(-1) + (3)(3)(2) (mod 15) ≡ -10 + 18 (mod 15) ≡ 8 (mod 15) ← Compare to what we got by Back Substitution 19 Chinese Remainder Theorem
  • 20. 20 Chinese Remainder Theorem Back to our original example: Find x such that x ≡ 2 (mod 3) x ≡ 3 (mod 5) Solution: x ≡ 8 (mod 15) Check: 8 = 2·3 + 2 ≡ 2 (mod 3) ✔ 8 = 1·5 + 3 ≡ 3 (mod 5) ✔
  • 21. 21 FYOG: Use the Chinese Remainder Theorem to find x such that x ≡ 1 (mod 5) x ≡ 3 (mod 7) Make sure you get the same answer as when you use Back Substitution! Chinese Remainder Theorem
  • 22. 22 FYOG: Use the Chinese Remainder Theorem to find x such that x ≡ 1 (mod 5) x ≡ 2 (mod 6) x ≡ 3 (mod 7) FYOG: Make sure you get the same answer using Back Substitution! Note: The Chinese remainder theorem is widely used for computing with large integers, as it allows replacing a computation for which one knows a bound on the size of the result by several similar computations on small integers. Note: We are mostly concerned about whether you can solve the 2-congruence systems (using both Chinese Remainder Theorem and Back Substitution), because that’s what you need for RSA. These 3-congruence (or more) systems are truly just For Your Own Good. Chinese Remainder Theorem
  • 23. 23 ● The following theorem shows that in special cases, we can compute modular exponentials extremely fast ● Fermat’s Little Theorem: If p is prime and a is an integer that is not divisible by p, then ap-1 ≡ 1 (mod p) ● Example: 56 (mod 7) ≡ 15625 (mod 7) ≡ 2232·7 + 1 (mod 7) ≡ 1 (mod 7) Fermat’s Little Theorem
  • 24. 24 Example: Use Fermat’s Little Theorem to calculate 7222 (mod 11) Fermat’s Little Theorem
  • 25. 25 Example: Use Fermat’s Little Theorem to calculate 7222 (mod 11) Solution: First, note that FLT applies because p = 11 is prime and a = 7 is an integer not divisible by 11. Now FLT tells us that 710 ≡ 1 (mod 11) And we remember (or look up) that ak (mod m) ≡ (a mod m)k So 7222 = 710·22 + 2 = (710)22 · 72 ≡ 122 · 49 (mod 11) ≡ 5 (mod 11) Fermat’s Little Theorem
  • 26. 26 Fermat’s Little Theorem Example: Use Fermat’s Little Theorem to calculate 3302 (mod 5) Solution: First, note that FLT applies because p = 5 is prime and a = 3 is an integer not divisible by 5. Now FLT tells us that 34 ≡ 1 (mod 5), and we know that 302 = 4·75 + 2, and we remember (or look up) that ak (mod m) ≡ (a mod m)k So 3302 = 34·75 + 2 = (34)75 · 32 ≡ 175 · 9 (mod 5) ≡ 4 (mod 5)
  • 27. 27 FYOG: Calculate 52003 (mod 7), 52003 (mod 11), and 52003 (mod 13) Fermat’s Little Theorem
  • 28. One of the earliest known cryptographic ciphers was used by Julius Caesar. His strategy was to shift each letter of the alphabet forward 3 places, wrapping around when you get to the end. In this scheme, for example: A ↦ D, K ↦ N, Y ↦ B This is often called a Caesar Cipher or a Shift Cipher. ● Mathematically, we can accomplish this by assigning to each letter a number between 0 and 25. For example: A ↦ 0, K ↦ 10, Y ↦ 24 ● The encoding can be done by passing the value through a shift function modulo 26: f(p) = (p+3) mod 26 28 Cryptography warm-up
  • 29. In general, for a shift k we can use the function f(p) = (p+k) mod 26 We can encode a message by: 1. Convert letters to numbers between 0 and 25 2. Pass each value through f(p) ● Example: Encode HELLO WORLD using a shift=5 cipher 1. Convert to numbers: HELLO WORLD ↦ 7 4 11 11 14 22 14 17 11 3 2. Shift: 12 9 16 16 19 1 19 22 16 8 The encoded message is: MJQQT BTWQI 29 Cryptography warm-up
  • 30. ● How do we decode a message like MJQQT BTWQI ? ● If we know the shift, then it’s easy - just run the message through the inverse: f -1(p) = (p - k) mod 26 ● Why is this not a very secure cipher? 30 Cryptography warm-up
  • 31. The Affine Cipher ● Instead of only shifting, multiply and then shift f(p) = (ap + b) mod 26 where a and b are integers with gcd(a, 26) = 1 ● S’pose we know a and b (i.e., we have the key) - how could we decode a message? 31 Cryptography warm-up
  • 32. S’pose we know a and b (i.e., we have the key) - how could we decode a message? ● S’pose we have an encrypted character c that we know must satisfy c ≡ ap + b (mod 26) ● Then we need to solve this congruence for p. So subtract b from both sides c - b ≡ ap (mod 26) ● Now we need the inverse of a (modulo 26), which we know exists because gcd(a, 26) = 1. Call the inverse , and we have p ≡ (c - b) (mod 26) 32 Cryptography warm-up
  • 33. Example: Use an affine cipher with a=7 and b=13 to encrypt the letter K. Example: Find a decryption formula for this affine cipher and use it to decrypt the character F. 33 Cryptography warm-up
  • 34. Example: Use an affine cipher with a=7 and b=13 to encrypt the letter K. Solution: The numerical value for K is 10, so we have K ↦ a · 10 + b = 7·10 + 13 = 83 ≡ 5 (mod 26) ↦ F Example: Find a decryption formula for this affine cipher and use it to decrypt the character F. Solution: Recall from earlier that we had the formula: p ≡ (c - b) (mod 26) So we need the inverse of a = 7 (modulo 26) 34 Cryptography warm-up
  • 35. Example: Find a decryption formula for this affine cipher and use it to decrypt the character F. 35 Cryptography warm-up
  • 36. Example: Find a decryption formula for this affine cipher and use it to decrypt the character F. So we need the inverse of a = 7 (modulo 26): 26 = 3·7 + 5 7 = 1·5 + 2 5 = 2·2 + 1 … and in reverse … 1 = 5 - 2·2 = 5 - 2·(7-1·5) = 3·5 - 2·7 = 3·(26 - 3·7) - 2·7 = 3·26 - 11·7 So the inverse of 7 (modulo 26) is -11 36 Cryptography warm-up
  • 37. Example: Find a decryption formula for this affine cipher and use it to decrypt the character F. So the inverse of 7 (modulo 26) is -11 Plugging into the decryption formula we have: (with character F ↦ 5) p ≡ (c - b) (mod 26) ≡ -11 · (5 - 13) (mod 26) ≡ 88 (mod 26) (note: 26·3 = 78) ≡ 10 (mod 26) ↦ K 37 Cryptography warm-up
  • 38. Example: Find a decryption formula for this affine cipher and use it to decrypt the character F. So the inverse of 7 (modulo 26) is -11 Plugging into the decryption formula we have: (with character F ↦ 5) p ≡ (c - b) (mod 26) ≡ -11 · (5 - 13) (mod 26) ≡ 88 (mod 26) (note: 26·3 = 78) ≡ 10 (mod 26) ↦ K FYOG: Encrypt HELLO WORLD with an affine cipher with a=5 and b=17. Derive the decryption formula and check that your encrypted message decrypts back properly. 38 Cryptography warm-up
  • 39. Recap: ● Back substitution and Chinese Remainder Theorem provide two avenues to solve systems of congruences ● Fermat’s Little Theorem offers a nice way to calculate giant numbers quickly ● Affine and shift cyphers -- two relatively simple examples for encoding/decoding messages; based on shifting and multiplying your intended message Next time: ● Cryptography-Heavy and bringing it all this number theory together: RSA 39 Systems of congruences and Cryptography-Lite
  • 41. 41 FYOG: Use the Chinese Remainder Theorem (CRT) to find x such that x ≡ 1 (mod 5) x ≡ 2 (mod 6) x ≡ 3 (mod 7) Solution: CRT gives that the solution is x ≡ a1 M1 y1 + a2 M2 y2 + a3 M3 y3 (mod m) ⇒ a1 = 1, a2 = 2, and a3 = 3 are given in the problem ⇒ m = m1 ·m2 ·m3 = 5·6·7 = 210 ⇒ M1 = m/m1 = 210/5 = 42, M2 = m/m2 = 210/6 = 35, M3 = m/m3 = 210/7 = 30 So now we need the yk, which are the inverses of the Mk (mod mk ). FYOG: hints!
  • 42. 42 So now we need the yk, which are the inverses of the Mk (mod mk ). M1 y1 ≡ 1 (mod m1) ⇒ 42y1 ≡ 1 (mod 5) Euclidean Algorithm: 42 = 5·8 + 2 5 = 2·2 + 1 2 = 1·2 + 0 (gcd(5,42) = last nonzero remainder = 1, so they’re relatively prime and an inverse exists. good!) Reverse Euclidean Algorithm: 1 = 5 - 2·2 = 5 - 2·(42 - 8·5) = 5 - 2·42 + 16·5 = 17·5 - 2·42 ⇒ So an inverse of 42 (modulo 5) is -2 Similarly, the inverses of 35 (mod 6) is -1, and an inverse of 30 (mod 7) is -3. These are our yk FYOG: hints!
  • 43. 43 So putting everything together, we find: x ≡ a1 M1 y1 + a2 M2 y2 + a3 M3 y3 (mod m) ≡ 1·42·(-2) + 2·35·(-1) + 3·30·(-3) (mod 210) ≡ -84 - 70 - 270 (mod 210) ≡ -424 (mod 210) ← note that 210·(-2) = -420 ≡ -4 (mod 210) Check: -4 ≡ 1 (mod 5) ? -4 ≡ 2 (mod 6) ? -4 ≡ 3 (mod 7) ? FYOG: hints!
  • 44. 44 FYOG: Use Back Substitution to find x such that x ≡ 1 (mod 5) x ≡ 2 (mod 6) x ≡ 3 (mod 7) Solution: From the previous example using Chinese Remainder Theorem on this same system, you know the answer should be x ≡ -4 (mod 210). First congruence: x ≡ 1 (mod 5) ⇒ 5k = x-1 (some integer k) ⇒ x = 5k+1 + Second congruence: x = 5k + 1 ≡ 2 (mod 6) ⇒ 5k ≡ 1 (mod 6) ⇒ need an inverse of 5 (mod 6)? ⇒ -1 works (because 5·(-1) = -5 = -1·6 + 1) ⇒ So (-1)·5k ≡ (-1)·1 (mod 6) ⇒ k ≡ -1 (mod 6) ⇒ 6m = k+1 (some integer m), which means k = 6m - 1 FYOG: hints!
  • 45. 45 ⇒ x = 5k + 1 = 5(6m - 1) + 1 = 30m -5 + 1 = 30m - 4 + Third congruence: x = 30m - 4 ≡ 3 (mod 7) ⇒ 30m ≡ 7 (mod 7) ≡ 0 (mod 7) ⇒ m ≡ 0 (mod 7) ⇒ 7n = m (some integer n) ⇒ x = 30(7n) - 4 = 210n - 4 ← this line is saying that if you divide x by 210, then the remainder is -4, so... ⇒ x ≡ -4 (mod 210) FYOG: hints!
  • 46. 46 FYOG: Calculate 52003 (mod 7), 52003 (mod 11), and 52003 (mod 13) Solution: 52003 (mod 7) = ? p=7 is prime, and 7 does not divide a=5, so Fermat’s Little Theorem applies. ⇒ 57-1 = 56 ≡ 1 (mod 7) And we know (probably by using a calculator) that 2003 = 6·333 + 5 ⇒ 52003 = (56)333 · 55 ≡ (1)333 · 55 (mod 7) ≡ 55 (mod 7) ≡ 3125 (mod 7) ≡ 3 (mod 7) Similarly… 52003 ≡ 4 (mod 11), and 52003 ≡ 8 (mod 13) FYOG: hints!