CS 202 Epp section ?? Aaron Bloomfield

Slides:



Advertisements
Similar presentations
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.
Advertisements

The Integers and Division. Outline Division: Factors, multiples Exercise 2.3 Primes: The Fundamental Theorem of Arithmetic. The Division Algorithm Greatest.
CSE115/ENGR160 Discrete Mathematics 03/15/12
5.1 Number Theory. The study of numbers and their properties. The numbers we use to count are called the Natural Numbers or Counting Numbers.
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.
February 19, 2015Applied Discrete Mathematics Week 4: Number Theory 1 The Growth of Functions Question: If f(x) is O(x 2 ), is it also O(x 3 )? Yes. x.
22C:19 Discrete Math Integers and Modular Arithmetic Fall 2010 Sukumar Ghosh.
CSE115/ENGR160 Discrete Mathematics 03/13/12 Ming-Hsuan Yang UC Merced 1.
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.
CSE 321 Discrete Structures Winter 2008 Lecture 8 Number Theory: Modular Arithmetic.
1 Integers and Division CS/APMA 202 Rosen section 2.4 Aaron Bloomfield.
CSE 311 Foundations of Computing I Lecture 12 Primes, GCD, Modular Inverse Spring
Fall 2002CMSC Discrete Structures1 Let us get into… Number Theory.
The Integers and Division
Section 5.1 Number Theory.
Integers Number Theory = Properties of Integers
CSCI 1900 Discrete Structures
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 3 (Part 2): The Fundamentals: Algorithms, the.
Chapter 2 The Fundamentals: Algorithms, the Integers, and Matrices
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.
CSE 504 Discrete Mathematics & Foundations of Computer Science
MATH 224 – Discrete Mathematics
The Integers & Division. a divides b if a is not zero there is a m such that a.m = b “a is a factor of b” “b is a multiple of a” a|b Division.
Chapter The Integers and Division Division
CompSci 102 Discrete Math for Computer Science
Copyright © Zeph Grunschlag, Basic Number Theory Zeph Grunschlag.
Dr-Zaguia-CSI2101-W081 Introduction to Number Theory Let a,b  Z with a  0. a|b  “a divides b” :  (  c  Z: b=ac) “There is an integer c such that.
Chapter 2 (Part 1): The Fundamentals: Algorithms, the Integers & Matrices The Integers and Division (Section 2.4)
CSE 311: Foundations of Computing Fall 2014 Lecture 12: Primes, GCD.
Chapter 4 With Question/Answer Animations. Section 4.1.
The Fundamentals. Algorithms What is an algorithm? An algorithm is “a finite set of precise instructions for performing a computation or for solving.
Module #9 – Number Theory 1/5/ Algorithms, The Integers and Matrices.
Greatest Common Divisors & Least Common Multiples  Definition 4 Let a and b be integers, not both zero. The largest integer d such that d|a and d|b is.
AF2. Turn off your phones Primes, gcd, some examples, reading.
Basic Number Theory.
Discrete Mathematics
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,
The Fundamentals: Algorithms, Integers, and Matrices CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Chapter 4 With Question/Answer Animations 1. Chapter Summary Divisibility and Modular Arithmetic - Sec 4.1 – Lecture 16 Integer Representations and Algorithms.
Ch04-Number Theory and Cryptography 1. Introduction to Number Theory Number theory is about integers and their properties. We will start with the basic.
Module #9 – Number Theory 6/11/20161 Chapter 3 Algorithms, Integers and Matrices.
Number Theory Lecture 1 Text book: Discrete Mathematics and its Applications, 7 th Edition.
Chapter 3 The Fundamentals: Algorithms, the integers, and matrices Section 3.4: The integers and division Number theory: the part of mathematics involving.
Agenda Review:  Relation Properties Lecture Content:  Divisor and Prime Number  Binary, Octal, Hexadecimal Review & Exercise.
Number Theory. Introduction to Number Theory Number theory is about integers and their properties. We will start with the basic principles of divisibility,
CS 210 Discrete Mathematics The Integers and Division (Section 3.4)
Divisibility and Primes
CSE15 Discrete Mathematics 03/20/17
Integers and Division Section 3.4.
Chapter 5: Number Theory
Thinking Critically 4.1 Divisibility Of Natural Numbers
CSE 311 Foundations of Computing I
MATH301- DISCRETE MATHEMATICS Copyright © Nahid Sultana Dr. Nahid Sultana Chapter 4: Number Theory and Cryptography.
Applied Discrete Mathematics Week 3: Algorithms
Applied Discrete Mathematics Week 4: Number Theory
Number Theory (Chapter 7)
Number Theory.
Discrete Math for CS CMPSC 360 LECTURE 12 Last time: Stable matching
Copyright © Zeph Grunschlag,
Divisibility and Modular Arithmetic
Applied Discrete Mathematics Week 10: Introduction to Counting
Number Theory.
From the last time: gcd(a, b) can be characterized in two different ways: It is the least positive value of ax + by where x and y range over integers.
Sets, Combinatorics, Probability, and Number Theory
Presentation transcript:

CS 202 Epp section ?? Aaron Bloomfield Integers and Division CS 202 Epp section ?? Aaron Bloomfield

Why prime numbers? Prime numbers are not well understood Basis for today’s cryptography Unless otherwise indicated, we are only talking about positive integers for this chapter

The divides operator New notation: 3 | 12 To specify when an integer evenly divides another integer Read as “3 divides 12” The not-divides operator: 5 | 12 To specify when an integer does not evenly divide another integer Read as “5 does not divide 12”

Theorem on the divides operator If a | b and a | c, then a | (b+c) Example: if 5 | 25 and 5 | 30, then 5 | (25+30) If a | b, then a | bc for all integers c Example: if 5 | 25, then 5 | 25*c for all ints c If a | b and b | c, then a | c Example: if 5 | 25 and 25 | 100, then 5 | 100

Prime numbers A positive integer p is prime if the only positive factors of p are 1 and p If there are other factors, it is composite Note that 1 is not prime! It’s not composite either – it’s in its own class An integer n is composite if and only if there exists an integer a such that a | n and 1 < a < n

Fundamental theorem of arithmetic Every positive integer greater than 1 can be uniquely written as a prime or as the product of two or more primes where the prime factors are written in order of non-decreasing size Examples 100 = 2 * 2 * 5 * 5 182 = 2 * 7 * 13 29820 = 2 * 2 * 3 * 5 * 7 * 71

Composite factors If n is a composite integer, then n has a prime divisor less than or equal to the square root of n Strong inductive proof using the following logic: Since n is composite, it has a factor a such that 1<a<n Thus, n = ab, where a and b are positive integers greater than 1 Either a≤n or b≤n (Otherwise, ab > n*n > n) Thus, n has a divisor not exceeding n This divisor is either prime or a composite If the latter, then it has a prime factor In either case, n has a prime factor less than n

Showing a number is prime Show that 113 is prime Solution The only prime factors less than 113 = 10.63 are 2, 3, 5, and 7 Neither of these divide 113 evenly Thus, by the fundamental theorem of arithmetic, 113 must be prime

Showing a number is composite Show that 899 is prime Solution Divide 899 by successively larger primes (up to 899 = 29.98), starting with 2 We find that 29 and 31 divide 899 On a unix system, enter “factor 899” aaron@orion:~.16> factor 899 899: 29 31

Primes are infinite Theorem (by Euclid): There are infinitely many prime numbers Proof by contradiction Assume there are a finite number of primes List them as follows: p1, p2 …, pn. Consider the number q = p1p2 … pn + 1 This number is not divisible by any of the listed primes If we divided pi into q, there would result a remainder of 1 We must conclude that q is a prime number, not among the primes listed above This contradicts our assumption that all primes are in the list p1, p2 …, pn.

The prime number theorem The radio of the number of primes not exceeding x and x/ln(x) approaches 1 as x grows without bound Rephrased: the number of prime numbers less than x is approximately x/ln(x) Rephrased: the chance of an number x being a prime number is 1 / ln(x) Consider 200 digit prime numbers ln (10200)  460 The chance of a 200 digit number being prime is 1/460 If we only choose odd numbers, the chance is 2/460 = 1/230 This result will be used in the next lecture!

Showing a number is prime or not Consider showing that 2650-1 is prime That number has about 200 digits There are approximately 10193 prime numbers less than 2650-1 By theorem 5 (x/ln(x), where x = 2650-1) How long would that take to test each of those prime numbers? Assume a computer can do 1 billion (109) per second It would take 10193/109 = 10184 seconds That’s 3.2 * 10176 years! There are quicker methods to show a number is prime, but not to find the factors if the number is found to be composite We will use this in the next lecture

The division “algorithm” Let a be an integer and d be a positive integer. Then there are unique integers q and r, with 0 ≤ r < d, such that a = dq+r We then define two operators: q = a div d r = a mod d

Greatest common divisor The greatest common divisor of two integers a and b is the largest integer d such that d | a and d | b Denoted by gcd(a,b) Examples gcd (24, 36) = 12 gcd (17, 22) = 1 gcd (100, 17) = 1

Relative primes Two numbers are relatively prime if they don’t have any common factors (other than 1) Rephrased: a and b are relatively prime if gcd (a,b) = 1 gcd (25, 39) = 1, so 25 and 39 are relatively prime

More on gcd’s Given two numbers a and b, rewrite them as: Example: gcd (120, 500) 120 = 23*3*5 = 23*31*51 500 = 22*53 = 22*30*53 Then compute the gcd by the following formula: Example: gcd(120,500) = 2min(3,2)3min(1,0)5min(1,3) = 223051 = 20

Least common multiple The least common multiple of the positive integers a and b is the smallest positive integer that is divisible by both a and b. Denoted by lcm (a, b) Example: lcm(10, 25) = 50 What is lcm (95256, 432)? 95256 = 233572, 432=2433 lcm (233572, 2433) = 2max(3,4)3max(5,3)7max(2,0) = 243572 = 190512

lcm and gcd theorem Let a and b be positive integers. Then a*b = gcd(a,b) * lcm (a, b) Example: gcd (10,25) = 5, lcm (10,25) = 50 10*25 = 5*50 Example: gcd (95256, 432) = 216, lcm (95256, 432) = 190512 95256*432 = 216*190512

End of lecture on 21 March 2007

Pseudorandom numbers Computers cannot generate truly random numbers! Algorithm for “random” numbers: choose 4 integers Seed x0: starting value Modulus m: maximum possible value Multiplier a: such that 2 ≤ a < m Increment c: between 0 and m Formula: xn+1 = (axn + c) mod m

Pseudorandom numbers Formula: xn+1 = (axn + c) mod m Let x0 = 3, m = 9, a = 7, and c = 4 x1 = 7x0+4 = 7*3+4 = 25 mod 9 = 7 x2 = 7x1+4 = 7*7+4 = 53 mod 9 = 8 x3 = 7x2+4 = 7*8+4 = 60 mod 9 = 6 x4 = 7x3+4 = 7*6+4 = 46 mod 9 = 1 x5 = 7x4+4 = 7*1+4 = 46 mod 9 = 2 x6 = 7x5+4 = 7*2+4 = 46 mod 9 = 0 x7 = 7x6+4 = 7*0+4 = 46 mod 9 = 4 x8 = 7x7+4 = 7*4+4 = 46 mod 9 = 5

Pseudorandom numbers Formula: xn+1 = (axn + c) mod m Let x0 = 3, m = 9, a = 7, and c = 4 This sequence generates: 3, 7, 8, 6, 1, 2, 0, 4, 5, 3 , 7, 8, 6, 1, 2, 0, 4, 5, 3 Note that it repeats! But it selects all the possible numbers before doing so The common algorithms today use m = 232-1 You have to choose 4 billion numbers before it repeats

The Caesar cipher Julius Caesar used this to encrypt messages A function f to encrypt a letter is defined as: f(p) = (p+3) mod 26 Where p is a letter (0 is A, 1 is B, 25 is Z, etc.) Decryption: f-1(p) = (p-3) mod 26 This is called a substitution cipher You are substituting one letter with another

The Caesar cipher Encrypt “go cavaliers” Decrypt “jr wfdydolhuv” Translate to numbers: g = 6, o = 14, etc. Full sequence: 6, 14, 2, 0, 21, 0, 11, 8, 4, 17, 18 Apply the cipher to each number: f(6) = 9, f(14) = 17, etc. Full sequence: 9, 17, 5, 3, 24, 3, 14, 11, 7, 20, 21 Convert the numbers back to letters 9 = j, 17 = r, etc. Full sequence: jr wfdydolhuv Decrypt “jr wfdydolhuv” Translate to numbers: j = 9, r = 17, etc. Apply the cipher to each number: f-1(9) = 6, f-1(17) = 14, etc. Convert the numbers back to letters 6 = g, 14 = 0, etc. Full sequence: go cavaliers

Rot13 encoding A Caesar cipher, but translates letters by 13 instead of 3 Then, apply the same function to decrypt it, as 13+13=26 Rot13 stands for “rotate by 13” Example: aaron@gemini:~.98> echo darth vader is luke skywalkers father | rot13 qnegu inqre vf yhxr fxljnyxref sngure aaron@gemini:~.99> echo qnegu inqre vf yhxr fxljnyxref sngure | rot13 darth vader is luke skywalkers father aaron@gemini:~.100>