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

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

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

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

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?

CSE 20 DISCRETE MATH. Winter

CPSC 467: Cryptography and Computer Security

CHAPTER 3. Congruences. Congruence: definitions and properties

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

MATH 115, SUMMER 2012 LECTURE 4 THURSDAY, JUNE 21ST

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

Number theory (Chapter 4)

Math 31 Lesson Plan. Day 5: Intro to Groups. Elizabeth Gillaspy. September 28, 2011

#26: Number Theory, Part I: Divisibility

Math 13, Spring 2013, Lecture B: Midterm

base 2 4 The EXPONENT tells you how many times to write the base as a factor. Evaluate the following expressions in standard notation.

Applied Cryptography and Computer Security CSE 664 Spring 2017

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

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

Elementary Properties of the Integers

Algorithmic number theory. Questions/Complaints About Homework? The division algorithm. Division

Applied Cryptography and Computer Security CSE 664 Spring 2018

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

CSE 20 DISCRETE MATH. Winter

2 Elementary number theory

Topic Contents. Factoring Methods. Unit 3: Factoring Methods. Finding the square root of a number

Cool Results on Primes

Contradiction MATH Contradiction. Benjamin V.C. Collins, James A. Swenson MATH 2730

Lecture 6: Introducing Complexity

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

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

Math 109 HW 9 Solutions

Fibonacci mod k. In this section, we examine the question of which terms of the Fibonacci sequence have a given divisor k.

1. Algebra 1.7. Prime numbers

Discrete Mathematics and Probability Theory Summer 2014 James Cook Note 5

Lecture 11 - Basic Number Theory.

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

Ma/CS 6a Class 4: Primality Testing

Algorithms: Review from last time

You separate binary numbers into columns in a similar fashion. 2 5 = 32

Clock Arithmetic and Euclid s Algorithm

Today we are going to have fun with integers, primes, fractions and infinite series. Turn the page if interested!

Announcements. CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis. Today. Mathematical induction. Dan Grossman Spring 2010

Continuing discussion of CRC s, especially looking at two-bit errors

Math 31 Lesson Plan. Day 2: Sets; Binary Operations. Elizabeth Gillaspy. September 23, 2011

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

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

HOW TO WRITE PROOFS. Dr. Min Ru, University of Houston

Math Lecture 23 Notes

3.2 Solving linear congruences. v3

Introduction to Cryptology. Lecture 20

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

5 + 9(10) + 3(100) + 0(1000) + 2(10000) =

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

Factoring. Number Theory # 2

Discrete Mathematics and Probability Theory Summer 2017 Course Notes Note 6

What Every Programmer Should Know About Floating-Point Arithmetic DRAFT. Last updated: November 3, Abstract

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

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

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Matroids and Greedy Algorithms Date: 10/31/16

1. Prove that the number cannot be represented as a 2 +3b 2 for any integers a and b. (Hint: Consider the remainder mod 3).

An Algorithm for Prime Factorization

For your quiz in recitation this week, refer to these exercise generators:

CS483 Design and Analysis of Algorithms

Modular Arithmetic Investigation

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

Fermat's Little Theorem

The Basics COPYRIGHTED MATERIAL. chapter. Algebra is a very logical way to solve

Prob. 1 Prob. 2 Prob. 3 Total

Algebra. Here are a couple of warnings to my students who may be here to get a copy of what happened on a day that you missed.

What is proof? Lesson 1

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

Algorithms (II) Yu Yu. Shanghai Jiaotong University

Modern Algebra Prof. Manindra Agrawal Department of Computer Science and Engineering Indian Institute of Technology, Kanpur

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

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.

Discrete Structures for Computer Science

Ma/CS 6a Class 4: Primality Testing

Lecture 2. The Euclidean Algorithm and Numbers in Other Bases

CPSC 467b: Cryptography and Computer Security

* 8 Groups, with Appendix containing Rings and Fields.

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

Modular Arithmetic Instructor: Marizza Bailey Name:

CSE 20 DISCRETE MATH. Fall

Theme : Cryptography. Instructor : Prof. C Pandu Rangan. Speaker : Arun Moorthy CS

CS March 17, 2009

Math 308 Midterm Answers and Comments July 18, Part A. Short answer questions

Cambridge University Press How to Prove it: A Structured Approach: Second edition Daniel J. Velleman Excerpt More information

MODULAR ARITHMETIC KEITH CONRAD

CSE 311 Lecture 28: Undecidability of the Halting Problem. Emina Torlak and Kevin Zatloukal

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

ICS141: Discrete Mathematics for Computer Science I

Lecture 2: Period Three Implies Chaos

A field F is a set of numbers that includes the two numbers 0 and 1 and satisfies the properties:

1 Reductions and Expressiveness

Chapter 14: Divisibility and factorization

CSE 20: Discrete Mathematics

FERMAT S TEST KEITH CONRAD

1 Overview and revision

I will update this document after every lecture to keep track of what we covered. Textbook refers to the book by Diane Herrmann and Paul Sally.

Proof by Contradiction

Transcription:

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

HW 3 De-Brief

HW 3 De-Brief PROOFS!

HW 3 De-Brief Proofs This is hard This is foreign You didn t tell me exactly what to do I don t think I deserved to lose these points!

HW 3 De-Brief Think back to when you wrote your first essay.

HW 3 De-Brief If your HW 3 score is in this range 70% 85% 100% Schedule an appointment with Adam today. Not tomorrow; today. There is something very important you didn t understand. If you aren t 100% on every comment you got by tomorrow, schedule an appointment with Adam. Great Work! Read all your feedback. 23% 33% 44%

HW 3 De-Brief If your HW 3 score is in this range 70% 85% 100% Schedule an appointment with Adam today. Not tomorrow; today. There is something very important you didn t understand. If you aren t 100% on every comment you got by tomorrow, schedule an appointment with Adam. Great Work! Read all your feedback. 23% 33% 44%

HW 3 De-Brief Okay, I got it. How do I schedule an appointment? Go to http://meeting.countablethoughts.com If I don t respond by Monday, then it probably didn t go through; so, e-mail me.

HW 3 De-Brief How I Oops 311 Never read the feedback, or

HW 3 De-Brief How I Oops 311 Never read the feedback, or Read the feedback but don t take it seriously, or

HW 3 De-Brief How I Oops 311 Never read the feedback, or Read the feedback but don t take it seriously, or Read the feedback but convince yourself that you get it now, or

HW 3 De-Brief How I Oops 311 Never read the feedback, or Read the feedback but don t take it seriously, or Read the feedback but convince yourself that you get it now, or Read the feedback, talk to a TA, but don t apply what you ve learned to future HWs, or

HW 3 De-Brief How smart you are and your grade are not the same thing.

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

Example Let n be an integer. Prove that n 2 0 (mod 4) or n 2 1 (mod 4) Case 1 (n is even): Let s start by looking a a small example: 0 2 = 0 0 (mod 4) 1 2 = 1 1 (mod 4) 2 2 = 4 0 (mod 4) 3 2 = 9 1 (mod 4) 4 2 = 16 0 (mod 4) Case 2 (n is odd): It looks like n 0 (mod 2) n 2 0 (mod 4), and n 1 (mod 2) n 2 1 (mod 4).

Example Let n be an integer. Prove that n 2 0 (mod 4) or n 2 1 (mod 4) Case 1 (n is even): Suppose n 0 (mod 2). Then, n = 2k for some k. So, n 2 = (2k) 2 = 4k 2. So, by definition of congruence, n 2 0 (mod 4). Case 2 (n is odd): Suppose n 1 (mod 2). Then, n = 2k + 1 for some k. So, n 2 = (2k + 1) 2 = 4k 2 + 4k + 1 = 4(k 2 + k) + 1. by definition of congruence, n 2 1 (mod 4). Let s start by looking a a small example: 0 2 = 0 0 (mod 4) 1 2 = 1 1 (mod 4) 2 2 = 4 0 (mod 4) 3 2 = 9 1 (mod 4) 4 2 = 16 0 (mod 4) It looks like n 0 (mod 2) n 2 0 (mod 4), and n 1 (mod 2) n 2 1 (mod 4). So,

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

Euclid s Theorem There are an infinite number of primes. Proof by contradiction: Suppose that there are only a finite number of primes: p ", p $,, p &

Euclid s Theorem There are an infinite number of primes. Proof by contradiction: Suppose that there are only a finite number of primes: p ", p $,, p & Suppose for contradiction that there are n primes for some natural number n. Call them p 1 < p 2 < < p n. Consider P = p 1 p 2 p n, and define Q = P + 1. Case 1 (Q is prime). Then, we re done, because Q is larger than any of the primes; so, it is a new prime. Case 2 (Q is composite). Then, there must be some prime p such that p Q. Note that since P divides every possible prime, p P as well. It follows that p (Q P) p ((P + 1) P) p 1. This is impossible, because p must be at least two. Since both cases lead to a contradiction, the original claim is true.

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]: 123018668453011775513049495838496272077 285356959533479219732245215172640050726 365751874520219978646938995647494277406 384592519255732630345373154826850791702 612214291346167042921431160222124047927 4737794080665351419597459856902143413

12301866845301177551304949583849627207728535695953347 92197322452151726400507263657518745202199786469389956 47494277406384592519255732630345373154826850791702612 21429134616704292143116022212404792747377940806653514 19597459856902143413 334780716989568987860441698482126908177047949837 137685689124313889828837938780022876147116525317 43087737814467999489 367460436667995904282446337996279526322791581643 430876426760322838157396665112792333734171433968 10270092798736308917

Factoring Okay. Fun I guess It turns out this is hard. Why should I care?

Factoring We can use ( abuse ) the fact that factoring is difficult for security.

Large Numbers But Test.java:3: error: integer number too large: 12345678901234567890 long x = 12345678901234567890; ^ 1 error Thanks Java 367460436667995904282446337996279526322791581643 430876426760322838157396665112792333734171433968 10270092798736308917 How do we store large numbers?

Large Non-negative Integer Representation String 12345 & 2 d 4 10 4 45+ Sum 5 10 + + 4 10 " + 3 10 $ + 2 10 0 + 1 10 1 List [5, 4, 3, 2, 1]

Large Non-negative Integer Representation String 11000000111001 & 2 b 4 2 4 45+ Sum 1 2 + + 0 2 " + 0 2 $ + 1 2 0 + 1 2 1 + 1 2 7 + 0 2 8 + 0 2 9 + 0 2 : + 0 2 ; + 0 2 "+ + 0 2 "" + 1 2 "$ + 1 2 "0 List [1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1]

Large Non-negative Integer Operations MOD M Just like before, we will consider these operations mod another number. This turns out to be more general and more useful. So, instead of (a + b), we ll look at (a + b) mod m

Large Non-negative Integer Operations MOD M Addition [0, 0, 1, 1] + [1, 0, 0, 1] --------------- [1, 0, 1, 0, 1] and then we mod by m at the end. Hey! This looks familiar! Multiplication This was HW, right? and then we mod by m at the end.

Large Non-negative Integer Operations MOD M Subtraction? Let s borrow from circuit design (again). How does subtraction mod 2^32 work?

Two s Complement Representation For, x is represented by the binary representation of ~x = 2 & 1 x ~x + 1 = 2 & 1 x + 1 = 2 & x = x [0, 0, 1, 1] - [1, 0, 0, 1] ---------------??????????????? ~ [1, 0, 0, 1] --------------- [0, 1, 1, 0] + [1] --------------- [1, 1, 1, 0]

Two s Complement Representation [0, 0, 1, 1] - [1, 0, 0, 1] ---------------??????????????? 0 2 + + 0 2 " + 1 2 $ + 1 2 0 = 12 1 2 + + 0 2 " + 0 2 $ + 1 2 0 = 9 ~ [1, 0, 0, 1] ------------ [0, 1, 1, 0] + [1] ------------ [1, 1, 1, 0] [0, 0, 1, 1] + [1, 1, 1, 0] --------------- [1, 1, 0, 0, 1] 0 2 + + 0 2 " + 1 2 $ + 1 2 0 = 12 1 2 + + 1 2 " + 1 2 $ + 0 2 0 = 7 1 2 + + 1 2 " + 0 2 $ + 0 2 0 = 3

Large Non-negative Integer Operations MOD M Division? This is weird. We ll come back to it next lecture.

Large Non-negative Integer Operations MOD M Exponentiation? 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

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 Exponentiation Algorithm 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 & mod m using O(log n) multiplications mod m

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;

P.S.: Pseudo-Random Number Generation Linear Congruential method x &N" = a x & + c mod m Choose random x +, a, c, m and produce a long sequence of x & s (Lagged Fibonacci Generator, Mersenne Twister...)