Modular Arithmetic

Total Page:16

File Type:pdf, Size:1020Kb

Modular Arithmetic Modular Arithmetic Adithya B., Brian L., William W., Daniel X. 9/2 §1 Chinese Remainder Theorem Oftentimes, we need to handle congruences modulo composite numbers, e.g. modulo 6, or modulo 210, etc. The Chinese Remainder Theorem is a useful tool that allows us to transfer from multiple congruences to a single congruence: Theorem 1.1 (Chinese Remainder Theorem) Let a1; a2; : : : ; an be pairwise coprime positive integers (that is, no two of these numbers share a common factor greater than one), and b1; b2; : : : ; bn be any integers. Then the system of n congruences x ≡ b1 (mod a1); x ≡ b2 (mod a2); ··· ; x ≡ bn (mod an) is equivalent to the congruence x ≡ k (mod a1a2 ··· an) for some integer k. That is, x satisfies all n congruences above if and only if x ≡ k (mod a1a2 ··· an). Note that this is an existence theorem: it does not tell us how to find k. For example, the theorem tells us that x ≡ 1 (mod 2); x ≡ 2 (mod 3); x ≡ 3 (mod 5); is equivalent to x ≡ k (mod 30) for some integer k, but it does not tell us what k is. (We can manually find that k = 23.) The Chinese Remainder Theorem is especially powerful because it allows us to collate multiple congruences into a single congruence without having to actually solve the system of congruences. This will be essential for the problems below. Example 1.2 (2012 AIME II #12) For a positive integer p, define the positive integer n to be p-safe if n differs in absolute value by more than 2 from all multiples of p. For example, the set of 10-safe numbers is f3; 4; 5; 6; 7; 13; 14; 15; 16; 17; 23;:::g. Find the number of positive integers less than or equal to 10; 000 which are simultaneously 7-safe, 11-safe, and 13-safe. 1 Adithya B., Brian L., William W., Daniel X. (9/2) Modular Arithmetic Solution. The p-safe condition translates nicely into modular arithmetic. In order for n to be 7-safe, it has to be more than two away from any multiple of 7. This means it has to be congruent to 3 or 4 modulo 7. Conversely, if n is congruent to 3 or 4 modulo 7 then it is more than 2 away from the nearest multiple of 7. Similarly, n is 11-safe if and only if it is congruent to 3; 4; 5; 6; 7, or 8 modulo 11, and n is 13-safe if and only if it is congruent to 3; 4; 5; 6; 7; 8; 9, or 10 modulo 13. For n to be simultaneously 7-safe, 11-safe, and 13-safe, all of the following congruences must be satisfied: • n ≡ 3; 4 (mod 7); • n ≡ 3; 4; 5; 6; 7; 8 (mod 11); • n ≡ 3; 4; 5; 6; 7; 8; 9; 10 (mod 13): Moreover, 7, 11, and 13 are pairwise relatively prime (they are all prime), so we can use the Chinese Remainder Theorem to splice together these conditions. For example, the congruences • n ≡ 4 (mod 7); • n ≡ 8 (mod 11); • n ≡ 3 (mod 13): have a unique solution modulo 7 · 11 · 13 = 1001. To find all possible solutions modulo 1001, we need to pick a residue modulo 7, a residue modulo 11, and a residue modulo 13; each such choice results in exactly one residue modulo 1001. With our list above, we find that this can be done in 2 · 6 · 8 = 96 ways. So there are 96 residues modulo 1001 that are 7-safe, 11-safe, and 13-safe. We now want to find the number of positive integers at most 10; 000 that work. From our work above, we see that: • There are 96 working integers in f1; 2;:::; 1001g, • There are 96 working integers in f1002; 1003;:::; 2002g, • ..., • There are 96 working integers in f9010; 9011;:::; 10010g. So there are 960 working integers from 1 to 10010, inclusive. We just need to examine the integers 10001;:::; 10010 and subtract any overcounts to find the final answer. Note that 10010 is a multiple of 7, 11, and 13. The next smallest multiples of 7, 11, and 13 are 10003, 9999, and 9997, respectively. From this, we see that the only working integers from 10001 to 10010 are 10006 and 10007. So we have two overcounts, and the number of positive integers less than or equal to 10; 000 which are 7-safe, 11-safe, and 13-safe is 960 − 2 = 958 . 2 Adithya B., Brian L., William W., Daniel X. (9/2) Modular Arithmetic Example 1.3 (2011 AIME II #14) There are N permutations (a1; a2; : : : ; a30) of 1; 2;:::; 30 such that for m 2 f2; 3; 5g, m divides an+m − an for all integers n with 1 ≤ n < n + m ≤ 30. Find the remainder when N is divided by 1000. Solution. We're given three different values of m to use; let's investigate them separately. For m = 2, the condition implies that a1 ≡ a3 ≡ · · · ≡ a29; a2 ≡ a4 ≡ · · · ≡ a30 (mod 2) Since the ai need to be a permutation of (1; 2;:::; 30), with 15 odd numbers and 15 even numbers, this implies that a1; a3; : : : ; a29 are all of the opposite parity as a2; a4; : : : ; a30. Thus we can choose that either a1; a3; : : : ; a29 are all even, or a1; a3; : : : ; a29 are all odd. There are 2 ways to do this. Let's take a look modulo 3. The condition gives us a1 ≡ a4 ≡ · · · ≡ a28; a2 ≡ a5 ≡ · · · ≡ a29; a3 ≡ a6 ≡ · · · ≡ a30 (mod 3): Again, since the ai are a permutation of (1; 2;:::; 30), 10 of them congruent are to each of 0; 1, and 2 modulo 3. So we can choose what a1; a4; : : : ; a28 are modulo 3, then pick a different residue for a2; a5; : : : ; a29, and use the last residue for a3; a6; : : : ; a30. We have 3! = 6 ways to do this. Finally, for m = 5 we can use the same logic. We get a1 ≡ a6 ≡ · · · ≡ a26; a2 ≡ a7 ≡ · · · ≡ a27; : : : ; a5 ≡ a10 ≡ · · · ≡ a30 (mod 5): We can choose the residues of a1; a6; : : : ; a26 modulo 5, then pick a different residue for a2; a7; : : : ; a27, and so on up to a5; a10; : : : ; a30. There ae 5! = 120 ways to assign residues modulo 5. We have now chosen a residue for each ai modulo 2; 3, and 5; by the Chinese Remainder Theorem this results in a unique residue modulo 30, and hence a unique element of f1; 2;:::; 30g. So our choices uniquely define the sequence (a1; a2; : : : ; a30): We're not done yet; we need to check if this sequence is a permutation. That is, we need to check that no two elements are equal. What happens if ai = aj? This means that ai ≡ aj (mod 2), so that i ≡ j (mod 2). We see this because a1 ≡ a3 ≡ · · · ≡ a29 6≡ a2 ≡ a4 ≡ · · · ≡ a30 (mod 2): Similarly, ai ≡ aj (mod 3), so i ≡ j (mod 3), and since ai ≡ aj (mod 5) we have i ≡ j (mod 5). By the Chinese Remainder Theorem, we have i ≡ j (mod 30). But i and j are between 1 and 30, so this forces i = j. Hence we conclude that our sequence is a permutation; no two terms are equal. We had 2! ways to set the residues modulo 2, 3! ways to set the residues modulo 3, and 5! ways to set the residues modulo 5, so the total number of ways is 2! · 3! · 5! = 2 · 6 · 120 = 1440 and the answer is 440 : 3 Adithya B., Brian L., William W., Daniel X. (9/2) Modular Arithmetic §2 Euler's Totient Theorem Euler's Totient Theorem is probably the most important theorem for dealing with exponents in modular arithmetic. Using it, one can compute the residue of large powers of numbers modulo a fixed n without having to resort to techniques such as \looking for patterns." To understand it, first we must know what the totient function is. Definition 2.1. The totient of n, denoted φ(n), is the number of positive integers less than or equal to n which are relatively prime to it. We won't go over it's proof in this class, but the totient is easily computable via the closed form 1 1 1 φ(n) = n 1 − 1 − ··· 1 − p1 p2 pk where p1; p2; : : : ; pk are the primes dividing n, listed without repetition. The proof can be done using Chinese Remainder Theorem on mods p1; : : : ; pk and is left as an exercise to the reader. Theorem 2.2 (Euler's Totient Theorem) Given an integer n > 1 and a natural a relatively prime to n, we have aφ(n) ≡ 1 (mod n) Proof. Denote S the set of residues modn which are coprime with n. By definition, jSj = φ(n). Now, consider the set T = fas (mod n)js 2 Sg, which is the set of the residues multiplied by a. As a is coprime with n, all elements of T are coprime with n as well. Furthermore, no two elements in T are the same, since as ≡ as0 (mod n) =) s ≡ s0 (mod n). So, T is a set of numbers coprime to n with magnitude jT j = jSj = φ(n). Hence, T = S. Of course, as they are the same set, the product of all the elements should be the same too. Hence, Y Y Y Y Y s ≡ t (mod n) =) s ≡ as ≡ aφ(n) s (mod n) s2S t2T s2S s2S s2S =) aφ(n) ≡ 1 (mod n) as desired.
Recommended publications
  • Modular Arithmetic
    CS 70 Discrete Mathematics and Probability Theory Fall 2009 Satish Rao, David Tse Note 5 Modular Arithmetic One way to think of modular arithmetic is that it limits numbers to a predefined range f0;1;:::;N ¡ 1g, and wraps around whenever you try to leave this range — like the hand of a clock (where N = 12) or the days of the week (where N = 7). Example: Calculating the day of the week. Suppose that you have mapped the sequence of days of the week (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday) to the sequence of numbers (0;1;2;3;4;5;6) so that Sunday is 0, Monday is 1, etc. Suppose that today is Thursday (=4), and you want to calculate what day of the week will be 10 days from now. Intuitively, the answer is the remainder of 4 + 10 = 14 when divided by 7, that is, 0 —Sunday. In fact, it makes little sense to add a number like 10 in this context, you should probably find its remainder modulo 7, namely 3, and then add this to 4, to find 7, which is 0. What if we want to continue this in 10 day jumps? After 5 such jumps, we would have day 4 + 3 ¢ 5 = 19; which gives 5 modulo 7 (Friday). This example shows that in certain circumstances it makes sense to do arithmetic within the confines of a particular number (7 in this example), that is, to do arithmetic by always finding the remainder of each number modulo 7, say, and repeating this for the results, and so on.
    [Show full text]
  • 8.6 Modular Arithmetic
    “mcs” — 2015/5/18 — 1:43 — page 263 — #271 8.6 Modular Arithmetic On the first page of his masterpiece on number theory, Disquisitiones Arithmeticae, Gauss introduced the notion of “congruence.” Now, Gauss is another guy who managed to cough up a half-decent idea every now and then, so let’s take a look at this one. Gauss said that a is congruent to b modulo n iff n .a b/. This is j written a b.mod n/: ⌘ For example: 29 15 .mod 7/ because 7 .29 15/: ⌘ j It’s not useful to allow a modulus n 1, and so we will assume from now on that moduli are greater than 1. There is a close connection between congruences and remainders: Lemma 8.6.1 (Remainder). a b.mod n/ iff rem.a; n/ rem.b; n/: ⌘ D Proof. By the Division Theorem 8.1.4, there exist unique pairs of integers q1;r1 and q2;r2 such that: a q1n r1 D C b q2n r2; D C “mcs” — 2015/5/18 — 1:43 — page 264 — #272 264 Chapter 8 Number Theory where r1;r2 Œ0::n/. Subtracting the second equation from the first gives: 2 a b .q1 q2/n .r1 r2/; D C where r1 r2 is in the interval . n; n/. Now a b.mod n/ if and only if n ⌘ divides the left side of this equation. This is true if and only if n divides the right side, which holds if and only if r1 r2 is a multiple of n.
    [Show full text]
  • 1. Modular Arithmetic
    Modular arithmetic Divisibility Given p ositive numb ers a b if a we can write b aq r 1 for appropriate integers q r such that r a The numb er r is the remainder We say that a divides b or ajb if r and so b aq ie b factors as a times q Primes A numb er is prime if it cant b e factored as a pro duct of two numb ers greater or equal to If a numb er factors ie it is not prime then we say that it is comp osite Exercise Find all prime numb ers smaller than Here are several imp ortant questions How do we determine whether a numb er is prime How do we factor a numb er into primes How can we nd big prime numb ers How many prime numb ers are there Exercise Factor Exercise Show that every numb er is either prime or divisible by a prime numb er Theorem There are innitely many prime numbers Proof Supp ose that there are only nitely many prime numb ers P P 1 n then N P P P is not divisible by any prime hence it do es 1 2 n factor and hence it is a new prime not ˜ Divisibility tricks Recall that a numb er is even if its last digit is divisible by it is divisible by if the sum of its digits is divisible by it is divisible by if its last digit is divisible by etc Why is this Can we nd other divisibility tricks eg for One p ossible explanation Let abc b e a digit numb er so that abc a b c Then abc a b c and this is an integer only if c is an integer abc a b c and this is an integer only if c is an integer abc a b a b c and this is an integer only if a b c is an integer
    [Show full text]
  • Chinese Remainder Theorem
    THE CHINESE REMAINDER THEOREM KEITH CONRAD We should thank the Chinese for their wonderful remainder theorem. Glenn Stevens 1. Introduction The Chinese remainder theorem says we can uniquely solve every pair of congruences having relatively prime moduli. Theorem 1.1. Let m and n be relatively prime positive integers. For all integers a and b, the pair of congruences x ≡ a mod m; x ≡ b mod n has a solution, and this solution is uniquely determined modulo mn. What is important here is that m and n are relatively prime. There are no constraints at all on a and b. Example 1.2. The congruences x ≡ 6 mod 9 and x ≡ 4 mod 11 hold when x = 15, and more generally when x ≡ 15 mod 99, and they do not hold for other x. The modulus 99 is 9 · 11. We will prove the Chinese remainder theorem, including a version for more than two moduli, and see some ways it is applied to study congruences. 2. A proof of the Chinese remainder theorem Proof. First we show there is always a solution. Then we will show it is unique modulo mn. Existence of Solution. To show that the simultaneous congruences x ≡ a mod m; x ≡ b mod n have a common solution in Z, we give two proofs. First proof: Write the first congruence as an equation in Z, say x = a + my for some y 2 Z. Then the second congruence is the same as a + my ≡ b mod n: Subtracting a from both sides, we need to solve for y in (2.1) my ≡ b − a mod n: Since (m; n) = 1, we know m mod n is invertible.
    [Show full text]
  • Number Theory
    Number Theory Margaret M. Fleck 31 January 2011 These notes cover concepts from elementary number theory. 1 Number Theory We’ve now covered most of the basic techniques for writing proofs. So we’re going to start applying them to specific topics in mathematics, starting with number theory. Number theory is a branch of mathematics concerned with the behavior of integers. It has very important applications in cryptography and in the design of randomized algorithms. Randomization has become an increasingly important technique for creating very fast algorithms for storing and retriev- ing objects (e.g. hash tables), testing whether two objects are the same (e.g. MP3’s), and the like. Much of the underlying theory depends on facts about which numbers evenly divide one another and which numbers are prime. 2 Factors and multiples You’ve undoubtedly seen some of the basic ideas (e.g. divisibility) somewhat informally in earlier math classes. However, you may not be fully clear on what happens with special cases, e.g. zero, negative numbers. We also need clear formal definitions in order to write formal proofs. So, let’s start with 1 Definition: Suppose that a and b are integers. Then a divides b if b = an for some integer n. a is called a factor or divisor of b. b is called a multiple of a. The shorthand for a divides b is a | b. Be careful about the order. The divisor is on the left and the multiple is on the right. Some examples: • 7 | 77 • 77 6| 7 • 7 | 7 because 7 = 7 · 1 • 7 | 0 because 0 = 7 · 0, zero is divisible by any integer.
    [Show full text]
  • IV.5 Arithmetic Geometry Jordan S
    i 372 IV. Branches of Mathematics where the aj,i1,...,in are indeterminates. If we write with many nice pictures and reproductions. A Scrap- g1f1 + ··· + gmfm as a polynomial in the variables book of Complex Curve Theory (American Mathemat- x1,...,xn, then all the coefficients must vanish, save ical Society, Providence, RI, 2003), by C. H. Clemens, the constant term which must equal 1. Thus we get and Complex Algebraic Curves (Cambridge University a system of linear equations in the indeterminates Press, Cambridge, 1992), by F. Kirwan, also start at an easily accessible level, but then delve more quickly into aj,i1,...,in . The solvability of systems of linear equations is well-known (with good computer implementations). advanced subjects. Thus we can decide if there is a solution with deg gj The best introduction to the techniques of algebraic 100. Of course it is possible that 100 was too small geometry is Undergraduate Algebraic Geometry (Cam- a guess, and we may have to repeat the process with bridge University Press, Cambridge, 1988), by M. Reid. larger and larger degree bounds. Will this ever end? For those wishing for a general overview, An Invitation The answer is given by the following result, which was to Algebraic Geometry (Springer, New York, 2000), by proved only recently. K. E. Smith, L. Kahanpää, P. Kekäläinen, and W. Traves, is a good choice, while Algebraic Geometry (Springer, New Effective Nullstellensatz. Let f1,...,fm be polyno- York, 1995), by J. Harris, and Basic Algebraic Geometry, mials of degree less than or equal to d in n variables, volumes I and II (Springer, New York, 1994), by I.
    [Show full text]
  • Congruences and Modular Arithmetic
    UI Math Contest Training Modular Arithmetic Fall 2019 Congruences and Modular Arithmetic • Congruences: We say a is congruent to b modulo m, and write a ≡ b mod m , if a and b have the same remainder when divided by m, or equivalently if a − b is divisible by m. Equivalently, the congruence notation a ≡ b mod m can be thought of as a shorthand notation for the statement \there exists an integer k such that a = b + km." Here are some examples to illustrate this notation: (1) 5 ≡ 17 mod 3 (since 5 and 17 both have remainder 2 when divided by 3, or equivalently, since 17 − 5 = 12 is divisible by 3). (2) 10 ≡ −4 mod 7 (since 10 − (−4) = 14 is divisible by 7) (3) 2013 ≡ 0 mod 3 (since 2013 − 0 = 2013 is divisible by 3) (4) n ≡ 0 mod 2 if n is even, and n ≡ 1 mod 2 if n is odd. (5) n ≡ d mod 10 if n has d as last decimal digit (since then n = d + 10k for some integer k, and hence n ≡ d mod 10) • Modular arithmetic: The key fact about congruences is that congruences to the same modu- lus can be added, multiplied, and taken to a fixed positive integral power. For example, since 6 ≡ −1 mod 7, we have 61000 ≡ (−1)1000 = 1 mod 7. This type of manipulation is called modular arithmetic or congruence magic, and it allows one to quickly calculate remainders and last digits of numbers with thousands of digits. • Congruence magic: An example. Consider the problem of finding the last digit of 20132014 (which is a number with thousands of decimal digits).
    [Show full text]
  • Large Numbers, the Chinese Remainder Theorem, and the Circle of Fifths Version of January 27, 2001
    Large Numbers, the Chinese Remainder Theorem, and the Circle of Fifths version of January 27, 2001 S. A. FULLING Texas A&M University College Station, TX 77843-3368 [email protected] 1. The problem. Consider a recurrence relation such as 2 an+1 = an +(n+3)nan ;a0=1; whose solutions are integers that grow rapidly with n. (This is a cooked-up example. For a realistic problem of this nature, look at [2], especially the formula at the end, and contemplate calculating Y40 ; or look at equation (3.65) of [9], whre the last coefficient is a fraction whose denominator has 80 decimal digits.) Suppose that: (1) We do not know how to solve the recurrence in closed form, so we want to use a computer to grind out the values of a for, say, n 20: n ≤ a1 =1;a2=5;a3=75;a4= 6975;a5= 48845925; :::: (2) We insist on knowing the answers exactly; floating-point numbers of a fixed precision are not adequate. The problem is that eventually the numbers will overflow the natural “word size” of the computer. If integers are represented by 16 bits, the largest signed integer is 215 1, the largest unsigned integer is 216 1. If “long” (32-bit) integers are used, we can get− up to 232 1 unsigned. − What− happens when an integer variable overflows depends on the programming lan- guage used. Some systems will give an error message and abort the program. In standard C, the storage of the number “rolls over” like a car’s odometer: the most significant dig- its are lost, without warning.
    [Show full text]
  • Modular Arithmetic
    Computational Number Theory Vidur Jasuja November 2020 1 So what is a mod anyway? 1.1 Some Notes • Note: unless stated otherwise, all variables stated will be assumed to be integers. • If a is divisible by b, we say that b divides a, denoted as b j a: 1.2 Defining Congruence Definition (Congruence (mod n)) We say two numbers a and b are congruent modulo n, where n is positive, or a ≡ b (mod n), if any one of the equivalent conditions listed here are met. • If n divides the difference of a and b, or in other words n divides a − b; • If there exists an integer k such that a + kn = b; • Or if a and b leave the same remainder upon division by n: Can you explain why these conditions are equivalent? §1.2.1 Simple Exercises 1. Find a number n such that n ≡ 2020 (mod 64): 2. Find a number n such that n ≡ −27 (mod 46): 3. Find a number 0 ≤ n < 57 such that n ≡ 982 (mod 57): What is another way to phrase this problem in more simple terms? 4. How many positive integers m are there such that 50 ≡ 2 (mod m)? 1.3 Properties of Mods Theorem (Addition works (mod n)) Suppose that a ≡ b (mod n); and c ≡ d (mod n): Then a + c ≡ b + d (mod n): Proof By our definitions of congruence, we have that b = a + nj for some integer j, and that d = c + nk for some integer k: Now, by our other equivalent definition of congruence, we want to show that n j b + d − a − c; or that 1 Computational Number Theory Vidur Jasuja n = c+nk +a+nj −c−a = nk +nj = n(k +j): Clearly, n divides n(k +j), which is an integer multiple of n, so we have shown what we wanted to show.
    [Show full text]
  • Finite Fields (PART 2): Modular Arithmetic
    Lecture 5: Finite Fields (PART 2) PART 2: Modular Arithmetic Theoretical Underpinnings of Modern Cryptography Lecture Notes on “Computer and Network Security” by Avi Kak ([email protected]) February 2, 2021 5:20pm ©2021 Avinash Kak, Purdue University Goals: To review modular arithmetic To present Euclid’s GCD algorithms To present the prime finite field Zp To show how Euclid’s GCD algorithm can be extended to find multiplica- tive inverses Perl and Python implementations for calculating GCD and mul- tiplicative inverses CONTENTS Section Title Page 5.1 Modular Arithmetic Notation 3 5.1.1 Examples of Congruences 5 5.2 Modular Arithmetic Operations 6 5.3 The Set Zn and Its Properties 9 5.3.1 So What is Zn? 11 5.3.2 Asymmetries Between Modulo Addition and Modulo 13 Multiplication Over Zn 5.4 Euclid’s Method for Finding the Greatest Common Divisor 16 of Two Integers 5.4.1 Steps in a Recursive Invocation of Euclid’s GCD Algorithm 18 5.4.2 An Example of Euclid’s GCD Algorithm in Action 19 5.4.3 Proof of Euclid’s GCD Algorithm 21 5.4.4 Implementing the GCD Algorithm in Perl and Python 22 5.5 Prime Finite Fields 29 5.5.1 What Happened to the Main Reason for Why Zn Could Not 31 be an Integral Domain 5.6 Finding Multiplicative Inverses for the Elements of Zp 32 5.6.1 Proof of Bezout’s Identity 34 5.6.2 Finding Multiplicative Inverses Using Bezout’s Identity 37 5.6.3 Revisiting Euclid’s Algorithm for the Calculation of GCD 39 5.6.4 What Conclusions Can We Draw From the Remainders? 42 5.6.5 Rewriting GCD Recursion in the Form of Derivations for 43 the Remainders 5.6.6 Two Examples That Illustrate the Extended Euclid’s Algorithm 45 5.7 The Extended Euclid’s Algorithm in Perl and Python 47 5.8 Homework Problems 54 Computer and Network Security by Avi Kak Lecture 5 Back to TOC 5.1 MODULAR ARITHMETIC NOTATION Given any integer a and a positive integer n, and given a division of a by n that leaves the remainder between 0 and n − 1, both inclusive, we define a mod n to be the remainder.
    [Show full text]
  • 1 Modular Arithmetic: ZN and Z
    CS 127/CSCI E-127: Introduction to Cryptography Prof. Salil Vadhan Fall 2013 Lecture Notes 8: Computational Number Theory Reading. • KatzLindell 2nd edition 8.0,8.1,8.2.3,8.3.0-8.3.2 OR 1st edition 7.0,7.1,7.2.3,7.3.0-7.3.2 Computational Number theory is a major source of hard problems (eg one-way functions) for cryptography. 1 Modular arithmetic: and ∗ ZN ZN Basic denitions: • x ≡ y (mod N) if Nj(x − y). (Written x = y mod N in KatzLindell.) • [x mod N] def= unique x0 2 f0;:::;N − 1g s.t. x ≡ x0 (mod N). def • ZN = f0;:::;N − 1g with arithmetic (+,·) modulo N. We cannot divide in general: 5 · 8 ≡ 5 · 1 (mod 35). Fact 1 (Extended Euclidean Algorithm) For any x; y 2 N there exists two integers a, b such that ax + by = gcd(x; y). Moreover, such a and b can be found in polynomial time. Denition of ∗ ZN ∗ def elements of with multiplicative inverses ZN = fx 2 ZN : gcd(x; N) = 1g = ZN −1 By a multiplicative inverse for x we mean an element y 2 ZN , denoted y = x , such that . Given and ∗ , we can compute −1 in polynomial time: x · y ≡ 1 (mod N) N x 2 ZN x Example: In ∗ , −1 . Z35 3 = ::: Euler phi function def ∗ φ(N) = jZN j Example: ∗ • Z35 = • φ(35) = 1 Q: how to generate random elements of ∗ ? ZN Fact 2 Y 1 N φ(N) = N · 1 − ≥ p 6loglogN primes pjN 2 Groups • An abelian group G is a set G with binary operation ? satisfying associativity, identity, inverses, and commutativity.
    [Show full text]
  • Chinese Remainder Theorem RSA Cryptosystem
    math 55 - induction and modular arithmetic Feb. 21 Chinese Remainder Theorem + The Chinese Remainder Theorem (CRT) says that given a1; : : : ; an 2 Z, m1; : : : ; mn 2 Z , where the mi are pairwise relatively prime, then the system of congruences: x ≡ a1 mod m1 x ≡ a2 mod m2 . x ≡ an mod mn has a unique solution modulo m = m1m2 ··· mn. We find this solution as follows. Let m Mk = . Then (since the mi are pairwise relatively prime) there are inverses yk such that mk Mkyk ≡ 1 mod mk. Then a1M1y1 + ··· + anMnyn mod m is the solution. 1. Compute the solution to the following system of congruences: x ≡ 1 mod 3 x ≡ 3 mod 5 x ≡ 5 mod 7 2. Check that the following system of congruences has no solutions. (In general, there may or may not be solutions when the mi are not pairwise relatively coprime.) x ≡ 1 mod 2 x ≡ 3 mod 4 x ≡ 5 mod 8 RSA cryptosystem The RSA cryptosystem is designed to encode information using number theory. The algo- rithm is as follows. 1. Choose two prime numbers p and q, and an integer e such that gcd(e; (p−1)(q−1)) = 1. (In general, larger p and q are more secure.) 2. Translate a given message into a sequence of integers by A = 00;B = 01;:::;Z = 25, and then group these integers into blocks of 4. 3. Encrypt each block M by replacing it with M e mod n. 4. To decrypt, compute an inverse d of e mod (p − 1)(q − 1). for each block C, compute Cd ≡ M de ≡ M mod n to get back the original message.
    [Show full text]