Chinese Remainder Theorem Dec 29 Picture from ………………………

Slides:



Advertisements
Similar presentations
The Euler Phi-Function Is Multiplicative (3/3)
Advertisements

1 Lect. 12: Number Theory. Contents Prime and Relative Prime Numbers Modular Arithmetic Fermat’s and Euler’s Theorem Extended Euclid’s Algorithm.
Mathematical Induction II Lecture 14: Nov
Copyright © Cengage Learning. All rights reserved. CHAPTER 5 SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION.
1 Section 2.4 The Integers and Division. 2 Number Theory Branch of mathematics that includes (among other things): –divisibility –greatest common divisor.
22C:19 Discrete Math Integers and Modular Arithmetic Fall 2010 Sukumar Ghosh.
Number Theory and Cryptography
Inverses and GCDs Supplementary Notes Prepared by Raymond Wong
Lecture 3.2: Public Key Cryptography II CS 436/636/736 Spring 2012 Nitesh Saxena.
Mathematics of Cryptography Part I: Modular Arithmetic, Congruence,
Matrix Algebra THE INVERSE OF A MATRIX © 2012 Pearson Education, Inc.
Great Theoretical Ideas in Computer Science.
CS555Spring 2012/Topic 61 Cryptography CS 555 Topic 6: Number Theory Basics.
Mathematics of Cryptography Part I: Modular Arithmetic, Congruence,
Great Theoretical Ideas in Computer Science.
Mathematics of Cryptography Part I: Modular Arithmetic
Module :MA3036NI Cryptography and Number Theory Lecture Week 7
Modular Arithmetic.
Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.
Chapter 4 Number Theory in Asia The Euclidean Algorithm The Chinese Remainder Theorem Linear Diophantine Equations Pell’s Equation in Brahmagupta Pell’s.
Prelude to Public-Key Cryptography Rocky K. C. Chang, February
Methods of Proof. This Lecture Now we have learnt the basics in logic. We are going to apply the logical rules in proving mathematical theorems. Direct.
Greatest Common Divisor
CompSci 102 Discrete Math for Computer Science
Methods of Proof Lecture 3: Sep 9. This Lecture Now we have learnt the basics in logic. We are going to apply the logical rules in proving mathematical.
Basic Number Theory Divisibility Let a,b be integers with a≠0. if there exists an integer k such that b=ka, we say a divides b which is denoted by a|b.
Copyright © Zeph Grunschlag, Basic Number Theory Zeph Grunschlag.
Section 2.2: Affine Ciphers; More Modular Arithmetic Shift ciphers use an additive key. To increase security, we can add a multiplicative parameter. –For.
1 Network and Computer Security (CS 475) Modular Arithmetic and the RSA Public Key Cryptosystem Jeremy R. Johnson.
Modular (Remainder) Arithmetic n = qk + r (for some k; r < k) eg 37 = (2)(17) + 3 Divisibility notation: 17 | n mod k = r 37 mod 17 = 3.
Network and Computer Security (CS 475) Modular Arithmetic
1 Section Congruences In short, a congruence relation is an equivalence relation on the carrier of an algebra such that the operations of the algebra.
Chinese Remainder Theorem. How many people What is x? Divided into 4s: remainder 3 x ≡ 3 (mod 4) Divided into 5s: remainder 4 x ≡ 4 (mod 5) Chinese Remainder.
Tuesday’s lecture: Today’s lecture: One-way permutations (OWPs)
Great Theoretical Ideas in Computer Science for Some.
Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS Fall 2005 Lecture 9Sept 27, 2005Carnegie.
Great Theoretical Ideas in Computer Science.
Great Theoretical Ideas In Computer Science COMPSCI 102 Fall 2010 Lecture 16October 27, 2010Duke University Modular Arithmetic and the RSA Cryptosystem.
Cryptography Lecture 14 Arpita Patra © Arpita Patra.
Divisibility and Modular Arithmetic
May 9, 2001Applied Symbolic Computation1 Applied Symbolic Computation (CS 680/480) Lecture 6: Multiplication, Interpolation, and the Chinese Remainder.
Methods of Proof Lecture 4: Sep 20 (chapter 3 of the book, except 3.5 and 3.8)
CS480 Cryptography and Information Security
Chapter 4 With Question/Answer Animations 1. Chapter Motivation Number theory is the part of mathematics devoted to the study of the integers and their.
Number Theory Lecture 1 Text book: Discrete Mathematics and its Applications, 7 th Edition.
Great Theoretical Ideas in Computer Science.
Fuw-Yi Yang1 Textbook: Introduction to Cryptography 2nd ed. By J.A. Buchmann Chap 1 Integers Department of Computer Science and Information Engineering,
Dr Nazir A. Zafar Advanced Algorithms Analysis and Design Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar.
Modular Arithmetic and the RSA Cryptosystem
Fermat’s Little Theorem
B504/I538: Introduction to Cryptography
Advanced Algorithms Analysis and Design
Advanced Algorithms Analysis and Design
Lecture 3.2: Public Key Cryptography II
MATH301- DISCRETE MATHEMATICS Copyright © Nahid Sultana Dr. Nahid Sultana Chapter 4: Number Theory and Cryptography.
Number Theory and Modular Arithmetic
Chapter 4 Number Theory in Asia
Modular Arithmetic II Lecture 10: Oct 6.
Topic 6: Number Theory Basics
Applied Symbolic Computation (CS 300) Modular Arithmetic
Modular Arithmetic and the RSA Cryptosystem
Systems Architecture I
Applied Symbolic Computation (CS 300) Modular Arithmetic
Copyright © Zeph Grunschlag,
Applied Symbolic Computation (CS 300) Modular Arithmetic
Applied Symbolic Computation (CS 300) Modular Arithmetic
Modular Inverses Recall the simple encryption function
Applied Symbolic Computation (CS 300) Modular Arithmetic
Matrix Algebra THE INVERSE OF A MATRIX © 2012 Pearson Education, Inc.
Presentation transcript:

Chinese Remainder Theorem Dec 29 Picture from ………………………

This Lecture In this lecture we will study the Chinese remainder theorem, which is a method to solve equations about remainders. One equation Ancient application Two equations and three equations Chinese Remainder theorem

Case Study ax  b (mod n) How to solve the following equation? 2x  3 (mod 7)For example, consider the equation Suppose there is a solution x to the equation, then there is a solution x in the range from 0 to 6, because we can replace x by x mod 7. Then we can see that x=5 is a solution. Also, 5+7, 5+2·7, 5+3·7, …, 5-7, 5-2·7…, are solutions. Therefore the solutions are of the form 5+7k for some integer k.

One Equation ax  b (mod n) How to solve the following equation? 2x  3 (mod 7) 5x  6 (mod 9) 4x  -1 (mod 5) 4x  2 (mod 6) 10x  2 (mod 7) 3x  1 (mod 6) x = 5 + 7k for any integer k x = 3 + 9k for any integer k x = 1 + 5k for any integer k x = 2 + 3k for any integer k x = 3 + 7k for any integer k no solutions

One Equation: Relatively Prime Case 1: a and n are relatively prime ax  b (mod n) Without loss of generality, we can assume that 0 < a < n. Because we can replace a by a mod n without changing the equation. e.g. 103x  6 (mod 9) is equivalent to 4x  6 (mod 9). Since a and n are relatively prime, there exists a multiplicative inverse a’ for a. Hence we can multiply a’ on both sides of the equation to obtain x  a’b (mod n) Therefore, a solution always exists when a and n are relatively prime.

One Equation: Common Factor Case 2: a and n have a common factor c>=2. ax  b (mod n) Case 2a: c divides b. ax  b (mod n)  ax = b + nk for some integer k  a 1 cx = b 1 c + n 1 ck  a 1 x = b 1 + n 1 k  a 1 x  b 1 (mod n 1 ) In Case (2a) we can simplify the equation, and solve the new equation instead. we assume c|a and c|n and also c|b.

One Equation: Common Factor Case 2: a and n have a common factor c>=2. ax  b (mod n) Case 2b: c does not divides b. ax  b (mod n)  ax = b + nk for some integer k  a 1 cx = b + n 1 ck  a 1 x = b/c + n 1 k This is a contradiction, since a 1 x and n 1 k are integers, but b/c is not an integer since c does not divide b. Therefore, in Case 2b, there is no solution.

One Equation Theorem. Let a, b, n be given integers. The above equation has a solution if and only if gcd(a,n) | b. Furthermore, if the condition gcd(a,n) | b is satisfied, then the solutions are of the form y mod (n/gcd(a,n)) for some integer y. ax  b (mod n) Proof. First, divide b by gcd(a,n). If not divisible, then there is no solution by Case (2b). If divisible, then we simplify the solution as in Case (2a). Then we proceed as in Case (1) to compute the solution.

One Equation: Exercise 87x  3 (mod 15) no solutions Replace 87 by 87 mod 15 12x  3 (mod 15)Divide both sides by gcd(12,15) = 3 4x  1 (mod 5) Compute the multiplicative inverse of 4 modulo 5 x  4 + 5k 114x  5 (mod 22) Replace 114 by 114 mod 22 4x  5 (mod 22)Divide both sides by gcd(4,22) = 2 Because 2 does not divide 5. Important: to be familiar with the extended Euclidean algorithm to compute gcd and to compute multiplicative inverse.

Example: n = 123, k= = 3· so 12 = n - 3k 37 = 3· so 1 = 37 – 3·12 = k – 3(n-3k) = 10k - 3n 12 = 12·1 + 0 done, gcd=1 Computing Multiplicative Inverse So 1 = 10k-3n. Then we know that 10 is the multiplicative inverse of 37 under modulo 123.

This Lecture One equation Ancient application Two equations and three equations Chinese Remainder theorem

Ancient Application of Number Theory Starting from 1500 soldiers, after a war, about soldiers died. 韓信 Now we want to know how many soldiers are left. Form groups of 3 soldiers

Ancient Application of Number Theory ……………………… There are 2 soliders left. Form groups of 5 soldiers

Ancient Application of Number Theory ……………………… There are 3 soliders left. Form groups of 7 soldiers

Ancient Application of Number Theory ……………………… There are 2 soliders left. We have 1073 soliders. How could he figure it out?!

The Mathematical Question x  2 (mod 3) x  3 (mod 5) x  2 (mod 7) 1000 <= x <= x = 1073 How to solve this system of modular equations?

This Lecture One equation Ancient application Two equations and three equations Chinese Remainder theorem

Two Equations c 1 x  d 1 (mod m 1 ) c 2 x  d 2 (mod m 2 ) x  a 1 (mod n 1 ) x  a 2 (mod n 2 ) Find a solution to satisfy both equations simultaneously. First we can solve each equation to reduce to the following form. (Of course, if one equation has no solution, then there is no solution.) There may be no solutions simultaneously satisfying both equations. For example, consider x  1 (mod 3), x  2 (mod 3). x  1 (mod 6), x  2 (mod 4).

Two Equations x  2 (mod 3) x  4 (mod 7) Case 1: n 1 and n 2 are relatively prime. x = 2+3u and x = 4+7v for some integers u and v. 2+3u = 4+7v => 3u = 2+7v => 3u  2 (mod 7) 5 is the multiplicative inverse for 3 under modulo 7 Multiply 5 on both sides gives: 5·3u  5·2 (mod 7) => u  3 (mod 7) => u = 3 + 7w Therefore, x = 2+3u = 2+3(3+7w) = 11+21w So any x  11 (mod 21) is the solution. Where did we use the assumption that n 1 and n 2 are relatively prime?

Two Equations x  2 (mod 3) x  4 (mod 7) Assume n 1 and n 2 are relatively prime. The original idea is to construct such an x directly. Let x = 3·a + 7·b Note that when x is divided by 3, the remainder is decided by the second term. And when x is divided by 7, the remainder is decided by the first term. More precisely, x mod 7 = (3·a + 7·b) mod 7 = 3a mod 7 Similarly, x mod 3 = (3·a + 7·b) mod 3 = 7b mod 3 Therefore, to satisfy the equations, we just need to find a such that 3a mod 7 = 4 and b such that 7b mod 3 = 2.

Two Equations x  2 (mod 3) x  4 (mod 7) Assume n 1 and n 2 are relatively prime. The original idea is to construct such an x directly. Let x = 3·a + 7·b Since 3 and 7 are relatively prime, both the equations can be solved. The first equation is 3a  4 (mod 7), and the answer is a=6. Similarly, the second equation is 7b  2 (mod 3), and the answer is b=2. So one answer is x = 3a+7b = 3(6)+7(2) = 32. Therefore, to satisfy the equations, we just need to find a such that 3a mod 7 = 4 and b such that 7b mod 3 = 2.

Two Equations x  2 (mod 3) x  4 (mod 7) Assume n 1 and n 2 are relatively prime. The original idea is to construct such an x directly. Let x = 3·a + 7·b So one answer is x = 3a+7b = 3(6)+7(2) = 32. Note that ·7·k is also a solution to satisfy both equations. The only solutions are of the form k for some integer k. Are there other solutions?

Three Equations Let x = 5 · 7 ·a + 3 · 7 ·b + 3 · 5 · c x  2 (mod 3) x  3 (mod 5) x  2 (mod 7) So the first (second, third) term is responsible for the first (second, third) equation. More precisely, x mod 3 = (5·7·a + 3·7·b + 3·5·c) mod 3 = 5·7·a mod 3 x mod 5 = (5·7·a + 3·7·b + 3·5·c) mod 5 = 3·7·b mod 5 x mod 7 = (5·7·a + 3·7·b + 3·5·c) mod 7 = 3·5·c mod 7 Therefore, to satisfy the equations, we want to find a,b,c to satisfy the following: x mod 3 = 35a mod 3 = 2 x mod 5 = 21b mod 5 = 3 x mod 7 = 15c mod 7 = 2

Three Equations Let x = 5 · 7 ·a + 3 · 7 ·b + 3 · 5 · c x  2 (mod 3) x  3 (mod 5) x  2 (mod 7) So the first (second, third) term is responsible for the first (second, third) equation. Now we just need to solve the following three equations separately. 35a  2 (mod 3), 21b  3 (mod 5), 15c  2 (mod 7). This is equal to 2a  2 (mod 3),b  3 (mod 5),c  2 (mod 7) Therefore, we can set a = 1, b = 3, c = 2. Then x = 35a+21b+15c = 35(1)+21(3)+15(2) = 128. Note that 128+3·5·7·k = k is also a solution. Since 韓信 knows that 1000 <= x <= 1100, he concludes that x = Wait, but how does he know that there is no other solution?

This Lecture One equation Ancient application Two equations and three equations Chinese Remainder theorem

Chinese Remainder Theorem x  a 1 (mod n 1 ) x  a 2 (mod n 2 ) x  a k (mod n k ) Theorem: If n 1,n 2,…,n k are relatively prime and a 1,a 2,…,a k are integers, then have a simultaneous solution x that is unique modulo n, where n = n 1 n 2 …n k. We will give a proof when k=3, but it can be extended easily to any k.

Proof of Chinese Remainder Theorem N 1 = n 2 n 3 N 1 x 1  1 (mod n 1 ) Let x = a 1 N 1 x 1 + a 2 N 2 x 2 + a 3 N 3 x 3 x  a 1 (mod n 1 ) Let N 2 = n 1 n 3 N 3 = n 1 n 2 Since N i and n i are relatively prime, this implies that there exist x 1 x 2 x 3 N 2 x 2  1 (mod n 2 )N 3 x 3  1 (mod n 3 ) So, a 1 N 1 x 1  a 1 (mod n 1 ),a 2 N 2 x 2  a 2 (mod n 2 ),a 3 N 3 x 3  a 3 (mod n 3 ) x  a 1 N 1 x 1 (mod n 1 ) Since n 1 |N 2 and n 1 |N 3, Since N 1 x 1  1 (mod n 1 ), Similarly, x  a 2 (mod n 2 ) x  a 3 (mod n 3 )

Uniqueness x  a 1 (mod n 1 ) x  a 2 (mod n 2 ) x  a k (mod n k ) Suppose there are two solutions, x and y, to the above system. Then x – y  0 (mod n i ) for any i. This means that n i | x – y for any i. Since n 1,n 2,…,n k are relatively prime, this means that n 1 n 2 …n k | x – y. (why?) Therefore, x = y (mod n 1 n 2 …n k ). So there is a unique solution in every n 1 n 2 …n k numbers.

General Systems What if n1,n2,…,nk are not relatively prime? x  3 (mod 10) x  8 (mod 15) x  5 (mod 84) x  3 (mod 2)  1 (mod 2) x  8 (mod 3)  2 (mod 3) x  8 (mod 5)  3 (mod 5) x  5 (mod 4)  1 (mod 4) x  5 (mod 3)  2 (mod 3) x  5 (mod 7) x  3 (mod 5) (a) (b) (c) (d) (e) (f) (g) (b) and (d) are the same. (c) and (f) are the same. (e) is stronger than (a). So we reduce the problem to the relatively prime case. The answer is 173 (mod 420).

Quick Summary First we talk about how to solve one equation ax  b (mod n). The equation has solutions if and only if gcd(a,n) divides b. Then we talk about how to find simultaneous solutions to two equations a 1 x  b 1 (mod n 1 ) and a 2 x  b 2 (mod n 2 ). First use the technique in one equation to reduce to the form x  c 1 (mod n 1 ) and x  c 2 (mod n 2 ). By setting x = k 1 n 1 + k 2 n 2, then we just need to find k 1 and k 2 so that c 2  k 1 n 1 (mod n 2 ) and c 1  k 2 n 2 (mod n 1 ). These equations can be solved separately by using techniques for one equation. The same techniques apply for more than two equations. And the solution is unique mod n 1 n 2 …n k if there are k equations. Finally, when n 1 n 2 …n k are not relatively prime, we show how to reduce it back to the relatively prime case.

A Faster Method x  3 (mod 10) x  8 (mod 15) x  5 (mod 84) There is another method to solve the system of modular equations. From the third equation we know that x = 5+84u. Plug it into the second equation gives 5+84u  8 (mod 15) => 84u  3 (mod 15). Solving this would give us u  2 (mod 5) => u = 2 + 5v. Therefore x = 5+84u = 5+84(2+5v) = v. Plug it into the first equation gives v  3 (mod 10) => 420v = -170 (mod 10). This equation is always true. So we can conclude that x = v, or equivalently x  173 (mod 420). This method can also be used to prove the Chinese Remainder Theorem. It is much faster (no need to find factorization), requiring only k-1 Euclidean algorithm.