Practical assessment week 5 and 6

Size: px
Start display at page:

Download "Practical assessment week 5 and 6"

Transcription

1 Practical assessment week 5 and 6 Finding prime numbers 1.1 Modular Arithmetic Basically, a b (mod n) if a = b + kn for some integer k. If a is non-negative and b is between 0 and n, you can think of b as the remainder of a when divided by n. Sometimes, b is called the residue of a, modulo n. Sometimes a is called congruent to b, modulo n (the triple equals sign,, denotes congruence). These are just different ways of saying the same thing. The set of integers from 0 to n - 1 form what is called a complete set of residues modulo n. This means that, for every integer a, its residue modulo n is some number from 0 to n - 1. The operation a mod n denotes the residue of a, such that the residue is some integer from 0 to n - 1. This operation is modular reduction. For example, 5 mod 3 = 2. In C, the % operator returns the remainder from the division of the first expression by the second; this can be a negative number if either operand is negative. Make sure you add n to the result of the modulo operator if it returns a negative number. Modular arithmetic is just like normal arithmetic: It s commutative, associative, and distributive. Also, reducing each intermediate result modulo n yields the same result as doing the whole calculation and then reducing the end result modulo n. a + b) mod n = ((a mod n) + (b mod n)) mod n (a - b) mod n = ((a mod n) - (b mod n)) mod n (a*b) mod n = ((a mod n)*(b mod n)) mod n (a*(b + c)) mod n = (((a*b) mod n) + ((a*c) mod n)) mod n Cryptography uses computation mod n a lot, because calculating discrete logarithms and square roots mod n can be hard problems. Modular arithmetic is also easier to work with on computers, because it restricts the range of all intermediate values and the result. For a k- bit modulus, n, the intermediate results of any addition, subtraction, or multiplication will not be more than 2k- bits long. So we can perform exponentiation in modular arithmetic without generating huge intermediate results. Calculating the power of some number modulo some number, a x mod n, is just a series of multiplications and divisions, but there are speedups. One kind of speedup aims to minimize the number of modular multiplications; another kind aims to optimize the individual modular multiplications. Because the operations are distributive, it is faster to do the exponentiation as a stream of successive multiplications, taking the modulus every time. It doesn t make much difference now, but it will when you re working with 200-bit numbers. For example, if you want to calculate a 8 mod n, don t use the naïve approach and perform seven multiplications and one huge modular reduction: (a*a*a*a*a*a*a*a) mod n Instead, perform three smaller multiplications and three smaller modular reductions: ((a 2 mod n) 2 mod n)2 mod n By the same token, a 16 mod n = (((a 2 mod n) 2 mod n) 2 mod n) 2 mod n A pseudo code is presented as follows Computing a k mod n IN: a integer si k n wher by k i we understand i-th bit from k (t number of the bits from k) OUT: a k mod n

2 b=1 if(!k)return(b); temp=a; if(k 0 )b=a; for(i=1;i++;i<t) { temp=temp 2 mod n if(k i )b=temp*bmod n return(b); Computing gcd(a,b) IN: a,b unsigned integer a b OUT: gcd(a,b) while(b) { temp=a mod b; a=b; b=temp return (a) Job 1. Implement the method to compute a k mod n and gcd 1.2 Chinese Remainder Theorem According to D. Wells, the following problem was posed by Sun Tsu Suan-Ching (4th century AD): There are certain things whose number is unknown. Repeatedly divided by 3, the remainder is 2; by 5 the remainder is 3; and by 7 the remainder is 2. What will be the number? Oystein Ore mentions another puzzle with a dramatic element from Brahma-Sphuta-Siddhanta (Brahma's Correct System) by Brahmagupta (born 598 AD): An old woman goes to market and a horse steps on her basket and crashes the eggs. The rider offers to pay for the damages and asks her how many eggs she had brought. She does not remember the exact number, but when she had taken them out two at a time, there was one egg left. The same happened when she picked them out three, four, five, and six at a time, but when she took them seven at a time they came out even. What is the smallest number of eggs she could have had? Problems of this kind are all examples of what universally became known as the Chinese Remainder Theorem. In mathematical parlance the problems can be stated as finding n, given its remainders of division by several numbers m 1, m 2,..., m k : n = n 1 (mod m 1 ) n = n (1) 2 (mod m 2 )... n = n k (mod m k ) The modern day theorem is best stated with a couple of useful notations. For non-negative integers m 1, m 2,..., m k, their greatest common divisor is defined as

3 gcd(m 1, m 2,..., m k ) = max{s: s m i, for i = 1,..., k, where, as always, "s m" means that s divides m exactly. The least common multiple of k numbers is defined as lcm(m 1, m 2,..., m k ) = min{s: s > 0 and m i s, for i = 1,..., k, Both gcd() and lcm() are symmetric functions of their arguments. They are complementary in the sense that, for k = 2, gcd(m 1, m 2 ) lcm(m 1, m 2 ) = m 1 m 2. However, for k > 2 a similar identity does not in general hold. For an example, consider two triplets: {2, 4, 16 and {2, 8, 16. Both have exactly the same gcd and lcm but obviously different products. On the other hand, both gcd and lcm are associative: gcd(m 1, (gcd(m 2, m 3 )) = gcd(gcd(m 1, m 2 ), m 3 ) and, both equal gcd(m 1, m 2, m 3 ). Similarly, lcm(m 1, (lcm(m 2, m 3 )) = lcm(lcm(m 1, m 2 ), m 3 ) Note If, for a prime p, p α i m i, with α i being the largest exponent with that property, then p α lcm(m 1, m 2,..., m k ), where α = max{α i and α is the largest exponent with that property. Similarly, the greatest common divisor of several numbers is the product of the largest powers of the primes that divide all the given numbers. Associativity allows one to proceed a step at a time with an inductive argument without putting all eggs into a basket at once. Jumping at the opportunity I'll prove the most basic case of k = 2. Theorem 1 Two simultaneous congruences n = n 1 (mod m 1 ) and n = n 2 (mod m 2 ) are only solvable when n 1 = n 2 (mod gcd(m 1, m 2 )). The solution is unique modulo lcm(m 1, m 2 ). (When m 1 and m 2 are coprime their gcd is 1. By convention, a = b (mod 1) holds for any a and b.) Proof By a generalization of the Euclid's algorithm, there are integers s and t such that tm 1 + sm 2 = gcd(m 1, m 2 ). Since n 2 - n 1 = 0 (mod gcd(m 1, m 2 )), for some, possibly different t and s, (2) tm 1 + sm 2 = n 2 - n 1. Then n = tm 1 + n 1 = -sm 2 + n 2 satisfies both congruences in the theorem. This proves the existence of a solution. To prove the uniqueness part, assume n and N satisfy the two congruences. Taking the differences we see that N - n = 0 (mod m 1 ) and N - n = 0 (mod m 2 ) which implies N - n = 0 (mod lcm(m 1, m 2 )). As was previously stated, a more general theorem can now be proved by induction. Theorem 2 The simultaneous congruences n = n 1 (mod m 1 ) n = n 2 (mod m 2 )... n = n k (mod m k )

4 are only solvable when n i = n j (mod gcd(m i, m j )), for all i and j, i j. The solution is unique modulo lcm(m 1, m 2,..., m k ). Proof Theorem 1 serves the initial step verification. Assume the theorem holds for k congruences and consider k + 1 of them. n = n 1 (mod m 1 ) n = n 2 (mod m 2 )... n = n k (mod m k ) n = n k+1 (mod m k+1 ) Let s be a solution to the first k equations. Then the congrurence n = s (mod lcm(m 1, m 2,..., m k )) has a solution. (Observe that every solution of the latter also satisfies the first k congruences.) To be able to apply the already proven Theorem 1, we need to show that (3) s = n k+1 (mod gcd(lcm(m 1,..., m k ), m k+1 )). Let's write g u = gcd(m u, m k+1 ), u = 1,..., k. Then we know that n u = n k+1 (mod g u) for these values of u. But n u = s + t um u, for some t u, implying n k+1 = s + t um u (mod g u) so that s = n k+1 (mod g u), u = 1, 2,..., k. If so, s = n k+1 (mod lcm(g 1,..., g k )) = n k+1 (mod lcm(gcd(m 1, m k+1 ),..., gcd(m k, m k+1 ))). = n k+1 (mod gcd(lcm(m 1,..., m k ), m k+1 )) because lcm(gcd(m 1, m k+1 ),..., gcd(m k, m k+1 )) = gcd(lcm(m 1,..., m k ), m k+1 ). Thus the system n = s (mod lcm(m 1, m 2,..., m k )) n = n k+1 (mod m k+1 ) has a solution which is unique modulo lcm(lcm(m 1, m 2,..., m k ), m k+1 ) = lcm(m 1, m 2,..., m k, m k+1 ). It also satisfies the whole set of k + 1 congruences. Corollary The simultaneous congruences n = n 1 (mod m 1 ) n = n 2 (mod m 2 )... n = n k (mod m k ) where all m i 's are pairwise coprime has a unique solution modulo m 1 m 2... m k. If some m i 's are not mutually prime, a solution may not exist unless the corresponding congruence agree. For example, the system n = 1 (mod 2) and n = 2 (mod 4) has not solution, while the system n = 1 (mod 2) and n = ±1 (mod 4) does. Another approach in Computing CR A method (3) that can compute the smallest solution N 0 directly, it is easy to carry out both by human and by computer. Firstly we solve a * x + r 1 = b * y + r 2, it can be rewritten as ax = by + r. Notice that if x 0,y 0 is a solution of ax = by + 1, then x = bn + rx 0,y = an + ry 0 is a solution of ax = by + r for any integer n. Because a(bn+rx 0 ) = b(an+ry 0 )+r

5 => abn + arx 0 = ban + bry 0 + r => ax 0 = by So the problem come down to solve ax = by + 1. If a > b, we can solve (a-b)x = by' + 1, y' = y - x first, say the solution is x,y', then y = y'+x. Similarly this can be done if a < b. Repeat the procedure, a and b become smaller and smaller. When a = 1, we can let y = 1 and x = b + 1, else if b = 1 we can let x = 1 and y = a - 1. Since x = bn + rx 0,y = an + ry 0 we can let x 1 = rx 0 mod b and y 1 = ry 0 mod a. x 1,y 1 will be the smallest numbers fulfil a * x + r 1 = b * y + r 2. Let r 4 = ax 1 + r 1 = by 1 + r 2, we can see that solutions are of the form abu + r 4. Then we solve abu + r 4 = cz + r 3 and get u 1,z 1. Finally N 0 = abu 1 + r 4 = cz 1 + r 3. For example, we solve N = 3x+2 = 5y+3 = 7z+2 again. Firstly solve 3x=5y+1 => 3(x-y)=2y+1 => x-y=2(y-(x-y))+1 => x 0 -y 0 =3,2y 0 -x 0 =1 => x 0 =7,y 0 =4 => r 4 =3*7+2=23 Then we solve 15u+23=7z+2 => 7z=15u+21 (here r=21, we are ready to know ru 0 mod 7 = 0), 7z=15u+1 => 7(z-u)=8u+1 => 7(z-2u)=u+1 => u 0 =6,z 0 =13 => u 1 = 21*6 mod 7 = 0 => N 0 =15*0+23=23. Job 2. Implement Chinese reminder computing 1.3 Fermat Primality Test Fermat's Little Theorem According to Fermat's Little Theorem if p is a prime number and a is a positive integer less than p, then a p = a ( mod p ) or alternatively: a (p-1) = 1 ( mod p ) Algorithm of the test If p is the number which we want to test for primality, then we could randomly choose a, such that a < p and then calculate (a (p-1) )%p. If the result is not 1, then by Fermat's Little Theorem p cannot be prime. What if that is not the case? We can choose another a and then do the same test again. We could stop after some number of iterations and if the result is always 1 in each of them, then we can state with very high probability that p is prime. The more iterations we do, the higher is the probability that our result is correct. You can notice that if the method returns composite, then the number is sure to be composite, otherwise it will be probably prime. Given below is a simple function implementing Fermat's primality test: /* Fermat's test for checking primality, the more iterations the more is accuracy */ bool Fermat(long long p,int iterations){ if(p == 1){ // 1 isn't prime return false;

6 for(int i=0;i<iterations;i++){ // choose a random integer between 1 and p-1 ( inclusive ) long long a = rand()%(p-1)+1; // modulo is the function we developed above for modular exponentiation. if(modulo(a,p-1,p)!= 1){ return false; /* p is definitely composite */ return true; /* p is probably prime */ More iterations of the function will result in higher accuracy, but will take more time. You can choose the number of iterations depending upon the application. Though Fermat is highly accurate in practice there are certain composite numbers p known as Carmichael numbers for which all values of a<p for which gcd(a,p)=1, (a (p-1) )%p = 1. If we apply Fermat's test on a Carmichael number the probability of choosing an a such that gcd(a,p)!= 1 is very low ( based on the nature of Carmichael numbers ), and in that case, the Fermat's test will return a wrong result with very high probability. Although Carmichael numbers are very rare ( there are about 250,000 of them less than ), but that by no way means that the result you get is always correct. Someone could easily challenge you if you were to use Fermat's test :). Out of the Carmichael numbers less than 10 16, about 95% of them are divisible by primes < This suggests that apart from applying Fermat's test, you may also test the number for divisibility with small prime numbers and this will further reduce the probability of failing. However, there are other improved primality tests which don't have this flaw as Fermat's. We will discuss some of them now. Job 3. Implement Fermat Primality Test computing 1.4 Miller-Rabin Primality Test 1. Fermat's Little Theorem. 2. If p is prime and x 2 = 1 ( mod p ), then x = +1 or -1 ( mod p ). We could prove this as follows: 3. x 2 = 1 ( mod p ) 4. x 2-1 = 0 ( mod p ) 5. (x-1)(x+1) = 0 ( mod p ) Now if p does not divide both (x-1) and (x+1) and it divides their product, then it cannot be a prime, which is a contradiction. Hence, p will either divide (x-1) or it will divide (x+1), so x = +1 or -1 ( mod p ). Let us assume that p - 1 = 2 d * s where s is odd and d >= 0. If p is prime, then either a s = 1 ( mod p ) as in this case, repeated squaring from a s will always yield 1, so (a (p-1) )%p will be 1; or a (s*(2r)) = -1 ( mod p ) for some r such that 0 <= r < d, as repeated squaring from it will always yield 1 and finally a (p-1) = 1 ( mod p ). If none of these hold true, a (p-1) will not be 1 for any prime number a ( otherwise there will be a contradiction with fact #2 ).

7 Algorithm Let p be the given number which we have to test for primality. First we rewrite p-1 as (2 d )*s. Now we pick some a in range [1,n-1] and then check whether a s = 1 ( mod p ) or a (s*(2r)) = -1 ( mod p ). If both of them fail, then p is definitely composite. Otherwise p is probably prime. We can choose another a and repeat the same test. We can stop after some fixed number of iterations and claim that either p is definitely composite, or it is probably prime. A small procedure realizing the above algorithm is given below: /* Miller-Rabin primality test, iteration signifies the accuracy of the test */ bool Miller(long long p,int iteration){ if(p<2){ return false; if(p!=2 && p%2==0){ return false; long long s=p-1; while(s%2==0){ s/=2; for(int i=0;i<iteration;i++){ long long a=rand()%(p-1)+1,temp=s; long long mod=modulo(a,temp,p); while(temp!=p-1 && mod!=1 && mod!=p-1){ mod=mulmod(mod,mod,p); temp *= 2; if(mod!=p-1 && temp%2==0){ return false; return true; It can be shown that for any composite number p, at least (3/4) of the numbers less than p will witness p to be composite when chosen as 'a' in the above test. Which means that if we do 1 iteration, probability that a composite number is returned as prime is (1/4). With k iterations the probability of test failing is (1/4) k or 4 (-k). This test is comparatively slower compared to Fermat's test but it doesn't break down for any specific composite numbers and iterations is a quite good choice for most applications. Job 4. Implement Miller-Rabin Primality Test computing 1.5 Solovay-Strassen Primality Test 1. Legendre Symbol: This symbol is defined for a pair of integers a and p such that p is prime. It is denoted by (a/p) and calculated as: 2. (a/p) = 0 if a%p = 0

8 3. (a/p) = 1 if there exists an integer k such that k 2 = a ( mod p ) (a/p)= -1 otherwise. It is proved by Euler that: (a/p) = (a ((p-1)/2)) % p So we can also say that: (ab/p) = (ab ((p-1)/2)) % p = (a ((p-1)/2)) %p * (b ((p-1)/2)) %p = (a/p)*(b/p) 4. Jacobian Symbol: This symbol is a generalization of Legendre Symbol as it does not require 'p' to be prime. Let a and n be two positive integers, and n = p1 k1 *.. * pn kn, then Jacobian symbol is defined as: 5. (a/n) = ((a/p1) k1 ) * ((a/p2) k2 ) *... * ((a/pn) kn ) So you can see that if n is prime, the Jacobian symbol and Legendre symbol are equal. There are some properties of these symbols which we can exploit to quickly calculate them: 1. (a/n) = 0 if gcd(a,n)!= 1, Hence (0/n) = 0. This is because if gcd(a,n)!= 1, then there must be some prime pi such that pi divides both a and n. In that case (a/pi) = 0 [ by definition of Legendre Symbol ]. 2. (ab/n) = (a/n) * (b/n). It can be easily derived from the fact (ab/p) = (a/p)(b/p) ( here (a/p) is the Legendry Symbol ). 3. if a is even, than (a/n) = (2/n)*((a/2)/n). It can be shown that: 4. = 1 if n = 1 ( mod 8 ) or n = 7 ( mod 8 ) 5. (2/n) = -1 if n = 3 ( mod 8 ) or n = 5 ( mod 8 ) = 0 otherwise 6. (a/n) = (n/a)*(-1 ((a-1)(n-1)/4)) if a and n are both odd. The algorithm for the test is really simple. We can pick up a random a and compute (a/n). If n is a prime then (a/n) should be equal to (a ((n-1)/2)) %n [ as proved by Euler ]. If they are not equal then n is composite, and we can stop. Otherwise we can choose more random values for a and repeat the test. We can declare n to be probably prime after some iterations. Note that we are not interested in calculating Jacobi Symbol (a/n) if n is an even integer because we can trivially see that n isn't prime, except 2 of course. Let us write a little code to compute Jacobian Symbol (a/n) and for the test: //calculates Jacobian(a/n) n>0 and n is odd int calculatejacobian(long long a,long long n){ if(!a) return 0; // (0/n) = 0 int ans=1; long long temp; if(a<0){ a=-a; // (a/n) = (-a/n)*(-1/n) if(n%4==3) ans=-ans; // (-1/n) = -1 if n = 3 ( mod 4 ) if(a==1) return ans; // (1/n) = 1 while(a){ if(a<0){ a=-a; // (a/n) = (-a/n)*(-1/n) if(n%4==3) ans=-ans; // (-1/n) = -1 if n = 3 ( mod 4 )

9 while(a%2==0){ a=a/2; // Property (iii) if(n%8==3 n%8==5) ans=-ans; swap(a,n); // Property (iv) if(a%4==3 && n%4==3) ans=-ans; // Property (iv) a=a%n; // because (a/p) = (a%p / p ) and a%pi = (a%n)%pi if n % pi = 0 if(a>n/2) a=a-n; if(n==1) return ans; return 0; /* Iterations determine the accuracy of the test */ bool Solovoy(long long p,int iteration){ if(p<2) return false; if(p!=2 && p%2==0) return false; for(int i=0;i<iteration;i++){ long long a=rand()%(p-1)+1; long long jacobian=(p+calculatejacobian(a,p))%p; long long mod=modulo(a,(p-1)/2,p); if(!jacobian mod!=jacobian){ return false; return true; It is shown that for any composite n, at least half of the a will result in n being declared as composite according to Solovay-Strassen test. This shows that the probability of getting a wrong result after k iterations is (1/2) k. However, it is generally less preferred than Rabin-Miller test in practice because it gives poorer performance. The various routines provided in the article can be highly optimized just by using bitwise operators instead of them. For example /= 2 can be replaced by ">>= 1", "%2" can be replaced by "&1" and "*= 2" can be replaced by "<<=1". Inline Assembly can also be used to optimize them further. Job 5. Implement Solovay-Strassen Primality Test computing Homework: Make the following comparation test between Miller-Rabin Primality and Solovay-Strassen Primality Test for 1000 numbers, numbers and numbers and create a graphic with required times. The used compiler, executable/interpreted, the language, if the hardware parallelism wre used and the targhet machine must be presented too

10 References 1. Bruce Schneier Applied Cryptography, Second Edition: Protocols, Algorthms, and Source Code in C Publisher: John Wiley & Sons, Inc., ISBN: , Douglas Stinson, Cryptography: Theory and Practice, CRC Press, CRC Press LLC ISBN: ,

Discrete Mathematics and Probability Theory Fall 2014 Anant Sahai Homework 5. This homework is due October 6, 2014, at 12:00 noon.

Discrete Mathematics and Probability Theory Fall 2014 Anant Sahai Homework 5. This homework is due October 6, 2014, at 12:00 noon. EECS 70 Discrete Mathematics and Probability Theory Fall 2014 Anant Sahai Homework 5 This homework is due October 6, 2014, at 12:00 noon. 1. Modular Arithmetic Lab (continue) Oystein Ore described a puzzle

More information

Mathematics of Cryptography

Mathematics of Cryptography Modulo arithmetic Fermat's Little Theorem If p is prime and 0 < a < p, then a p 1 = 1 mod p Ex: 3 (5 1) = 81 = 1 mod 5 36 (29 1) = 37711171281396032013366321198900157303750656 = 1 mod 29 (see http://gauss.ececs.uc.edu/courses/c472/java/fermat/fermat.html)

More information

Arithmetic and Algebra

Arithmetic and Algebra Arithmetic and Algebra Daniel Butnaru daniel.butnaru@uni-konstanz.de 15. Dezember 2006 Daniel Butnaru daniel.butnaru@uni-konstanz.de Arithmetic and Algebra 1/39 Outline 1 Introduction 2 Big Number Arithmetic

More information

2 Arithmetic. 2.1 Greatest common divisors. This chapter is about properties of the integers Z = {..., 2, 1, 0, 1, 2,...}.

2 Arithmetic. 2.1 Greatest common divisors. This chapter is about properties of the integers Z = {..., 2, 1, 0, 1, 2,...}. 2 Arithmetic This chapter is about properties of the integers Z = {..., 2, 1, 0, 1, 2,...}. (See [Houston, Chapters 27 & 28]) 2.1 Greatest common divisors Definition 2.16. If a, b are integers, we say

More information

Lecture 5: Arithmetic Modulo m, Primes and Greatest Common Divisors Lecturer: Lale Özkahya

Lecture 5: Arithmetic Modulo m, Primes and Greatest Common Divisors Lecturer: Lale Özkahya BBM 205 Discrete Mathematics Hacettepe University http://web.cs.hacettepe.edu.tr/ bbm205 Lecture 5: Arithmetic Modulo m, Primes and Greatest Common Divisors Lecturer: Lale Özkahya Resources: Kenneth Rosen,

More information

Lecture notes: Algorithms for integers, polynomials (Thorsten Theobald)

Lecture notes: Algorithms for integers, polynomials (Thorsten Theobald) Lecture notes: Algorithms for integers, polynomials (Thorsten Theobald) 1 Euclid s Algorithm Euclid s Algorithm for computing the greatest common divisor belongs to the oldest known computing procedures

More information

LARGE PRIME NUMBERS (32, 42; 4) (32, 24; 2) (32, 20; 1) ( 105, 20; 0).

LARGE PRIME NUMBERS (32, 42; 4) (32, 24; 2) (32, 20; 1) ( 105, 20; 0). LARGE PRIME NUMBERS 1. Fast Modular Exponentiation Given positive integers a, e, and n, the following algorithm quickly computes the reduced power a e % n. (Here x % n denotes the element of {0,, n 1}

More information

1 Recommended Reading 1. 2 Public Key/Private Key Cryptography Overview RSA Algorithm... 2

1 Recommended Reading 1. 2 Public Key/Private Key Cryptography Overview RSA Algorithm... 2 Contents 1 Recommended Reading 1 2 Public Key/Private Key Cryptography 1 2.1 Overview............................................. 1 2.2 RSA Algorithm.......................................... 2 3 A Number

More information

Numbers. Çetin Kaya Koç Winter / 18

Numbers. Çetin Kaya Koç   Winter / 18 Çetin Kaya Koç http://koclab.cs.ucsb.edu Winter 2016 1 / 18 Number Systems and Sets We represent the set of integers as Z = {..., 3, 2, 1,0,1,2,3,...} We denote the set of positive integers modulo n as

More information

Applied Cryptography and Computer Security CSE 664 Spring 2018

Applied Cryptography and Computer Security CSE 664 Spring 2018 Applied Cryptography and Computer Security Lecture 12: Introduction to Number Theory II Department of Computer Science and Engineering University at Buffalo 1 Lecture Outline This time we ll finish the

More information

Outline. Some Review: Divisors. Common Divisors. Primes and Factors. b divides a (or b is a divisor of a) if a = mb for some m

Outline. Some Review: Divisors. Common Divisors. Primes and Factors. b divides a (or b is a divisor of a) if a = mb for some m Outline GCD and Euclid s Algorithm AIT 682: Network and Systems Security Topic 5.1 Basic Number Theory -- Foundation of Public Key Cryptography Modulo Arithmetic Modular Exponentiation Discrete Logarithms

More information

Outline. AIT 682: Network and Systems Security. GCD and Euclid s Algorithm Modulo Arithmetic Modular Exponentiation Discrete Logarithms

Outline. AIT 682: Network and Systems Security. GCD and Euclid s Algorithm Modulo Arithmetic Modular Exponentiation Discrete Logarithms AIT 682: Network and Systems Security Topic 5.1 Basic Number Theory -- Foundation of Public Key Cryptography Instructor: Dr. Kun Sun Outline GCD and Euclid s Algorithm Modulo Arithmetic Modular Exponentiation

More information

CIS 6930/4930 Computer and Network Security. Topic 5.1 Basic Number Theory -- Foundation of Public Key Cryptography

CIS 6930/4930 Computer and Network Security. Topic 5.1 Basic Number Theory -- Foundation of Public Key Cryptography CIS 6930/4930 Computer and Network Security Topic 5.1 Basic Number Theory -- Foundation of Public Key Cryptography 1 Review of Modular Arithmetic 2 Remainders and Congruency For any integer a and any positive

More information

Number Theory Proof Portfolio

Number Theory Proof Portfolio Number Theory Proof Portfolio Jordan Rock May 12, 2015 This portfolio is a collection of Number Theory proofs and problems done by Jordan Rock in the Spring of 2014. The problems are organized first by

More information

ECEN 5022 Cryptography

ECEN 5022 Cryptography Elementary Algebra and Number Theory University of Colorado Spring 2008 Divisibility, Primes Definition. N denotes the set {1, 2, 3,...} of natural numbers and Z denotes the set of integers {..., 2, 1,

More information

1 Overview and revision

1 Overview and revision MTH6128 Number Theory Notes 1 Spring 2018 1 Overview and revision In this section we will meet some of the concerns of Number Theory, and have a brief revision of some of the relevant material from Introduction

More information

CSC 474 Network Security. Outline. GCD and Euclid s Algorithm. GCD and Euclid s Algorithm Modulo Arithmetic Modular Exponentiation Discrete Logarithms

CSC 474 Network Security. Outline. GCD and Euclid s Algorithm. GCD and Euclid s Algorithm Modulo Arithmetic Modular Exponentiation Discrete Logarithms Computer Science CSC 474 Network Security Topic 5.1 Basic Number Theory -- Foundation of Public Key Cryptography CSC 474 Dr. Peng Ning 1 Outline GCD and Euclid s Algorithm Modulo Arithmetic Modular Exponentiation

More information

CHAPTER 6. Prime Numbers. Definition and Fundamental Results

CHAPTER 6. Prime Numbers. Definition and Fundamental Results CHAPTER 6 Prime Numbers Part VI of PJE. Definition and Fundamental Results 6.1. Definition. (PJE definition 23.1.1) An integer p is prime if p > 1 and the only positive divisors of p are 1 and p. If n

More information

THE MILLER RABIN TEST

THE MILLER RABIN TEST THE MILLER RABIN TEST KEITH CONRAD 1. Introduction The Miller Rabin test is the most widely used probabilistic primality test. For odd composite n > 1 at least 75% of numbers from to 1 to n 1 are witnesses

More information

CPSC 467b: Cryptography and Computer Security

CPSC 467b: Cryptography and Computer Security CPSC 467b: Cryptography and Computer Security Michael J. Fischer Lecture 8 February 1, 2012 CPSC 467b, Lecture 8 1/42 Number Theory Needed for RSA Z n : The integers mod n Modular arithmetic GCD Relatively

More information

p = This is small enough that its primality is easily verified by trial division. A candidate prime above 1000 p of the form p U + 1 is

p = This is small enough that its primality is easily verified by trial division. A candidate prime above 1000 p of the form p U + 1 is LARGE PRIME NUMBERS 1. Fermat Pseudoprimes Fermat s Little Theorem states that for any positive integer n, if n is prime then b n % n = b for b = 1,..., n 1. In the other direction, all we can say is that

More information

ECE596C: Handout #11

ECE596C: Handout #11 ECE596C: Handout #11 Public Key Cryptosystems Electrical and Computer Engineering, University of Arizona, Loukas Lazos Abstract In this lecture we introduce necessary mathematical background for studying

More information

Discrete Mathematics and Probability Theory Fall 2018 Alistair Sinclair and Yun Song Note 6

Discrete Mathematics and Probability Theory Fall 2018 Alistair Sinclair and Yun Song Note 6 CS 70 Discrete Mathematics and Probability Theory Fall 2018 Alistair Sinclair and Yun Song Note 6 1 Modular Arithmetic In several settings, such as error-correcting codes and cryptography, we sometimes

More information

Congruence Classes. Number Theory Essentials. Modular Arithmetic Systems

Congruence Classes. Number Theory Essentials. Modular Arithmetic Systems Cryptography Introduction to Number Theory 1 Preview Integers Prime Numbers Modular Arithmetic Totient Function Euler's Theorem Fermat's Little Theorem Euclid's Algorithm 2 Introduction to Number Theory

More information

This is a recursive algorithm. The procedure is guaranteed to terminate, since the second argument decreases each time.

This is a recursive algorithm. The procedure is guaranteed to terminate, since the second argument decreases each time. 8 Modular Arithmetic We introduce an operator mod. Let d be a positive integer. For c a nonnegative integer, the value c mod d is the remainder when c is divided by d. For example, c mod d = 0 if and only

More information

Factorization & Primality Testing

Factorization & Primality Testing Factorization & Primality Testing C etin Kaya Koc http://cs.ucsb.edu/~koc koc@cs.ucsb.edu Koc (http://cs.ucsb.edu/~ koc) ucsb ccs 130h explore crypto fall 2014 1/1 Primes Natural (counting) numbers: N

More information

IRREDUCIBILITY TESTS IN F p [T ]

IRREDUCIBILITY TESTS IN F p [T ] IRREDUCIBILITY TESTS IN F p [T ] KEITH CONRAD 1. Introduction Let F p = Z/(p) be a field of prime order. We will discuss a few methods of checking if a polynomial f(t ) F p [T ] is irreducible that are

More information

Outline. Number Theory and Modular Arithmetic. p-1. Definition: Modular equivalence a b [mod n] (a mod n) = (b mod n) n (a-b)

Outline. Number Theory and Modular Arithmetic. p-1. Definition: Modular equivalence a b [mod n] (a mod n) = (b mod n) n (a-b) Great Theoretical Ideas In CS Victor Adamchik CS - Lecture Carnegie Mellon University Outline Number Theory and Modular Arithmetic p- p Working modulo integer n Definitions of Z n, Z n Fundamental lemmas

More information

2.3 In modular arithmetic, all arithmetic operations are performed modulo some integer.

2.3 In modular arithmetic, all arithmetic operations are performed modulo some integer. CHAPTER 2 INTRODUCTION TO NUMBER THEORY ANSWERS TO QUESTIONS 2.1 A nonzero b is a divisor of a if a = mb for some m, where a, b, and m are integers. That is, b is a divisor of a if there is no remainder

More information

Topics in Cryptography. Lecture 5: Basic Number Theory

Topics in Cryptography. Lecture 5: Basic Number Theory Topics in Cryptography Lecture 5: Basic Number Theory Benny Pinkas page 1 1 Classical symmetric ciphers Alice and Bob share a private key k. System is secure as long as k is secret. Major problem: generating

More information

CPSC 467: Cryptography and Computer Security

CPSC 467: Cryptography and Computer Security CPSC 467: Cryptography and Computer Security Michael J. Fischer Lecture 9 September 30, 2015 CPSC 467, Lecture 9 1/47 Fast Exponentiation Algorithms Number Theory Needed for RSA Elementary Number Theory

More information

cse 311: foundations of computing Fall 2015 Lecture 12: Primes, GCD, applications

cse 311: foundations of computing Fall 2015 Lecture 12: Primes, GCD, applications cse 311: foundations of computing Fall 2015 Lecture 12: Primes, GCD, applications n-bit unsigned integer representation Represent integer x as sum of powers of 2: If x = n 1 i=0 b i 2 i where each b i

More information

ALGEBRA. 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers

ALGEBRA. 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers ALGEBRA CHRISTIAN REMLING 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers by Z = {..., 2, 1, 0, 1,...}. Given a, b Z, we write a b if b = ac for some

More information

An integer p is prime if p > 1 and p has exactly two positive divisors, 1 and p.

An integer p is prime if p > 1 and p has exactly two positive divisors, 1 and p. Chapter 6 Prime Numbers Part VI of PJE. Definition and Fundamental Results Definition. (PJE definition 23.1.1) An integer p is prime if p > 1 and p has exactly two positive divisors, 1 and p. If n > 1

More information

A Guide to Arithmetic

A Guide to Arithmetic A Guide to Arithmetic Robin Chapman August 5, 1994 These notes give a very brief resumé of my number theory course. Proofs and examples are omitted. Any suggestions for improvements will be gratefully

More information

3 The fundamentals: Algorithms, the integers, and matrices

3 The fundamentals: Algorithms, the integers, and matrices 3 The fundamentals: Algorithms, the integers, and matrices 3.4 The integers and division This section introduces the basics of number theory number theory is the part of mathematics involving integers

More information

CPSC 467b: Cryptography and Computer Security

CPSC 467b: Cryptography and Computer Security Outline Quadratic residues Useful tests Digital Signatures CPSC 467b: Cryptography and Computer Security Lecture 14 Michael J. Fischer Department of Computer Science Yale University March 1, 2010 Michael

More information

CIS 551 / TCOM 401 Computer and Network Security

CIS 551 / TCOM 401 Computer and Network Security CIS 551 / TCOM 401 Computer and Network Security Spring 2008 Lecture 15 3/20/08 CIS/TCOM 551 1 Announcements Project 3 available on the web. Get the handout in class today. Project 3 is due April 4th It

More information

Introduction to Information Security

Introduction to Information Security Introduction to Information Security Lecture 5: Number Theory 007. 6. Prof. Byoungcheon Lee sultan (at) joongbu. ac. kr Information and Communications University Contents 1. Number Theory Divisibility

More information

Public Key Encryption

Public Key Encryption Public Key Encryption 3/13/2012 Cryptography 1 Facts About Numbers Prime number p: p is an integer p 2 The only divisors of p are 1 and p s 2, 7, 19 are primes -3, 0, 1, 6 are not primes Prime decomposition

More information

The next sequence of lectures in on the topic of Arithmetic Algorithms. We shall build up to an understanding of the RSA public-key cryptosystem.

The next sequence of lectures in on the topic of Arithmetic Algorithms. We shall build up to an understanding of the RSA public-key cryptosystem. CS 70 Discrete Mathematics for CS Fall 2003 Wagner Lecture 10 The next sequence of lectures in on the topic of Arithmetic Algorithms. We shall build up to an understanding of the RSA public-key cryptosystem.

More information

Number Theory. CSS322: Security and Cryptography. Sirindhorn International Institute of Technology Thammasat University CSS322. Number Theory.

Number Theory. CSS322: Security and Cryptography. Sirindhorn International Institute of Technology Thammasat University CSS322. Number Theory. CSS322: Security and Cryptography Sirindhorn International Institute of Technology Thammasat University Prepared by Steven Gordon on 29 December 2011 CSS322Y11S2L06, Steve/Courses/2011/S2/CSS322/Lectures/number.tex,

More information

NUMBER SYSTEMS. Number theory is the study of the integers. We denote the set of integers by Z:

NUMBER SYSTEMS. Number theory is the study of the integers. We denote the set of integers by Z: NUMBER SYSTEMS Number theory is the study of the integers. We denote the set of integers by Z: Z = {..., 3, 2, 1, 0, 1, 2, 3,... }. The integers have two operations defined on them, addition and multiplication,

More information

Introduction to Cryptography. Lecture 6

Introduction to Cryptography. Lecture 6 Introduction to Cryptography Lecture 6 Benny Pinkas page 1 Public Key Encryption page 2 Classical symmetric ciphers Alice and Bob share a private key k. System is secure as long as k is secret. Major problem:

More information

CHAPTER 3. Congruences. Congruence: definitions and properties

CHAPTER 3. Congruences. Congruence: definitions and properties CHAPTER 3 Congruences Part V of PJE Congruence: definitions and properties Definition. (PJE definition 19.1.1) Let m > 0 be an integer. Integers a and b are congruent modulo m if m divides a b. We write

More information

4 Number Theory and Cryptography

4 Number Theory and Cryptography 4 Number Theory and Cryptography 4.1 Divisibility and Modular Arithmetic This section introduces the basics of number theory number theory is the part of mathematics involving integers and their properties.

More information

Basic elements of number theory

Basic elements of number theory Cryptography Basic elements of number theory Marius Zimand 1 Divisibility, prime numbers By default all the variables, such as a, b, k, etc., denote integer numbers. Divisibility a 0 divides b if b = a

More information

Basic elements of number theory

Basic elements of number theory Cryptography Basic elements of number theory Marius Zimand By default all the variables, such as a, b, k, etc., denote integer numbers. Divisibility a 0 divides b if b = a k for some integer k. Notation

More information

Discrete Mathematics and Probability Theory Summer 2014 James Cook Note 5

Discrete Mathematics and Probability Theory Summer 2014 James Cook Note 5 CS 70 Discrete Mathematics and Probability Theory Summer 2014 James Cook Note 5 Modular Arithmetic In several settings, such as error-correcting codes and cryptography, we sometimes wish to work over a

More information

Number Theory. Zachary Friggstad. Programming Club Meeting

Number Theory. Zachary Friggstad. Programming Club Meeting Number Theory Zachary Friggstad Programming Club Meeting Outline Factoring Sieve Multiplicative Functions Greatest Common Divisors Applications Chinese Remainder Theorem Throughout, problems to try are

More information

Discrete Structures Lecture Solving Congruences. mathematician of the eighteenth century). Also, the equation gggggg(aa, bb) =

Discrete Structures Lecture Solving Congruences. mathematician of the eighteenth century). Also, the equation gggggg(aa, bb) = First Introduction Our goal is to solve equations having the form aaaa bb (mmmmmm mm). However, first we must discuss the last part of the previous section titled gcds as Linear Combinations THEOREM 6

More information

Chapter 9 Mathematics of Cryptography Part III: Primes and Related Congruence Equations

Chapter 9 Mathematics of Cryptography Part III: Primes and Related Congruence Equations Chapter 9 Mathematics of Cryptography Part III: Primes and Related Congruence Equations Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 9.1 Chapter 9 Objectives

More information

Chapter 8. Introduction to Number Theory

Chapter 8. Introduction to Number Theory Chapter 8 Introduction to Number Theory CRYPTOGRAPHY AND NETWORK SECURITY 1 Index 1. Prime Numbers 2. Fermat`s and Euler`s Theorems 3. Testing for Primality 4. Discrete Logarithms 2 Prime Numbers 3 Prime

More information

Cryptography CS 555. Topic 18: RSA Implementation and Security. CS555 Topic 18 1

Cryptography CS 555. Topic 18: RSA Implementation and Security. CS555 Topic 18 1 Cryptography CS 555 Topic 18: RSA Implementation and Security Topic 18 1 Outline and Readings Outline RSA implementation issues Factoring large numbers Knowing (e,d) enables factoring Prime testing Readings:

More information

Number Theory A focused introduction

Number Theory A focused introduction Number Theory A focused introduction This is an explanation of RSA public key cryptography. We will start from first principles, but only the results that are needed to understand RSA are given. We begin

More information

CSE 311 Lecture 13: Primes and GCD. Emina Torlak and Kevin Zatloukal

CSE 311 Lecture 13: Primes and GCD. Emina Torlak and Kevin Zatloukal CSE 311 Lecture 13: Primes and GCD Emina Torlak and Kevin Zatloukal 1 Topics Modular arithmetic applications A quick wrap-up of Lecture 12. Primes Fundamental theorem of arithmetic, Euclid s theorem, factoring.

More information

Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 3

Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 3 CS 70 Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 3 Modular Arithmetic In several settings, such as error-correcting codes and cryptography, we sometimes wish to work over a smaller

More information

A Few Primality Testing Algorithms

A Few Primality Testing Algorithms A Few Primality Testing Algorithms Donald Brower April 2, 2006 0.1 Introduction These notes will cover a few primality testing algorithms. There are many such, some prove that a number is prime, others

More information

1. multiplication is commutative and associative;

1. multiplication is commutative and associative; Chapter 4 The Arithmetic of Z In this chapter, we start by introducing the concept of congruences; these are used in our proof (going back to Gauss 1 ) that every integer has a unique prime factorization.

More information

Chapter 9 Basic Number Theory for Public Key Cryptography. WANG YANG

Chapter 9 Basic Number Theory for Public Key Cryptography. WANG YANG Chapter 9 Basic Number Theory for Public Key Cryptography WANG YANG wyang@njnet.edu.cn Content GCD and Euclid s Algorithm Modular Arithmetic Modular Exponentiation Discrete Logarithms GCD and Euclid s

More information

cse 311: foundations of computing Spring 2015 Lecture 12: Primes, GCD, applications

cse 311: foundations of computing Spring 2015 Lecture 12: Primes, GCD, applications cse 311: foundations of computing Spring 2015 Lecture 12: Primes, GCD, applications casting out 3s Theorem: A positive integer n is divisible by 3 if and only if the sum of its decimal digits is divisible

More information

Ma/CS 6a Class 4: Primality Testing

Ma/CS 6a Class 4: Primality Testing Ma/CS 6a Class 4: Primality Testing By Adam Sheffer Reminder: Euler s Totient Function Euler s totient φ(n) is defined as follows: Given n N, then φ n = x 1 x < n and GCD x, n = 1. In more words: φ n is

More information

22. The Quadratic Sieve and Elliptic Curves. 22.a The Quadratic Sieve

22. The Quadratic Sieve and Elliptic Curves. 22.a The Quadratic Sieve 22. The Quadratic Sieve and Elliptic Curves 22.a The Quadratic Sieve Sieve methods for finding primes or for finding factors of numbers are methods by which you take a set P of prime numbers one by one,

More information

Lecture 7: Number Theory Steven Skiena. skiena

Lecture 7: Number Theory Steven Skiena.   skiena Lecture 7: Number Theory Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.sunysb.edu/ skiena Number Theory and Divisibility G-d created

More information

Linear Congruences. The equation ax = b for a, b R is uniquely solvable if a 0: x = b/a. Want to extend to the linear congruence:

Linear Congruences. The equation ax = b for a, b R is uniquely solvable if a 0: x = b/a. Want to extend to the linear congruence: Linear Congruences The equation ax = b for a, b R is uniquely solvable if a 0: x = b/a. Want to extend to the linear congruence: ax b (mod m), a, b Z, m N +. (1) If x 0 is a solution then so is x k :=

More information

Discrete Mathematics and Probability Theory Summer 2017 Course Notes Note 6

Discrete Mathematics and Probability Theory Summer 2017 Course Notes Note 6 CS 70 Discrete Mathematics and Probability Theory Summer 2017 Course Notes Note 6 Modular Arithmetic In several settings, such as error-correcting codes and cryptography, we sometimes wish to work over

More information

Know the Well-ordering principle: Any set of positive integers which has at least one element contains a smallest element.

Know the Well-ordering principle: Any set of positive integers which has at least one element contains a smallest element. The first exam will be on Monday, June 8, 202. The syllabus will be sections. and.2 in Lax, and the number theory handout found on the class web site, plus the handout on the method of successive squaring

More information

Instructor: Bobby Kleinberg Lecture Notes, 25 April The Miller-Rabin Randomized Primality Test

Instructor: Bobby Kleinberg Lecture Notes, 25 April The Miller-Rabin Randomized Primality Test Introduction to Algorithms (CS 482) Cornell University Instructor: Bobby Kleinberg Lecture Notes, 25 April 2008 The Miller-Rabin Randomized Primality Test 1 Introduction Primality testing is an important

More information

MTH 346: The Chinese Remainder Theorem

MTH 346: The Chinese Remainder Theorem MTH 346: The Chinese Remainder Theorem March 3, 2014 1 Introduction In this lab we are studying the Chinese Remainder Theorem. We are going to study how to solve two congruences, find what conditions are

More information

Number theory (Chapter 4)

Number theory (Chapter 4) EECS 203 Spring 2016 Lecture 10 Page 1 of 8 Number theory (Chapter 4) Review Questions: 1. Does 5 1? Does 1 5? 2. Does (129+63) mod 10 = (129 mod 10)+(63 mod 10)? 3. Does (129+63) mod 10 = ((129 mod 10)+(63

More information

CSE 20 DISCRETE MATH. Winter

CSE 20 DISCRETE MATH. Winter CSE 20 DISCRETE MATH Winter 2017 http://cseweb.ucsd.edu/classes/wi17/cse20-ab/ Today's learning goals Define and use the congruence modulo m equivalence relation Perform computations using modular arithmetic

More information

Math 131 notes. Jason Riedy. 6 October, Linear Diophantine equations : Likely delayed 6

Math 131 notes. Jason Riedy. 6 October, Linear Diophantine equations : Likely delayed 6 Math 131 notes Jason Riedy 6 October, 2008 Contents 1 Modular arithmetic 2 2 Divisibility rules 3 3 Greatest common divisor 4 4 Least common multiple 4 5 Euclidean GCD algorithm 5 6 Linear Diophantine

More information

2x 1 7. A linear congruence in modular arithmetic is an equation of the form. Why is the solution a set of integers rather than a unique integer?

2x 1 7. A linear congruence in modular arithmetic is an equation of the form. Why is the solution a set of integers rather than a unique integer? Chapter 3: Theory of Modular Arithmetic 25 SECTION C Solving Linear Congruences By the end of this section you will be able to solve congruence equations determine the number of solutions find the multiplicative

More information

Primality Testing. 1 Introduction. 2 Brief Chronology of Primality Testing. CS265/CME309, Fall Instructor: Gregory Valiant

Primality Testing. 1 Introduction. 2 Brief Chronology of Primality Testing. CS265/CME309, Fall Instructor: Gregory Valiant CS265/CME309, Fall 2018. Instructor: Gregory Valiant Primality Testing [These notes may not be distributed outside this class without the permission of Gregory Valiant.] 1 Introduction Prime numbers are

More information

2 Elementary number theory

2 Elementary number theory 2 Elementary number theory 2.1 Introduction Elementary number theory is concerned with properties of the integers. Hence we shall be interested in the following sets: The set if integers {... 2, 1,0,1,2,3,...},

More information

Addition. Ch1 - Algorithms with numbers. Multiplication. al-khwārizmī. al-khwārizmī. Division 53+35=88. Cost? (n number of bits) 13x11=143. Cost?

Addition. Ch1 - Algorithms with numbers. Multiplication. al-khwārizmī. al-khwārizmī. Division 53+35=88. Cost? (n number of bits) 13x11=143. Cost? Ch - Algorithms with numbers Addition Basic arithmetic Addition ultiplication Division odular arithmetic factoring is hard Primality testing 53+35=88 Cost? (n number of bits) O(n) ultiplication al-khwārizmī

More information

Chapter 4 Finite Fields

Chapter 4 Finite Fields Chapter 4 Finite Fields Introduction will now introduce finite fields of increasing importance in cryptography AES, Elliptic Curve, IDEA, Public Key concern operations on numbers what constitutes a number

More information

basics of security/cryptography

basics of security/cryptography RSA Cryptography basics of security/cryptography Bob encrypts message M into ciphertext C=P(M) using a public key; Bob sends C to Alice Alice decrypts ciphertext back into M using a private key (secret)

More information

11 Division Mod n, Linear Integer Equations, Random Numbers, The Fundamental Theorem of Arithmetic

11 Division Mod n, Linear Integer Equations, Random Numbers, The Fundamental Theorem of Arithmetic 11 Division Mod n, Linear Integer Equations, Random Numbers, The Fundamental Theorem of Arithmetic Bezout s Lemma Let's look at the values of 4x + 6y when x and y are integers. If x is -6 and y is 4 we

More information

C-N Math 207 Discrete Math

C-N Math 207 Discrete Math C-N Math 207 - Massey, 1 / 70 C-N Math 207 Discrete Math Kenneth Massey September 16, 2011 Question C-N Math 207 - Massey, 2 / 70 Introduction What is the smallest positive number? Sets C-N Math 207 -

More information

C-N Math 207 Discrete Math

C-N Math 207 Discrete Math C-N Math 207 Discrete Math Kenneth Massey September 16, 2011 C-N Math 207 - Massey, 1 / 70 Question Introduction What is the smallest positive number? C-N Math 207 - Massey, 2 / 70 Sets Introduction a

More information

PUTNAM TRAINING NUMBER THEORY. Exercises 1. Show that the sum of two consecutive primes is never twice a prime.

PUTNAM TRAINING NUMBER THEORY. Exercises 1. Show that the sum of two consecutive primes is never twice a prime. PUTNAM TRAINING NUMBER THEORY (Last updated: December 11, 2017) Remark. This is a list of exercises on Number Theory. Miguel A. Lerma Exercises 1. Show that the sum of two consecutive primes is never twice

More information

7.2 Applications of Euler s and Fermat s Theorem.

7.2 Applications of Euler s and Fermat s Theorem. 7.2 Applications of Euler s and Fermat s Theorem. i) Finding and using inverses. From Fermat s Little Theorem we see that if p is prime and p a then a p 1 1 mod p, or equivalently a p 2 a 1 mod p. This

More information

PRIMALITY TESTING. Professor : Mr. Mohammad Amin Shokrollahi Assistant : Mahdi Cheraghchi. By TAHIRI JOUTI Kamal

PRIMALITY TESTING. Professor : Mr. Mohammad Amin Shokrollahi Assistant : Mahdi Cheraghchi. By TAHIRI JOUTI Kamal PRIMALITY TESTING Professor : Mr. Mohammad Amin Shokrollahi Assistant : Mahdi Cheraghchi By TAHIRI JOUTI Kamal TABLE OF CONTENTS I- FUNDAMENTALS FROM NOMBER THEORY FOR RANDOMIZED ALGORITHMS:.page 4 1)

More information

FERMAT S TEST KEITH CONRAD

FERMAT S TEST KEITH CONRAD FERMAT S TEST KEITH CONRAD 1. Introduction Fermat s little theorem says for prime p that a p 1 1 mod p for all a 0 mod p. A naive extension of this to a composite modulus n 2 would be: for all a 0 mod

More information

Number Theory and Algebra: A Brief Introduction

Number Theory and Algebra: A Brief Introduction Number Theory and Algebra: A Brief Introduction Indian Statistical Institute Kolkata May 15, 2017 Elementary Number Theory: Modular Arithmetic Definition Let n be a positive integer and a and b two integers.

More information

Number Theory Solutions Packet

Number Theory Solutions Packet Number Theory Solutions Pacet 1 There exist two distinct positive integers, both of which are divisors of 10 10, with sum equal to 157 What are they? Solution Suppose 157 = x + y for x and y divisors of

More information

Lucas Lehmer primality test - Wikipedia, the free encyclopedia

Lucas Lehmer primality test - Wikipedia, the free encyclopedia Lucas Lehmer primality test From Wikipedia, the free encyclopedia In mathematics, the Lucas Lehmer test (LLT) is a primality test for Mersenne numbers. The test was originally developed by Edouard Lucas

More information

Simple Math: Cryptography

Simple Math: Cryptography 1 Introduction Simple Math: Cryptography This section develops some mathematics before getting to the application. The mathematics that I use involves simple facts from number theory. Number theory is

More information

Primality Testing- Is Randomization worth Practicing?

Primality Testing- Is Randomization worth Practicing? Primality Testing- Is Randomization worth Practicing? Shubham Sahai Srivastava Indian Institute of Technology, Kanpur ssahai@cse.iitk.ac.in April 5, 2014 Shubham Sahai Srivastava (IITK) Primality Test

More information

2x 1 7. A linear congruence in modular arithmetic is an equation of the form. Why is the solution a set of integers rather than a unique integer?

2x 1 7. A linear congruence in modular arithmetic is an equation of the form. Why is the solution a set of integers rather than a unique integer? Chapter 3: Theory of Modular Arithmetic 25 SECTION C Solving Linear Congruences By the end of this section you will be able to solve congruence equations determine the number of solutions find the multiplicative

More information

Applied Cryptography and Computer Security CSE 664 Spring 2017

Applied Cryptography and Computer Security CSE 664 Spring 2017 Applied Cryptography and Computer Security Lecture 11: Introduction to Number Theory Department of Computer Science and Engineering University at Buffalo 1 Lecture Outline What we ve covered so far: symmetric

More information

Mathematics for Cryptography

Mathematics for Cryptography Mathematics for Cryptography Douglas R. Stinson David R. Cheriton School of Computer Science University of Waterloo Waterloo, Ontario, N2L 3G1, Canada March 15, 2016 1 Groups and Modular Arithmetic 1.1

More information

OWO Lecture: Modular Arithmetic with Algorithmic Applications

OWO Lecture: Modular Arithmetic with Algorithmic Applications OWO Lecture: Modular Arithmetic with Algorithmic Applications Martin Otto Winter Term 2008/09 Contents 1 Basic ingredients 1 2 Modular arithmetic 2 2.1 Going in circles.......................... 2 2.2

More information

CPSC 467b: Cryptography and Computer Security

CPSC 467b: Cryptography and Computer Security CPSC 467b: Cryptography and Computer Security Michael J. Fischer Lecture 9 February 6, 2012 CPSC 467b, Lecture 9 1/53 Euler s Theorem Generating RSA Modulus Finding primes by guess and check Density of

More information

INTEGERS. In this section we aim to show the following: Goal. Every natural number can be written uniquely as a product of primes.

INTEGERS. In this section we aim to show the following: Goal. Every natural number can be written uniquely as a product of primes. INTEGERS PETER MAYR (MATH 2001, CU BOULDER) In this section we aim to show the following: Goal. Every natural number can be written uniquely as a product of primes. 1. Divisibility Definition. Let a, b

More information

All variables a, b, n, etc are integers unless otherwise stated. Each part of a problem is worth 5 points.

All variables a, b, n, etc are integers unless otherwise stated. Each part of a problem is worth 5 points. Math 152, Problem Set 2 solutions (2018-01-24) All variables a, b, n, etc are integers unless otherwise stated. Each part of a problem is worth 5 points. 1. Let us look at the following equation: x 5 1

More information

8 Primes and Modular Arithmetic

8 Primes and Modular Arithmetic 8 Primes and Modular Arithmetic 8.1 Primes and Factors Over two millennia ago already, people all over the world were considering the properties of numbers. One of the simplest concepts is prime numbers.

More information

Course 2BA1: Trinity 2006 Section 9: Introduction to Number Theory and Cryptography

Course 2BA1: Trinity 2006 Section 9: Introduction to Number Theory and Cryptography Course 2BA1: Trinity 2006 Section 9: Introduction to Number Theory and Cryptography David R. Wilkins Copyright c David R. Wilkins 2006 Contents 9 Introduction to Number Theory and Cryptography 1 9.1 Subgroups

More information