Affine Cipher Project 1 Introduction
Total Page:16
File Type:pdf, Size:1020Kb
Affine Cipher Project 141KECBZ0H5CRK1HUZK1CGPCR.5PUGUZU1WCU.CM1CUBHUCAK.6.Z5WCP1RK1UCH5 WC0EPU1KECU.C141KEC.UB1KXC,,RBHKV1PCWGRQ15P7CHCUHV1C.6CU9.CRGUG1P Directions: • Answer all numbered questions completely. • Show non-trivial work, and put your final answer in the box provided. • Questions without boxes should be answered in complete sentences in the space provided. 1 Introduction Cryptography is the study of secret codes, or the secure transmission of information that nobody except the desired recipient can read. By the end of this project, you will be able to decipher the quote printed above. The mathematical study of ciphers will lead us through a world in which the number line is a closed curve, and fractions do not exist. This project is designed to help you to: • read and understand definitions and notation • observe patterns and generalize • think logically, analytically, and abstractly • express problems and solutions precisely • follow examples • combine ideas to solve problems and create applications 1 2 Caesar Cipher A cipher is a function or algorithm for translating plaintext into encrypted ciphertext. Throughout history, governments and merchants have used ciphers to safely transmit sensitive information. Julius Caesar is said to have use a simple system of substituting each letter with the letter 3 spots over, wrapping around the alphabet if necessary. Here is the mapping: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z # # # # # # # # # # # # # # # # # # # # # # # # # # D E F G H I J K L M N O P Q R S T U V W X Y Z A B C Space and punctuation are discarded. The message \POMPEY" gets encrypted to \SRPSHB". To decrypt a message, the recipient just inverts the process. 1. Encrypt the plaintext \ATTACKATDAWN". 2. Decrypt the ciphertext \WKHTXLFNEURZQIRAMXPSVRYHUWKHODCBGRJ". 3. There is nothing special about a shift of three. Encrypt \ATTACKATDAWN" using a shift of five. 4. There are 26 letters in the alphabet, so a shift of 13 can be repeated to restore the original plaintext. This is known as the ROT13 system, and is used modern-day to hide answers, punchlines, and spoilers. Use ROT13 to decode the answer: Is it right to pay taxes to Caesar or not? TVIRGBPNRFNEJUNGVFPNRFNEF 2 3 Modular Numbers: Zn Think about the numbers on a clock, except replace the 12 with a zero. This set of numbers is called Z12. Z12 = f0; 1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11g Notice that this is a discrete set of integers. We will not be interested in fractional values between them. Starting at zero, what happens if you make one complete revolution? You might say that 12 hours have passed, but the hand points to 0. Since the clock position of 12 and 0 is the same, we say these numbers are equivalent. Similarly, 13 is equivalent to 1, 14 is equivalent to 2, etc. (think about military time). Mathematically, we write 12 (mod 12) = 0 13 (mod 12) = 1 14 (mod 12) = 2 We can also describe the equivalence using a triple-equal sign: 12 ≡ 0 (mod 12) 13 ≡ 1 (mod 12) 14 ≡ 2 (mod 12) We're just using the cyclical pattern to equate numbers that occur 12 units apart. We call 12 the base. You can add or subtract the base to get equivalent numbers. For example, to find numbers equivalent to 8 (mod 12), start at 8 and repeatedly add or subtract 12. These are all equivalent: −4 ≡ 8 ≡ 20 ≡ 32 (mod 12) since they correspond to the same position on the clock. Numbers that are equal in this way are referred to as aliases or members of the same equivalence class. You evaluate a number (mod 12) by finding out the position (between 0 and 11) that it is equivalent to. For example, to evaluate 27 (mod 12), start at 27 and repeatedly subtract 12 until you get inside Z12. The answer is 3, which we write by saying 27 (mod 12) = 3 We could also write 27 ≡ 3 (mod 12). Hence 27 is an alias of 3. 3 5. Evaluate the following. (a) 18 (mod 12) (d) −3 (mod 12) (b) 37 (mod 12) (e) 124 (mod 12) (c) 48 (mod 12) (f) −14 (mod 12) 6. List 4 aliases of 7 (mod 12). 7. True or false? (a)3 ≡ 39 (mod 12) (c) 18 ≡ 48 (mod 12) (b) 17 ≡ 125 (mod 12) (d) −33 ≡ 51 (mod 12) 8. If x ≡ y (mod 12) then you know that the difference, x − y, is divisible by . 9. You know that 27 (mod 12) = 3. What is the remainder when you divide 27 by 12 ? . There is nothing special about 12. For example, we could work in base 7, where the universe of numbers is Z7 = f0; 1; 2; 3; 4; 5; 6g 4 Zn always goes from zero up to n − 1 (one less than the base). Reducing an integer to its equivalent member of Z7 works the same as it did in base 12. For example, 11 (mod 7) = 4 or put another way 11 ≡ 4 (mod 7) since 11 and 4 are 7 units apart. Also, notice that 4 is the remainder when you divide 11 by 7. As another example, let's evaluate −13 (mod 5). Start at -13, and repeatedly add 5 until you're in Z5 = f0; 1; 2; 3; 4g. −13; −8; −3; 2 Therefore we know that −13 (mod 5) = 2. You can get this answer in Excel; click on a cell and type: =mod(-13,5) Notice that -13 and 2 are 15 units apart. In general, two numbers are aliases if the difference between them is a multiple of the base. 10. Evaluate mod the given base: (a) 9 (mod 5) (f) 24 (mod 3) (b) −4 (mod 17) (g) 24 (mod 4) (c) 56 (mod 41) (h) −14 (mod 5) (d) 56 (mod 26) (e) 27 (mod 6) (i) −14 (mod 7) 11. True or false? (a)3 ≡ 31 (mod 7) (c)3 ≡ 31 (mod 4) (b)3 ≡ 31 (mod 5) (d) 119 ≡ 0 (mod 13) 12. List 4 aliases of 1 (mod 26). 5 4 Addition and subtraction Addition can be visualized as a clockwise rotation around the Zn clock. Subtraction moves counter-clockwise. In general, add or subtract as usual, and then reduce the answer modulo the base. For example: 5 + 11 (mod 12) = 16 (mod 12) = 4 It looks strange to say that 5 + 11 = 4, but it should make sense given the cyclic nature of these number systems. If you start at 5 o'clock and add 11 hours, then the clock reads 4 o'clock. Subtraction works similarly: 7 − 22 (mod 12) = −15 (mod 12) = 9 13. Do the following arithmetic: (a) 4 + 5 (mod 7) (e) 10 + 20 (mod 26) (b) 1 + 1 (mod 2) (f) 10 − 20 (mod 26) (c)2 − 11 (mod 4) (g) 7 + 4 (mod 10) (d) 13 + 7 (mod 5) (h) 12 + 12 + 12 + 12 (mod 41) You can do simple algebra in modular arithmetic, but make sure your answer is within the correct range. For example, let's solve: x + 7 ≡ 4 (mod 9) Subtract 7 from both sides to get x = −3, but it's not quite right since we only accept answers that lie in the set Z9 = f0; 1; 2; ··· ; 8g. Realizing that −3 ≡ 6 (mod 9), the correct answer is x = 6. You can check your answer by verifying that 6 + 7 (mod 9) = 13 (mod 9) = 4 14. Solve each equation. List all possible answers in Zn where n is the base. (a)8+ x ≡ 3 (mod 12) (c) 35 + x ≡ 0 (mod 41) (b) x − 7 ≡ 5 (mod 17) (d) x + x ≡ 4 (mod 12) 6 5 Caesar Cipher Revisited The Caesar cipher can be described in terms of modular arithmetic. Imagine a 26 position clock, where each letter of the alphabet corresponds to a number in Z26. Let x be the number corresponding to a plaintext letter, and y be the number corresponding to a ciphertext letter. For example, with a Caesar cipher shift of 3 positions, we may have 'J' (x = 9) mapping to 'M' (y = 12). Caesar's encryption function can be written algebraically as: y = f(x) = x + 3 (mod 26) To be more general (pun intended), we could have an shift of b characters. y = f(x) = x + b (mod 26) Subtracting b from both sides, we see that the inverse function used to decrypt messages is x = f −1(y) = y − b (mod 26) For example, using b = 3, the map between plaintext 'J' and ciphertext 'M' is represented by: y = f(9) = 9 + 3 (mod 26) = 12 x = f −1(12) = 12 − 3 (mod 26) = 9 15. Use the Caesar cipher with b = 7 to encrypt your \SHZA" name. 7 16. Is it true that f(x) = x + 13 (mod 26) is the same as f(x) = x − 13 (mod 26) ? Explain. 17. Write a function that is the same as f(x) = x − 10 (mod 26), but does not use subtraction. 8 6 Multiplication After multiplying numbers in Zn, reduce result modulo the base. For example: 3 · 7 (mod 12) = 21 (mod 12) = 9 − 2 · 5 (mod 3) = −10 (mod 3) = 2 We can even set up a multiplication table like you did in elementary school, but this one will look a little different. Here is the (mod 12) multiplication table: × 0 1 2 3 4 5 6 7 8 9 10 11 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 2 3 4 5 6 7 8 9 10 11 2 0 2 4 6 8 10 0 2 4 6 8 10 3 0 3 6 9 0 3 6 9 0 3 6 9 4 0 4 8 0 4 8 0 4 8 0 4 8 5 0 5 10 3 8 1 6 11 4 9 2 7 6 0 6 0 6 0 6 0 6 0 6 0 6 7 0 7 2 9 4 11 6 1 8 3 10 5 8 0 8 4 0 8 4 0 8 4 0 8 4 9 0 9 6 3 0 9 6 3 0 9 6 3 10 0 10 8 6 4 2 0 10 8 6 4 2 11 0 11 10 9 8 7 6 5 4 3 2 1 This table is symmetric, and you should notice lots of patterns.