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

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

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

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

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

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

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

CPSC 467: Cryptography and Computer Security

Applied Cryptography and Computer Security CSE 664 Spring 2017

Discrete Mathematics GCD, LCM, RSA Algorithm

CS March 17, 2009

3 The fundamentals: Algorithms, the integers, and matrices

Integers and Division

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

Numbers. Çetin Kaya Koç Winter / 18

4 Number Theory and Cryptography

CS483 Design and Analysis of Algorithms

Algorithms (II) Yu Yu. Shanghai Jiaotong University

Chapter 4 Finite Fields

The Euclidean Algorithm and Multiplicative Inverses

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

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

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

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

Number Theory and Cryptography

1. Algebra 1.7. Prime numbers

CSE 20 DISCRETE MATH. Winter

Section Summary. Division Division Algorithm Modular Arithmetic

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

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.

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

Mathematical Foundations of Cryptography

ECE 646 Lecture 5. Mathematical Background: Modular Arithmetic

Intermediate Math Circles February 26, 2014 Diophantine Equations I

2.5 정수와알고리즘 (Integers and Algorithms)

8 Primes and Modular Arithmetic

Base-b representations of integers. (b 진법표현 ) Algorithms for computer arithmetic: Euclidean algorithm for finding GCD s.

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

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?

Introduction to Cryptography CS 355 Lecture 3

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

Lecture 7: Number Theory Steven Skiena. skiena

Mat Week 8. Week 8. gcd() Mat Bases. Integers & Computers. Linear Combos. Week 8. Induction Proofs. Fall 2013

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

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

Encryption: The RSA Public Key Cipher

Student Responsibilities Week 8. Mat Section 3.6 Integers and Algorithms. Algorithm to Find gcd()

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

Discrete Structures Lecture Primes and Greatest Common Divisor

CHAPTER 3. Congruences. Congruence: definitions and properties

Public Key Encryption

CMPUT 403: Number Theory

Congruence Classes. Number Theory Essentials. Modular Arithmetic Systems

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

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

Applied Cryptography and Computer Security CSE 664 Spring 2018

NOTES ON SIMPLE NUMBER THEORY

Lecture 11 - Basic Number Theory.

Number Theory. Modular Arithmetic

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

With Question/Answer Animations. Chapter 4

Lecture 7 Number Theory Euiseong Seo

Basic elements of number theory

Basic elements of number theory

Number theory (Chapter 4)

COMS W4995 Introduction to Cryptography September 29, Lecture 8: Number Theory

Number Theory. Zachary Friggstad. Programming Club Meeting

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

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

OWO Lecture: Modular Arithmetic with Algorithmic Applications

CS250: Discrete Math for Computer Science

Discrete Mathematics and Probability Theory Summer 2014 James Cook Note 5

ICS141: Discrete Mathematics for Computer Science I

Senior Math Circles Cryptography and Number Theory Week 2

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

Lecture 2. The Euclidean Algorithm and Numbers in Other Bases

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

The RSA Cryptosystem: Factoring the public modulus. Debdeep Mukhopadhyay

CS1800 Discrete Structures Fall 2017 October, CS1800 Discrete Structures Midterm Version A

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

Remainders. We learned how to multiply and divide in elementary

Conversions between Decimal and Binary

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

2301 Assignment 1 Due Friday 19th March, 2 pm

Lecture 6: Cryptanalysis of public-key algorithms.,

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

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

Chinese Remainder Theorem

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

Number Theory Notes Spring 2011

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

CS 4770: Cryptography. CS 6750: Cryptography and Communication Security. Alina Oprea Associate Professor, CCIS Northeastern University

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 = ,

1. (16 points) Circle T if the corresponding statement is True or F if it is False.

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

CIS 551 / TCOM 401 Computer and Network Security

Basic Algorithms in Number Theory

Transcription:

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 {0,1} then representation is b n-1 b 2 b 1 b 0 For n = 8: 99 = 64 + 32 + 2 + 1 18 = 16 + 2 99: 0110 0011 18: 0001 0010

sign-magnitude integer representation n-bit signed integers Suppose 2 n 1 < x < 2 n 1 First bit as the sign, n-1 bits for the value 99 = 64 + 32 + 2 + 1 18 = 16 + 2 For n = 8: 99: 0110 0011-18: 1001 0010 Any problems with this representation?

two s complement representation n-bit signed integers, first bit will still be the sign bit Suppose 0 x < 2 n 1, x is represented by the binary representation of x Suppose 0 x 2 n 1, x is represented by the binary representation of 2 n x Key property: Two s complement representation of any number y is equivalent to y mod 2 n so arithmetic works mod 2 n 99 = 64 + 32 + 2 + 1 18 = 16 + 2 For n = 8: 99: 0110 0011-18: 1110 1110

sign-magnitude vs. two s complement -7-6 -5-4 -3-2 -1 0 1 2 3 4 5 6 7 1111 1110 1101 1100 1011 1010 1001 0000 0001 0010 0011 0100 0101 0110 0111 Sign-Magnitude -8-7 -6-5 -4-3 -2-1 0 1 2 3 4 5 6 7 1000 1001 1010 1011 1100 1101 1110 1111 0000 0001 0010 0011 0100 0101 0110 0111 Two s complement

two s complement representation For 0 < x 2 n 1, x is represented by the binary representation of 2 n x To compute this: Flip the bits of x then add 1: All 1 s string is 2 n 1, so Flip the bits of x replace x by 2 n 1 x

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.

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]: 1230186684530117755130494958384962720772 8535695953347921973224521517264005072636 5751874520219978646938995647494277406384 5925192557326303453731548268507917026122 1429134616704292143116022212404792747377 94080665351419597459856902143413

123018668453011775513049495838496272077285356959533479 219732245215172640050726365751874520219978646938995647 494277406384592519255732630345373154826850791702612214 291346167042921431160222124047927473779408066535141959 7459856902143413 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)