DTTF/NB479: Dszquphsbqiz Day 8 Announcements: Please use pencil on quizzes if possible Questions? Today: Congruences Chinese Remainder Theorem Modular Exponents
Hill Cipher implementation Encryption Easy to do in MATLAB. Or find/write a matrix library for language X. Decryption Uses matrix inverse. How do we determine if a matrix is invertible mod 26?
How to break via known plaintext? Good work on last session’s quiz. Idea: Assume you know the matrix size, n. Then grab n sets of n plaintext chars ciphertext This gives n 2 equations and n 2 unknowns. Then solve using basic linear algebra, but mod n. Caveat: sometimes it doesn’t give a unique solution, so you need to choose a different set of plaintext. Hmm. This could make a nice exam problem…
Substitution ciphers Each letter in the alphabet is always replaced by another one. Which ciphers have we seen are substitution ciphers? Which aren’t and why? Breaking ciphertext only uses linguistic structure. Frequencies of: Single letters Digrams (2-letter combinations) Trigrams Where do T&W get their rules like “80% of letters preceding n are vowels”? (p. 26) See http://keithbriggs.info/documents/english_latin.pdf Lots of trial and error when done by hand. Could automate with a dictionary.
Fairy Tales HTTP :// XKCD . COM /872/ Goldilocks’ discovery of Newton’s method of approximation required surprisingly few changes.
Basics 4: Congruence Def: a≡b (mod n) iff (a-b) = nk for some int k Properties ∈ ≠ ≡ ≡ , , , , 0 , (mod ), Consider a b c d Z n If a b c d n then ≡ ∃ ∈ = + + ≡ + (mod ) . . ( ) ( )(mod ) a b n if k Z s t a b nk a c b d n ≡ − ≡ − 0 (mod ) | ( ) ( )(mod ) a n iff n a a c b d n ≡ ≡ (mod ) (mod ) a a n ac bd n ≡ ≡ = ≡ (mod ) (mod ) gcd( , ) 1 (mod ), a b n iff b a n If a n and ab ac n then ≡ ≡ ⇒ ≡ ≡ , (mod ) (mod ) (mod ) a b b c n a c n b c n You can easily solve congruences ax≡b (mod n) if gcd(a,n) = 1. For small numbers, do by hand For larger numbers, compute a -1 using Euclid
1-2 Solving ax≡b (mod n) when gcd(a,n )≠1 Let gcd(a,n)=d Example: 2x ≡ 7(mod 10 ) If d doesn’t divide b then no solution Else divide everything by d Example: and solve 3x ≡ 3 (mod 6) (a/d)x=(b/d)(mod (n/d)) Get solution x 0 Multiple solutions: x 0 , x 0 +n/d,x 0 +2n/d,…x 0 +(d-1)n/d Always write solution with the original modulus This is an easy program to code once you have Euclid…
How could we write x ≡ 16 (mod 35) as a system of congruences with smaller moduli?
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: ≡ (mod ) x a m ≡ (mod ) x b n
3-4 CRT Equivalences let us use systems of congruences to solve problems ≡ 3 (mod 7 ) x Solve the system: ≡ 5 (mod 15 ) x How many solutions? 2 ≡ 1 (mod 35 ) x Find them.
Chinese Remainder Theorem n-factor form Let m 1 , m 2 ,… m k be integers such that gcd(m i , m j )=1 when i ≠ j. For integers a 1 , … a k , there exists exactly 1 solution (mod m 1 m 2 …m k ) to the system: ≡ (mod ) x a m 1 1 ≡ (mod ) x a m 2 2 ... ≡ (mod ) x a m k k
5-6 Modular Exponentiation Compute last digit of 3^2000 Compute 3^2000 (mod 19) Idea: Get the powers of 3 by repeatedly squaring 3, BUT taking mod at each step.
Modular Exponentiation (All congruences are mod 19) ≡ 2 3 9 Compute 3^2000 = ≡ ≡ 4 2 3 9 81 5 (mod 19) = ≡ ≡ 8 2 3 5 25 6 = ≡ ≡ − 16 2 Technique: 3 6 36 17 ( 2 ) or = ≡ ≡ Repeatedly square 32 2 3 17 289 4 3, but take mod at = ≡ 64 2 3 4 16 each step . ≡ ≡ ≡ 128 2 3 16 256 9 ≡ Then multiply the 256 3 5 terms you need to ≡ 512 3 6 get the desired power. ≡ 1024 3 17 ≡ 2000 1024 512 256 128 64 16 3 ( 3 )( 3 )( 3 )( 3 )( 3 )( 3 ) Book’s ≡ 2000 3 ( 17 )( 6 )( 5 )( 9 )( 16 )( 17 ) powermod() ≡ 2000 3 ( 1248480 ) ≡ 2000 3 9 (mod 19 )
Modular Exponentiation ≡ 2 3 9 Compute 3^2000 = ≡ (mod 152) 4 2 3 9 81 = ≡ ≡ 8 2 3 81 6561 25 = ≡ ≡ 16 2 3 25 625 17 = ≡ ≡ 32 2 3 17 289 137 = ≡ ≡ 64 2 3 137 18769 73 ≡ 128 3 9 ≡ 256 3 81 ≡ 512 3 25 ≡ 1024 3 17 ≡ 2000 1024 512 256 128 64 16 3 ( 3 )( 3 )( 3 )( 3 )( 3 )( 3 ) ≡ 2000 3 ( 17 )( 25 )( 81 )( 9 )( 73 )( 17 ) ≡ 2000 3 ( 384492875 ) ≡ 2000 3 9 (mod 152 )
Recommend
More recommend