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

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

CSE 311: Foundations of Computing. Lecture 12: Two s Complement, Primes, GCD

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

cse 311: foundations of computing Fall 2015 Lecture 11: Modular arithmetic and applications

Adam Blank Spring 2017 CSE 311. Foundations of Computing I. * All slides are a combined effort between previous instructors of the course

Fall 2015 Lecture 14: Modular congruences. cse 311: foundations of computing

CPSC 467b: Cryptography and Computer Security

Applied Cryptography and Computer Security CSE 664 Spring 2017

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

CPSC 467: Cryptography and Computer Security

Discrete Mathematics GCD, LCM, RSA Algorithm

CS March 17, 2009

Integers and Division

CS483 Design and Analysis of Algorithms

Chapter 4 Finite Fields

Intermediate Math Circles February 26, 2014 Diophantine Equations I

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

The Euclidean Algorithm and Multiplicative Inverses

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. AIT 682: Network and Systems Security. GCD and Euclid s Algorithm Modulo Arithmetic Modular Exponentiation Discrete Logarithms

8 Primes and Modular Arithmetic

Numbers. Çetin Kaya Koç Winter / 18

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

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

3 The fundamentals: Algorithms, the integers, and matrices

CSE 20 DISCRETE MATH. Winter

ECE 646 Lecture 5. Mathematical Background: Modular Arithmetic

Mathematical Foundations of Cryptography

Number Theory and Cryptography

Notes. Number Theory: Applications. Notes. Number Theory: Applications. Notes. Hash Functions I

Algorithms (II) Yu Yu. Shanghai Jiaotong University

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

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.

CMPUT 403: Number Theory

Section Summary. Division Division Algorithm Modular Arithmetic

CS250: Discrete Math for Computer Science

Introduction to Cryptography CS 355 Lecture 3

4 Number Theory and Cryptography

Senior Math Circles Cryptography and Number Theory Week 2

Number Theory: Applications. Number Theory Applications. Hash Functions II. Hash Functions III. Pseudorandom Numbers

Math.3336: Discrete Mathematics. Primes and Greatest Common Divisors

Slides by Christopher M. Bourke Instructor: Berthe Y. Choueiry. Spring 2006

1. Algebra 1.7. Prime numbers

Public Key Encryption

Number Theory. Zachary Friggstad. Programming Club Meeting

Lecture 7: Number Theory Steven Skiena. skiena

The set of integers will be denoted by Z = {, -3, -2, -1, 0, 1, 2, 3, 4, }

Remainders. We learned how to multiply and divide in elementary

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

Discrete Structures Lecture Primes and Greatest Common Divisor

Homework 3, solutions

Proofs. Methods of Proof Divisibility Floor and Ceiling Contradiction & Contrapositive Euclidean Algorithm. Reading (Epp s textbook)

Congruence Classes. Number Theory Essentials. Modular Arithmetic Systems

COT 3100 Applications of Discrete Structures Dr. Michael P. Frank

CSC 474 Information Systems Security

Number theory. Myrto Arapinis School of Informatics University of Edinburgh. October 9, /29

Inverses. Today: finding inverses quickly. Euclid s Algorithm. Runtime. Euclid s Extended Algorithm.

Basic elements of number theory

Basic elements of number theory

NOTES ON SIMPLE NUMBER THEORY

Introduction to Public-Key Cryptosystems:

Some Facts from Number Theory

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

Lecture 7 Number Theory Euiseong Seo

Q 2.0.2: If it s 5:30pm now, what time will it be in 4753 hours? Q 2.0.3: Today is Wednesday. What day of the week will it be in one year from today?

Arithmetic Algorithms, Part 1

Encryption: The RSA Public Key Cipher

a the relation arb is defined if and only if = 2 k, k

Number theory (Chapter 4)

ECE 646 Lecture 5. Motivation: Mathematical Background: Modular Arithmetic. Public-key ciphers. RSA keys. RSA as a trap-door one-way function

Finite Fields. Mike Reiter

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

The RSA Cryptosystem: Factoring the public modulus. Debdeep Mukhopadhyay

CHAPTER 3. Congruences. Congruence: definitions and properties

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

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

MONOALPHABETIC CIPHERS AND THEIR MATHEMATICS. CIS 400/628 Spring 2005 Introduction to Cryptography

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

CHAPTER 6. Prime Numbers. Definition and Fundamental Results

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

2301 Assignment 1 Due Friday 19th March, 2 pm

Chinese Remainder Theorem

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

Introduction to Cybersecurity Cryptography (Part 5)

Mathematics for Computer Science Exercises for Week 10

Introduction to Cryptography. Lecture 6

CIS 6930/4930 Computer and Network Security. Topic 4. Cryptographic Hash Functions

Number Theory Notes Spring 2011

With Question/Answer Animations. Chapter 4

2. THE EUCLIDEAN ALGORITHM More ring essentials

Lecture 11 - Basic Number Theory.

Chapter 2 (Part 3): The Fundamentals: Algorithms, the Integers & Matrices. Integers & Algorithms (2.5)

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

Number Theory. Modular Arithmetic

4 Powers of an Element; Cyclic Groups

Solution Sheet (i) q = 5, r = 15 (ii) q = 58, r = 15 (iii) q = 3, r = 7 (iv) q = 6, r = (i) gcd (97, 157) = 1 = ,

Algorithms CMSC Basic algorithms in Number Theory: Euclid s algorithm and multiplicative inverse

COMP239: Mathematics for Computer Science II. Prof. Chadi Assi EV7.635

MATH 501 Discrete Mathematics. Lecture 6: Number theory. German University Cairo, Department of Media Engineering and Technology.

CSE 311 Lecture 11: Modular Arithmetic. Emina Torlak and Kevin Zatloukal

Transcription:

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 by 3.

leaked game of thrones

pattern matching

pattern matching

basic applications of mod Hashing Pseudo random number generation Simple cipher

hashing Scenario: Map a small number of data values from a large domain 0, 1,, M 1 into a small set of locations 0,1,, n 1 so one can quickly check if some value is present.

hashing Scenario: Map a small number of data values from a large domain 0, 1,, M 1 into a small set of locations 0,1,, n 1 so one can quickly check if some value is present hash x = x mod p for p a prime close to n or hash x = (ax + b) mod p Depends on all of the bits of the data helps avoid collisions due to similar values need to manage them if they occur

Linear Congruential method: pseudo-random number generation x n+1 = a x n + c mod m Choose random x 0, a, c, m and produce a long sequence of x n s [good for some applications, really bad for many others]

simple ciphers Caesar cipher, A = 1, B = 2,... HELLO WORLD Shift cipher f(p) = (p + k) mod 26 f 1 (p) = (p k) mod 26 More general f(p) = (ap + b) mod 26

modular exponentiation mod 7 X 1 2 3 4 5 6 1 2 3 4 5 6 a a 1 a 2 a 3 a 4 a 5 a 6 1 2 3 4 5 6

modular exponentiation mod 7 X 1 2 3 4 5 6 1 1 2 3 4 5 6 2 2 4 6 1 3 5 3 3 6 2 5 1 4 4 4 1 5 2 6 3 5 5 3 1 6 4 2 6 6 5 4 3 2 1 a a 1 a 2 a 3 a 4 a 5 a 6 1 2 3 4 5 6

modular exponentiation mod 7 X 1 2 3 4 5 6 1 1 2 3 4 5 6 2 2 4 6 1 3 5 3 3 6 2 5 1 4 4 4 1 5 2 6 3 5 5 3 1 6 4 2 6 6 5 4 3 2 1 a a 1 a 2 a 3 a 4 a 5 a 6 1 1 1 1 1 1 1 2 2 4 1 2 4 1 3 3 2 6 4 5 1 4 4 2 1 4 2 1 5 5 4 6 2 3 1 6 6 1 6 1 6 1

exponentiation Compute 78365 81453 Compute 78365 81453 mod 104729 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 exponentiaion 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

Let M = 104729 program trace 78365 81453 mod M = ((78365 mod M) * (78365 81452 mod M)) mod M = (78365 * ((78365 2 mod M) 81452/2 mod M)) mod M = (78365 * ((78852) 40726 mod M)) mod M = (78365 * ((78852 2 mod M) 20363 mod M)) mod M = (78365 * (86632 20363 mod M)) mod M = (78365 * ((86632 mod M)* (86632 20362 mod M)) mod M =... = 45235

fast exponentiation algorithm Another way: 81453 = 2 16 + 2 13 + 2 12 + 2 11 + 2 10 + 2 9 + 2 5 + 2 3 + 2 2 + 2 0 a 81453 = a 216 a 213 a 212 a 211 a 210 a 29 a 25 a 23 a 22 a 20 a 81453 mod m= ( (((((a 216 mod m a 213 mod m ) mod m a 212 mod m) mod m a 211 mod m) mod m a 210 mod m) mod m a 29 mod m) mod m a 25 mod m) mod m a 23 mod m) mod m a 22 mod m) mod m a 20 mod m) mod m The fast exponentiation algorithm computes a n mod m using O(log n) multiplications 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 = 2 2 2 2 3 591 = 3 197 45,523 = 45,523 321,950 = 2 5 5 47 137 1,234,567,890 = 2 3 3 5 3,607 3,803

factorization If n is composite, it has a factor of size at most n.

euclid s theorem There are an infinite number of primes. Proof by contradiction: Suppose that there are only a finite number of primes: p 1, p 2,, p n

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]: 12301866845301177551304949583849627207 72853569595334792197322452151726400507 26365751874520219978646938995647494277 40638459251925573263034537315482685079 17026122142913461670429214311602221240 47927473779408066535141959745985690214 3413

1230186684530117755130494958384962720772853569595334 7921973224521517264005072636575187452021997864693899 5647494277406384592519255732630345373154826850791702 6122142913461670429214311602221240479274737794080665 351419597459856902143413 334780716989568987860441698482126908177047949837 137685689124313889828837938780022876147116525317 43087737814467999489 367460436667995904282446337996279526322791581643 430876426760322838157396665112792333734171433968 10270092798736308917

GCD(a, b): greatest common divisor Largest integer d such that d a and d b GCD(100, 125) = GCD(17, 49) = GCD(11, 66) = GCD(13, 0) = GCD(180, 252) =

gcd and factoring a = 2 3 3 5 2 7 11 = 46,200 b = 2 3 2 5 3 7 13 = 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?

If a and b are positive integers, then gcd a, b = gcd(b, a mod b) useful GCD fact Proof: By definition a = a div b b + (a mod b) If d a and d b then d a mod b. If d b and d a mod b then d a.

Repeatedly use the GCD fact to reduce numbers until you get GCD x, 0 = x. 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)