CSE 311: Foundations of Computing Fall 2014 Lecture 12: Primes, GCD.

Slides:



Advertisements
Similar presentations
RSA COSC 201 ST. MARY’S COLLEGE OF MARYLAND FALL 2012 RSA.
Advertisements

CS 202 Epp section ?? Aaron Bloomfield
WS Algorithmentheorie 03 – Randomized Algorithms (Primality Testing) Prof. Dr. Th. Ottmann.
Section 4.1: Primes, Factorization, and the Euclidean Algorithm Practice HW (not to hand in) From Barr Text p. 160 # 6, 7, 8, 11, 12, 13.
The Integers and Division. Outline Division: Factors, multiples Exercise 2.3 Primes: The Fundamental Theorem of Arithmetic. The Division Algorithm Greatest.
Primality Testing Patrick Lee 12 July 2003 (updated on 13 July 2003)
Sets, Combinatorics, Probability, and Number Theory Mathematical Structures for Computer Science Chapter 3 Copyright © 2006 W.H. Freeman & Co.MSCS Slides.
1 Section 2.4 The Integers and Division. 2 Number Theory Branch of mathematics that includes (among other things): –divisibility –greatest common divisor.
CSE 311 Foundations of Computing I Lecture 13 Number Theory Autumn 2012 CSE
Chapter Primes and Greatest Common Divisors ‒Primes ‒Greatest common divisors and least common multiples 1.
22C:19 Discrete Math Integers and Modular Arithmetic Fall 2010 Sukumar Ghosh.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2009 Tuesday, 28 April Number-Theoretic Algorithms Chapter 31.
CSE115/ENGR160 Discrete Mathematics 03/15/11
Elementary Number Theory and Methods of Proof. Basic Definitions An integer n is an even number if there exists an integer k such that n = 2k. An integer.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2002 Tuesday, 26 November Number-Theoretic Algorithms Chapter 31.
6/20/2015 5:05 AMNumerical Algorithms1 x x1x
CSE 321 Discrete Structures Winter 2008 Lecture 8 Number Theory: Modular Arithmetic.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 7 Tuesday, 11/6/01 Number-Theoretic Algorithms Chapter.
1 Integers and Division CS/APMA 202 Rosen section 2.4 Aaron Bloomfield.
CSE 321 Discrete Structures Winter 2008 Lecture 10 Number Theory: Primality.
CSE 311 Foundations of Computing I Lecture 12 Primes, GCD, Modular Inverse Spring
Divisibility October 8, Divisibility If a and b are integers and a  0, then the statement that a divides b means that there is an integer c such.
Integers Number Theory = Properties of Integers

1 Properties of Integers Objectives At the end of this unit, students should be able to: State the division algorithm Apply the division algorithm Find.
3.4/3.5 The Integers and Division/ Primes and Greatest Common Divisors Let each of a and b be integers. We say that a divides b, in symbols a | b, provided.
MATH 224 – Discrete Mathematics
Module :MA3036NI Cryptography and Number Theory Lecture Week 7
CPSC 3730 Cryptography and Network Security
1 Cryptography and Network Security Third Edition by William Stallings Lecture slides by Lawrie Brown Chapter 4 – Finite Fields.
Cryptography Inverses and GCD Piotr Faliszewski. GCD(a,b) gcd(a, 0) = a gcd(a, b) = gcd(b, a mod b) a = b*q + r Here: q =  a / b  r = a mod b (a –
Introduction to Algorithms Second Edition by Cormen, Leiserson, Rivest & Stein Chapter 31.
CS 312: Algorithm Analysis Lecture #4: Primality Testing, GCD This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.Creative.
CS/ECE Advanced Network Security Dr. Attila Altay Yavuz
MA/CSSE 473 Day 06 Euclid's Algorithm. MA/CSSE 473 Day 06 Student Questions Odd Pie Fight Euclid's algorithm (if there is time) extended Euclid's algorithm.
Lecture 6.1: Misc. Topics: Number Theory CS 250, Discrete Structures, Fall 2011 Nitesh Saxena.
CS Modular Division and RSA1 RSA Public Key Encryption To do RSA we need fast Modular Exponentiation and Primality generation which we have shown.
MA/CSSE 473 Day 08 Extended Euclid's Algorithm Modular Division Fermat's little theorem.
CSE 311 Foundations of Computing I Lecture 14 Euclid’s Algorithm Mathematical Induction Autumn 2012 CSE
Tuesday’s lecture: Today’s lecture: One-way permutations (OWPs)
Application: Algorithms Lecture 20 Section 3.8 Wed, Feb 21, 2007.
AF2. Turn off your phones Primes, gcd, some examples, reading.
Foundations of Computing I CSE 311 Fall Review: Division Theorem Let a be an integer and d a positive integer. Then there are unique integers q.
CSE 311: Foundations of Computing Fall 2013 Lecture 12: Primes, GCD, modular inverse.
Discrete Mathematics
CSE 311: Foundations of Computing Fall 2013 Lecture 11: Modular arithmetic and applications.
CS 312: Algorithm Analysis Lecture #4: Primality Testing, GCD This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.Creative.
Application: Algorithms Lecture 19 Section 3.8 Tue, Feb 20, 2007.
AF2. Turn off your phones Primes, gcd, some examples, reading.
1 Discrete Structures – CNS2300 Text Discrete Mathematics and Its Applications Kenneth H. Rosen (5 th Edition) Chapter 2 The Fundamentals: Algorithms,
Chapter 4 With Question/Answer Animations 1. Chapter Summary Divisibility and Modular Arithmetic - Sec 4.1 – Lecture 16 Integer Representations and Algorithms.
CSE 311 Foundations of Computing I Lecture 12 Modular Arithmetic and Applications Autumn 2012 CSE
CSE 311 Foundations of Computing I Lecture 11 Modular Exponentiation and Primes Autumn 2011 CSE 3111.
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.
Divisibility and Primes
Numerical Algorithms x x-1 Numerical Algorithms
Thinking Critically 4.1 Divisibility Of Natural Numbers
CSE 311 Foundations of Computing I
Numerical Algorithms x x-1
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett
Number Theory (Chapter 7)
Discrete Math for CS CMPSC 360 LECTURE 12 Last time: Stable matching
CSE 311 Foundations of Computing I
CSE 311: Foundations of Computing
CSE 321 Discrete Structures
CSE 321 Discrete Structures
Application: Algorithms
Application: Algorithms
Number Theory.
Useful GCD Fact If a and b are positive integers, then gcd(a,b) = gcd(b, a mod b) Proof: By definition of mod, a = qb+ (a mod b) for.
Presentation transcript:

CSE 311: Foundations of Computing Fall 2014 Lecture 12: Primes, GCD

Basic Applications of mod Hashing Pseudo random number generation

Hashing

Pseudo-Random Number Generation Linear Congruential method

Modular Exponentiation mod 7 X aa1a1 a2a2 a3a3 a4a4 a5a5 a6a

Exponentiation Compute Compute mod Output is small – need to keep intermediate results small

Repeated Squaring – small and fast Since a mod m ≡ a (mod m) for any a we have a 2 mod m = (a mod m) 2 mod m and a 4 mod m = (a 2 mod m) 2 mod m and a 8 mod m = (a 4 mod m) 2 mod m and a 16 mod m = (a 8 mod m) 2 mod m and a 32 mod m = (a 16 mod m) 2 mod m Can compute a k mod m for k=2 i in only i steps

Fast Exponentiation public static long FastModExp(long base, long exponent, long modulus) { long result = 1; base = base % modulus; while (exponent > 0) { if ((exponent % 2) == 1) { result = (result * base) % modulus; exponent -= 1; } /* Note that exponent is definitely divisible by 2 here. */ exponent /= 2; base = (base * base) % modulus; /* The last iteration of the loop will always be exponent = 1 */ /* so, result will always be correct. */ } return result; } b e mod m = (b 2 ) e/2 mod m, when e is even) b e mod m = (b*(b e-1 mod m) mod m)) mod m

Program Trace mod M = ((78365 mod M) * ( mod M)) mod M = (78365 * (( mod M) 81452/2 mod M)) mod M = (78365 * ((78852) mod M)) mod M = (78365 * (( mod M) mod M)) mod M = (78365 * ( mod M)) mod M = (78365 * ((86632 mod M)* ( mod M)) mod M =... = Let M =

Fast Exponentiation Algorithm Another way: = a = a 2 16 · a 2 13 · a 2 12 · a 2 11 · a 2 10 · a 2 9 · a 2 5 · a 2 3 · a 2 2 · a 2 0 a mod m= (…(((((a 2 16 mod m · a 2 13 mod m ) mod m · a 2 12 mod m) mod m · a 2 11 mod m) mod m · a 2 10 mod m) mod m · a 2 9 mod m) mod m · a 2 5 mod m) mod m · a 2 3 mod m) mod m · a 2 2 mod m) mod m · a 2 0 mod m) mod m

Primality An integer p greater than 1 is called prime if the only positive factors of p are 1 and p. A positive integer that is greater than 1 and is not prime is called composite.

Fundamental Theorem of Arithmetic Every positive integer greater than 1 has a unique prime factorization 48 = = ,523 = 45, ,950 = ,234,567,890 = ,607 3,803

Factorization

Euclid’s Theorem

Famous Algorithmic Problems Primality Testing – Given an integer n, determine if n is prime Factoring – Given an integer n, determine the prime factorization of n

Factoring Factor the following 232 digit number [RSA768]:

Greatest Common Divisor

GCD and Factoring a = = 46,200 b = = 204,750 GCD(a, b) = 2 min(3,1) 3 min(1,2) 5 min(2,3) 7 min(1,1) 11 min(1,0) 13 min(0,1) Factoring is expensive! Can we compute GCD(a,b) without factoring?

Useful GCD Fact If a and b are positive integers, then gcd(a,b) = gcd(b, a mod b)

Euclid’s Algorithm GCD(660,126)

Euclid’s Algorithm GCD(x, y) = GCD(y, x mod y) int GCD(int a, int b){ /* a >= b, b > 0 */ int tmp; while (b > 0) { tmp = a % b; a = b; b = tmp; } return a; } Example: GCD(660, 126)