Integers and DivisionCS/APMA 202Rosen section 2.4Aaron Bloomfield
Rosen, chapter 2We are only doing 2 or 3 of the sections in chapter 22.4: integers and division2.6: applications of number theoryAnd only parts of that section2.7: matrices (maybe)
Quick surveyHave you seen matrices before?Lots and lots and lotsA fair amountJust a littleIs that kinda like the movie?
Why prime numbers?Prime numbers are not well understood
Basis for todays cryptography
Unless otherwise indicated, we are only talking about positive integers for this chapter
The divides operatorNew notation: 3 | 12To specify when an integer evenly divides another integerRead as 3 divides 12
The not-divides operator: 5 | 12To specify when an integer does not evenly divide another integerRead as 5 does not divide 12
Theorem on the divides operatorIf 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 cExample: if 5 | 25, then 5 | 25*c for all ints c
If a | b and b | c, then a | cExample: if 5 | 25 and 25 | 100, then 5 | 100
The book calls this Theorem 1
Prime numbersA positive integer p is prime if the only positive factors of p are 1 and pIf there are other factors, it is compositeNote that 1 is not prime!Its not composite either its 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 arithmeticEvery 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
Examples100 = 2 * 2 * 5 * 5182 = 2 * 7 * 1329820 = 2 * 2 * 3 * 5 * 7 * 71
The book calls this Theorem 2
Composite factorsIf n is a composite integer, then n has a prime divisor less than or equal to the square root of n
Direct proofSince n is composite, it has a factor a such that 1 n)Thus, n has a divisor not exceeding nThis divisor is either prime or a compositeIf the latter, then it has a prime factorIn either case, n has a prime factor less than n
The book calls this Theorem 3
Showing a number is primeShow that 113 is prime (Rosen, question 8c, 2.4)
SolutionThe only prime factors less than 113 = 10.63 are 2, 3, 5, and 7Neither of these divide 113 evenlyThus, by the fundamental theorem of arithmetic, 113 must be prime
Showing a number is compositeShow that 899 is prime (Rosen, question 8c, 2.4)
SolutionDivide 899 by successively larger primes, starting with 2We find that 29 and 31 divide 899
On a unix system, enter factor 899aaron@orion:~.16> factor 899899: 29 31
Primes are infiniteTheorem (by Euclid): There are infinitely many prime numbersThe book calls this Theorem 4
Proof by contradictionAssume there are a finite number of primesList them as follows: p1, p2 , pn.Consider the number q = p1p2 pn + 1This number is not divisible by any of the listed primesIf we divided pi into q, there would result a remainder of 1We must conclude that q is a prime number, not among the primes listed aboveThis contradicts our assumption that all primes are in the list p1, p2 , pn.
End of lecture on 17 Febrary 2005
Mersenne numbersMersenne nubmer: any number of the form 2n-1Mersenne prime: any prime of the form 2p-1, where p is also a primeExample: 25-1 = 31 is a Mersenne primeExample: 211-1 = 2047 is not a prime (23*89)Largest Mersenne prime: 224,036,583-1, which has 7,235,733 digitsIf M is a Mersenne prime, then M(M+1)/2 is a perfect numberA perfect number equals the sum of its divisorsExample: 23-1 = 7 is a Mersenne prime, thus 7*8/2 = 28 is a perfect number28 = 1+2+4+7+14Example: 25-1 = 31 is a Merenne prime, thus 31*32/2 = 496 is a perfect number
Merenne primesReference for Mersenne primes:http://mathworld.wolfram.com/MersennePrime.htmlFinding Mersenne primesGIMPS Great Internet Mersenne Prime Searchhttp://www.mersenne.org/prime.htmA new one was just discovered (last week): http://mathworld.wolfram.com/news/2005-02-18/mersenne/This is only the 42nd such prime discovered
The prime number theoremThe radio of the number of primes not exceeding x and x/ln(x) approaches 1 as x grows without boundRephrased: 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 numbersln (10200) 460The chance of a 200 digit number being prime is 1/460If we only choose odd numbers, the chance is 2/460 = 1/230This result will be used in the next lecture!
The book calls this Theorem 5
Showing a number is prime or notConsider showing that 2650-1 is primeThat number has about 200 digitsThere are approximately 10193 prime numbers less than 2650-1By 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 secondIt would take 10193/109 = 10184 secondsThats 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 compositeWe will use this in the next lecture
The division algorithmLet 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 dr = a mod d
The book calls this Theorem 6
Greatest common divisorThe greatest common divisor of two integers a and b is the largest integer d such that d | a and d | bDenoted by gcd(a,b)
Examplesgcd (24, 36) = 12gcd (17, 22) = 1gcd (100, 17) = 1
Relative primesTwo numbers are relatively prime if they dont 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
Pairwise relative primeA set of integers a1, a2, an are pairwise relatively prime if, for all pairs of numbers, they are relatively primeFormally: The integers a1, a2, an are pairwise relatively prime if gcd(ai, aj) = 1 whenever 1 i < j n.
Example: are 10, 17, and 21 pairwise relatively prime?gcd(10,17) = 1, gcd (17, 21) = 1, and gcd (21, 10) = 1Thus, they are pairwise relatively primeExample: are 10, 19, and 24 pairwise relatively prime?Since gcd(10,24) 1, they are not
More on gcdsGiven two numbers a and b, rewrite them as:Example: gcd (120, 500)120 = 23*3*5 = 23*31*51500 = 22*53 = 22*30*53Then compute the gcd by the following formula:Example: gcd(120,500) = 2min(3,2)3min(1,0)5min(1,3) = 223051 = 20
Least common multipleThe 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) = 50What is lcm (95256, 432)?95256 = 233572, 432=2433lcm (233572, 2433) = 2max(3,4)3max(5,3)7max(2,0) = 243572 = 190512
lcm and gcd theoremLet a and b be positive integers. Then a*b = gcd(a,b) * lcm (a, b)
Example: gcd (10,25) = 5, lcm (10,25) = 5010*25 = 5*50
Example: gcd (95256, 432) = 216, lcm (95256, 432) = 19051295256*432 = 216*190512
The book calls this Theorem 7
Modular arithmeticIf a and b are integers and m is a positive integer, then a is congruent to b modulo m if m divides a-bNotation: a b (mod m)Rephrased: m | a-bRephrased: a mod m = bIf they are not congruent: a b (mod m)
Example: Is 17 congruent to 5 modulo 6?Rephrased: 17 5 (mod 6)As 6 divides 17-5, they are congruentExample: Is 24 congruent to 14 modulo 6?Rephrased: 24 14 (mod 6)As 6 does not divide 24-14 = 10, they are not congruent
More on congruenceLet a and b be integers, and let m be a positive integer. Then a b (mod m) if and only if a mod m = b mod mThe book calls this Theorem 8Example: Is 17 congruent to 5 modulo 6?Rephrased: does 17 5 (mod 6)?17 mod 6 = 5 mod 6Example: Is 24 congruent to 14 modulo 6?Rephrased: 24 14 (mod 6)24 mod 6 14 mod 6
Even more on congruenceLet m be a positive integer. The integers a and b are congruent modulo m if and only if there is an integer k such that a = b + kmThe book calls this Theorem 9
Example: 17 and 5 are congruent modulo 617 = 5 + 2*65 = 17 -2*6
Even even more on congruenceLet m be a positive integer. If a b (mod m) and c d (mod m), then a+c (b+d) (mod m) and ac bd (mod m)The book calls this Theorem 10
ExampleWe know that 7 2 (mod 5) and 11 1 (mod 5)Thus, 7+11 (2+1) (mod 5), or 18 3 (mod 5)Thus, 7*11 2*1 (mod 5), or 77 2 (mod 5)
Uses of congruencesHashing functions
aaron@orion:~/ISOs/dvd.39> md5sum debian-31-i386-binary.iso 96c8bba5a784c2f48137c22e99cd5491 debian-31-i386-binary.iso
md5 (file) = mod 2128Not really this is a simplification
Todays demotivators
Pseudorandom numbersComputers cannot generate truly random numbers!
Algorithm for random numbers: choose 4 integersSeed x0: starting valueModulus m: maximum possible valueMultiplier a: such that 2 a < m Increment c: between 0 and m
Formula: xn+1 = (axn + c) mod m
Pseudorandom numbersFormula: xn+1 = (axn + c) mod mLet x0 = 3, m = 9, a = 7, and c = 4
x1 = 7x0+4 = 7*3+4 = 25 mod 9 = 7x2 = 7x1+4 = 7*7+4 = 53 mod 9 = 8x3 = 7x2+4 = 7*8+4 = 60 mod 9 = 6x4 = 7x3+4 = 7*6+4 = 46 mod 9 = 1x5 = 7x4+4 = 7*1+4 = 46 mod 9 = 2x6 = 7x5+4 = 7*2+4 = 46 mod 9 = 0x7 = 7x6+4 = 7*0+4 = 46 mod 9 = 4x8 = 7x7+4 = 7*4+4 = 46 mod 9 = 5
Pseudorandom numbersFormula: xn+1 = (axn + c) mod mLet 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, 3Note that it repeats!But it selects all the possible numbers before doing so
The common algorithms today use m = 232-1You have to choose 4 billion numbers before it repeats
The Caesar cipherJulius Caesar used this to encrypt messages
A function f to encrypt a letter is defined as: f(p) = (p+3) mod 26Where 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 cipherYou are substituting one letter with another
The Caesar cipherEncrypt go cavaliersTranslate to numbers: g = 6, o = 14, etc.Full sequence: 6, 14, 2, 0, 21, 0, 11, 8, 4, 17, 18Apply the cipher to each number: f(6) = 9, f(14) = 17, etc.Full sequence: 9, 17, 5, 3, 24, 3, 14, 11, 7, 20, 21Convert the numbers back to letters 9 = j, 17 = r, etc.Full sequence: jr wfdydolhuv
Decrypt jr wfdydolhuvTranslate to numbers: j = 9, r = 17, etc. Full sequence: 9, 17, 5, 3, 24, 3, 14, 11, 7, 20, 21Apply the cipher to each number: f-1(9) = 6, f-1(17) = 14, etc.Full sequence: 6, 14, 2, 0, 21, 0, 11, 8, 4, 17, 18Convert the numbers back to letters 6 = g, 14 = 0, etc. Full sequence: go cavaliers
Rot13 encodingA Caesar cipher, but translates letters by 13 instead of 3Then, apply the same function to decrypt it, as 13+13=26Rot13 stands for rotate by 13
Example:aaron@orion:~.4> echo Hello World | rot13Uryyb Jbeyqaaron@orion:~.5> echo Uryyb Jbeyq | rot13Hello Worldaaron@orion:~.6>
Quick surveyI felt I understood the material in this slide setVery wellWith some review, Ill be goodNot reallyNot at all
Quick surveyThe pace of the lecture for this slide set wasFastAbout rightA little slowToo slow
Quick surveyHow interesting was the material in this slide set? Be honest!Wow! That was SOOOOOO cool!Somewhat interestingRather bortingZzzzzzzzzzz
Top Related