100 likes | 107 Views
Explore congruences, Chinese Remainder Theorem, & modular exponents. Solve equations, find solutions, & compute remainders with examples. Learn how to code these algorithms efficiently.
E N D
DTTF/NB479: Dszquphsbqiz Day 10 • Announcements: • Homework 2 due now • Quiz this Friday on concepts from chapter 2 • Practical quiz next week on breaking codes from chapter 2 • Questions? • Today: • Congruences • Chinese Remainder Theorem • Modular Exponents
How to find x and y? x and y swapped from book, which assumes that a < b on p. 69 Assume a > b Let qi and ri be the series of quotients and remainders, respectively, found along the way. a = q1b + r1 b = q2r1 + r2 r1 = q3r2 + r3 ... ri-2 = qiri-1 + ri rk-2 = qkrk-1 + rk rk-1 = qk+1rk To find x, take x0 = 1, x1 = 0, xj = xj-2 – qj-1xj-1 To find y, take y0 = 0, y1 = 1, yj = yj-2 – qj-1yj-1 Use to calculate xk and yk (the desired result) Example: gcd(5862,1856)=2 Yields x = -101, y = 319 Check: 5862(-101) + 1856(319) = 2?
Congruence Properties • Properties
Solving Congruences • Solve. Check with a partner.
Solving ax=b(mod n) when gcd(a,n)~=1 Example: 10x=4(mod 10) Other examples: • Let gcd(a,n)=d • If d doesn’t divide b then no solution • Else divide everything by d and solve(a/d)x=(b/d)(mod (n/d)) • Get solution x0 • Multiple solutions:x0, x0+n/d,x0+2n/d,…x0+(d-1)n/d • This is an easy program to code once you have Euclid…
Chinese Remainder Theorem • Equivalence between a single congruence mod a composite number and a system of congruences mod its factors • Two-factor form • Given gcd(m,n)=1. For integers a and b, there exists exactly 1 solution (mod mn) to the system:
Chinese Remainder Theorem • Solve: • How many solutions? • Find them.
Chinese Remainder Theorem • n-factor form • Let m1, m2,… mk be integers such that gcd(mi, mj )=1 when i ~= j. For integers a1, … ak, there exists exactly 1 solution (mod m1m2…mk) to the system:
Modular Exponentiation • Compute last digit of 3^2000 • Compute 3^2000 (mod 152) • Technique: • Repeatedly square 3, but take mod at each step. • Matlab’s powermod()