Download presentation
Presentation is loading. Please wait.
1
Announcements: Homework 1 returned. Comments from Kevin? Homework 1 returned. Comments from Kevin? Matlab: tutorial available at http://www.math.ufl.edu/help/matlab-tutorial/ Matlab: tutorial available at http://www.math.ufl.edu/help/matlab-tutorial/ http://www.math.ufl.edu/help/matlab-tutorial/ Homework 2 due Tuesday Homework 2 due Tuesday Quiz this Friday on concepts from chapter 2 (tentative) Quiz this Friday on concepts from chapter 2 (tentative) Practical quiz next week on breaking codes from chapter 2 Practical quiz next week on breaking codes from chapter 2Questions?Today: Euclid’s algorithm Euclid’s algorithm Congruences if time Congruences if time DTTF/NB479: DszquphsbqizDay 9
2
Basics 1: Divisibility Definition: Property 1: Property 2 (transitive): Property 3 (linear combinations):
3
Basics 2: Primes Any integer p > 1 divisible by only p and 1. How many are there? Prime number theorem: Let (x) be the number of primes less than x. Let (x) be the number of primes less than x. Then Then Application: how many 319-digit primes are there? Application: how many 319-digit primes are there? Every positive integer is a unique product of primes. Every positive integer is a unique product of primes.
4
Basics: 3. GCD gcd(a,b)=max j (j|a and j|b). Def.: a and b are relatively prime iff gcd(a,b)=1 gcd(14,21) easy… What about gcd(1856, 5862)? gcd(500267500347832384769, 12092834543475893256574665)? Do you really want to factor each one? What’s our alternative?
5
Euclid’s Algorithm gcd(a,b) { if (a < b) swap (a,b) // a > b r = a % b while (r ~= 0) { a = b b = r r = a % b } gcd = b // last r ~= 0 } Calculate gcd(1856, 5862) =2
6
Euclid’s Algorithm gcd(a,b) { if (a > b) swap (a,b) // a > b r = a % b while (r ~= 0) { a = b b = r r = a % b } gcd = b // last r ~= 0 } Assume a > b Let q i and r i be the series of quotients and remainders, respectively, found along the way. a = q 1 b + r 1 b = q 2 r 1 + r 2 r 1 = q 3 r 2 + r 3... r i-2 = q i r i-1 + r i r k-2 = q k r k-1 + r k r k-1 = q k+1 r k You’ll prove this computes the gcd in Homework 3 (by induction)… r k is gcd(a,b)
7
Fundamental result: If d = gcd(a,b) then ax + by = d For some integers x and y. These ints are just a by-product of the Euclidean algorithm! Allows us to find a -1 (mod n) very quickly… Choose b = n and d = 1. Choose b = n and d = 1. If gcd(a,n) =1, then ax + ny = 1 If gcd(a,n) =1, then ax + ny = 1 ax = 1 (mod n) because it differs from 1 by a multiple of n ax = 1 (mod n) because it differs from 1 by a multiple of n Therefore, x = a -1 (mod n). Therefore, x = a -1 (mod n). Why does this work? How do we find x and y?
8
Why does this work? Given a,b ints, not both 0, and gcd(a,b) = d. Prove ax + by = d Recall gcd(a,b,)=d = r k is the last non-zero remainder found via Euclid. We’ll show the property true for all remainders r j (by strong induction) Assume a > b Let q i and r i be the series of quotients and remainders, respectively, found along the way. a = q 1 b + r 1 b = q 2 r 1 + r 2 r 1 = q 3 r 2 + r 3... r i-2 = q i r i-1 + r i r k-2 = q k r k-1 + r k r k-1 = q k+1 r k
9
How to find x and y? To find x, take x 0 = 1, x 1 = 0, x j = x j-2 – q j-1 x j-1 To find y, take y 0 = 0, y 1 = 1, y j = y j-2 – q j-1 y j-1 Use to calculate x k and y k (the desired result) Example:gcd(5862,1856)=2 Yields x = -101, y = 319 Assume a > b Let q i and r i be the series of quotients and remainders, respectively, found along the way. a = q 1 b + r 1 b = q 2 r 1 + r 2 r 1 = q 3 r 2 + r 3... r i-2 = q i r i-1 + r i r k-2 = q k r k-1 + r k r k-1 = q k+1 r k x and y swapped from book, which assumes that a < b on p. 69 Check: 5862(-101) + 1856(319) = 2?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.