ELEC1087: Discrete Mathematics Lecture 3, 4, 5: Numbers & Primes Lecture 3, 4, 5: Numbers & Primes Spring 2010 / Edmund Lam (based on notes by Dr Hayden So; illustrations from Rosen, Graham et al., and wikipedia) Integer functions Integer functions ` “Whole numbers constitute the backbone of discrete mathematics, and we often need to convert from fractions or arbitrary real numbers to integers.” ÚGraham, Knuth, Patashnik ` Our roadmap: ` (notation) floor and ceiling ` (notation) division and modulus ` prime, and relatively prime ` public-key cryptography PAGE 2
20
Embed
ELEC1087: Discrete Mathematicswork1807/lec03-prime.pdfELEC1087: Discrete Mathematics ... illustrations from Rosen, Graham et al., and wikipedia) Integer functions ... `Remember the
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Spring 2010 / Edmund Lam(based on notes by Dr Hayden So; illustrations from Rosen, Graham et al., and wikipedia)
Integer functionsInteger functions“Whole numbers constitute the backbone of discrete mathematics, and we often need to convert from fractions or arbitrary real numbers to integers.”
Graham, Knuth, Patashnik
Our roadmap:(notation) floor and ceiling(notation) division and modulusprime, and relatively primepublic-key cryptography
PAGE 2
Floor and Ceiling FunctionsFloor and Ceiling Functions
PAGE 3
Floor and CeilingFloor and Ceiling
3
22
1
01 2 3 4-4 -3 -2 -1
-11
-2
floor
ceiling-3
-4
PAGE 4
Properties of Floor and Ceiling 1Properties of Floor and Ceiling 1
PAGE 5
Properties of Floor and Ceiling 2Properties of Floor and Ceiling 2
Modular ArithmeticModular ArithmeticIn many discrete math problems, we only care about the remainder of an integer division.Example: Assume a bus arrives at a bus stop every 10 minutes starting at 11:00am. It takes Albert 7 minutes to get to the bus stop while it takes Betty 13 minutes. Who
ll h l h b ?will have to wait longer at the bus stop?
Show that if n | m where n >1 m >1 are integersShow that if n | m, where n >1,m >1 are integers,
and if a ≡ b (modm), where a and b are integers,
then a ≡ b (modn)
PAGE 19
Using Congruence ArithmeticUsing Congruence ArithmeticHash FunctionChecksumCryptographyyp g p y
PAGE 20
HashingHashingA many-to-one mapping between a (relatively) larger set to a smaller set
e.g. memory map, database, dictionary
The mapping function is called a hashing functionA simple hash function: h(k) = k mod m
PAGE 21
Hashing ExampleHashing ExampleFor example, we want to sort students submitted midterm into 12 boxes according to their Chinese zodiac sign (rat ox into 12 boxes according to their Chinese zodiac sign (rat, ox, tiger, rabbit, etc)Solution: First, we label box for zodiac sign rat=0, ox=1, Solution: First, we label box for zodiac sign rat 0, ox 1, tiger=2…Then the box number (b) to hold the midterm for a student born in year (y) midterm will be calculated as:
b = (y - 2008) mod 12F l id f d b i 2000 ill b For example, midterm of a student born in year 2000 will be placed at box
b = (2000 - 2008) mod 12 = 4b (2000 2008) mod 12 4Therefore, it will be at box for year of dragon
PAGE 22
ChecksumChecksumUse to verify a number (code) is valid
E HKID d UPC d ISBN d dit d t E.g. HKID card, UPC code, ISBN code, credit card, passport number, etc
ISBN-10 code has 10 digits g{a9 a8 a7 … a1 a0}
Last digit is a check digit, computed against the weighted sum of previous 9 digits with weights {10 9 8 3 2} sum of previous 9 digits, with weights {10, 9, 8, … 3, 2} such that10 a9 + 9 a8 + … + 3 a2 + 2 a1 ≡ -a0 (mod 11)9 8 2 1 0 ( )In other word, the weighted sum of all digits add up as a multiple of 11
Shift h l tt i f d i th l h b t b 3 Shift each letter in a message forward in the alphabet by 3 letters (with wrap-around)E.g “I LOVE DISCRETE MATH” becomes “L ORYH gGLVFUHWH PDWK”
Algorithm:R t h l tt b “A” = 0 “B”=1 t Represents each letter as a number “A” = 0, “B”=1, etc To encrypt a letter p, use the following function:
f (p) (p + 3) mod 26To decrypt a letter p, use the inverse function:
f (p) = (p + 3) mod 26
f −1(p) = (p − 3) mod 26
PAGE 24
Further thoughtsFurther thoughts
1. Modular arithmetic is “simple” to understand and compute.
2 Th ’ i h t t f th i d 2. There’s an inherent asymmetry: from the remainder we cannot deduce the original numbers.
3. Modular arithmetic turns out to be important in several pformulas involving prime numbers.
PAGE 25
Prime NumbersPrime NumbersPrime numbers have been studied extensively since
ancient timeAn extremely important class of numbers in modern
h i ll i h d hmath, especially with regard to cryptography
A positive integer p greater than 1 is called prime if the only positive factors of p are 1 and p
Otherwise, it is composite
PAGE 26
Division Algorithm ExampleDivision Algorithm ExampleExample A: 100 is divided by 7.Solution: We have 100 = 14(7) + 2.Therefore
i 100 di 7 14quotient = 100 div 7 = 14remainder = 100 mod 7 = 2
E l B 13 i di id d b 5Example B: -13 is divided by 5.Solution: We have -13 = -3 (5) + 2.Th fThereforequotient = -13 div 5 = -3remainder = 13 mod 5 = 2remainder = -13 mod 5 = 2
Note: remainder must be positive and smaller than the divisorthe divisor.
PAGE 27
Fundamental Theorem of ArithmeticFundamental Theorem of ArithmeticEvery positive integer greater than 1 can be written
l h d f uniquely as a prime or as the product of two or more primes where the prime factors are written in order of nondecreasing sizeof nondecreasing size.Examples:
Greatest Common DivisorGreatest Common DivisorThe greatest integer d that divides two non-zero integers
b i ll d h di i f d ba, b is called the greatest common divisor of a and bDenoted gcd(a,b)T i d b l ti l i if d( b) 1Two integers a and b are relatively prime if gcd(a,b) = 1Example
Least Common MultipleLeast Common MultipleThe least common multiple (LCM) of the integers a and bis the smallest positive integer that is divisible by both aand b.For example, lcm(12,15) = 60
For two positive integers a and b,ab = gcd(a,b) × lcm(a,b)
PAGE 34
The Euclidean Algorithm (1)The Euclidean Algorithm (1)To find the gcd of 2 integersBased on the following observation:Based on the following observation:
Proof:
PAGE 35
The Euclidean Algorithm (2)The Euclidean Algorithm (2)To find gcd(a,b):Let x := max(a,b), y := min(a,b)while y ≠ 0b ibegin
r := x mod yx := yx := yy := r
endendIn other words, divide the larger number x with the smaller one y to get remainder r. Then set y to be smaller one y to get remainder r. Then set y to be the bigger number, and r be the smaller number, and repeat the division until the remainder is 0p
P bli k t h C Public-key cryptography: Can we communicate a secret message in the open?
Yes with the discrete math we know!Yes—with the discrete math we know!
PAGE 38
Public key: an examplePublic-key: an exampleGreen = public Red = secret
Alice and Bob agrees prime p=23 and base g=5
Alice’s secret integer: a=6. Alice sends Bob: A=56 mod 23=8
Bob’s secret integer: b=15. Bob sends Alice: B=515 mod 23=19
Alice computes s=196 mod 23=2
Bob computes s=815 mod 23=2
Alice and Bob know 2, but Eve doesn’t!Eve
Use it as the private keythereafter
Magic?
PAGE 39
Alice Bob
Public key: an examplePublic-key: an exampleRequirements:
p is a primeg is a primitive root mod p (we did not discuss what this means, but you can look up the web)you can look up the web)
Calculations:A = ga mod pA g mod pB = gb mod ps = Ab mod p = gab mod p = gba mod p = Ba mod pp g p g p p
Key insight—the Discrete Logarithm Problem:Given A, g, p: difficult to calculate a. Need big prime number p (~ several hundred digits), and big a,bg needs not be big, e.g. 2 or 5