This preview shows page 1. Sign up to view the full content.
Unformatted text preview: CSCI 124/Vora/GWU 1 CSCI 124: Discrete Structures II: Modular Arithmetic
Poorvi L. Vora We start with three simple examples from cryptography to illustrate the need for the mathematics of what is known as modern algebra. We then deﬁne modular arithmetic. The cryptographic problem we examine in this set of notes is as follows: Alice (the sender) wishes to communicate secretly with Bob (the receiver). That is, she does not wish anyone else to overhear the conversation, or read the letter. There is a communication channel linking them – such as a phone line, a data link, or a postal service. The channel is typically insecure. Alice encrypts her message using a key known only to Bob, and uses the insecure communication link to send him the encrypted message. Bob uses the key to decrypt the message. 1 The Shift Cipher One of the ﬁrst known ciphers is the shift cipher from the times of Julius Caesar. In this cipher, the letters from A through Z are associated with the numbers 0 through 25. The key is a letter too, and is similarly associated with a number. Encryption is performed letter by letter, by adding the key to each letter in the plaintext message to get the corresponding letter in the ciphertext. This is best explained through an example. Example 1. Encrypt the sentence “IS CLASS OVER YET?” with the shift cipher, key = “E”. Decrypt the result. Solution: Convert the letters in the sentence to their numerical values: IS CLASS OVER YET 8 18 2 11 0 18 18 14 21 4 17 24 4 19 To encrypt, add the value of the key: : 12 22 6 15 4 22 22 18 25 8 21 2 8 23 Convert back: mwgpewwszivcix To decrypt with knowledge of the key, subtract from each ciphertext symbol: First convert to numbers: 12 22 6 15 4 22 22 18 25 8 21 2 8 23 Then subtract : 8 18 2 11 0 18 18 14 21 4 17 -2=24 4 19 Then convert back to letters: IS CLASS OVER YET Example 2: Decrypt the following ciphertext without knowing the key: mjrmjrmjrtjpmwjvo Solution: Try every possible key: nksnksnksukqnxkwp oltoltoltvlroylxq CSCI 124/Vora/GWU 2 pmupmupmuwmspzmyr qnvqnvqnvxntqanzs rowrowrowyourboat Thus a brute force attack, requiring a number of steps that is half the size of the keyspace ( in real-world cryptography today. One may wish to make a brute-force attack somewhat more difﬁcult. One step towards doing this is to use a different key with each letter in the string. Another is to use multiplication instead of addition. in Example 2), on average, would result in success at determining the key. The shift cipher is hence extremely weak and is not used 2 Vigenere Cipher In this cipher, the key is a string of symbols that is repeated. It can be as long as the message. Example 3 Encrypt the plaintext message: HO HO HO AND A BOTTLE OF RUM using the Vigenere cipher and the key: CHRISTMAS Solution: The message in numbers is: 7 14 7 14 7 14 0 13 3 0 1 14 19 19 11 4 14 17 20 12 The key, in numbers, repeated to form a string as long as the message, is: 2 7 17 8 18 19 12 0 18 2 7 17 8 18 19 12 0 18 2 7 17 The ciphertext in numbers is: 9 21 24 22 25 33=7 12 13 21 2 8 31=5 27=1 37=11 30=4 16 14 35=9 22 19 In letters, the ciphertext is J V Y W Z H M N V C I ..... Unfortunately, for this method to be secure, the key needs to be as long as the message. As the key needs to be sent securely from the sender to the receiver, this is often very impractical. 3 The Afﬁne Cipher
is encrypted as where and form the key. and . Can you decrypt For this cipher, a number the result? Example 4. Encrypt the sentence “IS CLASS OVER YET?” with the afﬁne cipher, Solution: Convert the letters in the sentence to their numerical values: IS CLASS OVER YET 8 18 2 11 0 18 18 14 21 4 17 24 4 19 Multiply by : CSCI 124/Vora/GWU 3 24 54=2 6 33=7 0 2 2 ... Convert back: y c g h a c c ... How would one decrypt with knowledge of the key? If one divided by 3, that would not always give an integer. In this case, what does it mean to divide by 3? To understand this, we need to understand better the mathematical structure behind the numbers we’ve assigned to the alphabet. 4 Modular Arithmetic In assigning numbers to the alphabet, it seems that we are saying that 2 is the same as 28 which is the same as 54. That is, we are saying that two numbers are the same if their difference is divisible by 26. We need not restrict ourselves to , and can generalize this to any number . Deﬁnition 1: For example, if and only if , , . If , etc. , we say “a is congruent to b modulo m”. Recall the deﬁnition of equivalence relations in CS 123. An equivalence was something like an equality, but not quite an equality. In fact, an equivalence is exactly what we’ve been using; you will show this in the discussion session. Note that ,, , , , are congruent among themselves , because or or are all divisible by . In fact, numbers are congruent among themselves when their remainders are the same on division by . To examine this further, we ﬁrst need a simple fact. Theorem: (without proof) Let and . and be two integers. There exist unique integers . sets, each consisting of integers partitions the set of integers into and such that , is often denoted From the examples it appears that the equivalence partitions the set of integers into with the same remainder when divided by sets, which we may number A through Z: . For example, the equivalence We can show this formally. Theorem: (For example, . Also, . , and , , that is, , CSCI 124/Vora/GWU 4 , etc.). Proof: Suppose and , where and . and In the next theorem, we see that, while doing any instead of a number themselves. Theorem: If and , then: operations on two numbers, say and , we can get . Hence operations the same result by doing the operations on two other numbers, say and , congruent to , we can take any element from its representative class and respectively. That is, are operations on the entire class representing the respective numbers, and not on the individual numbers Proof: If For part II: , then . If , then . Prove part I in discussion session. CSCI 124/Vora/GWU 5 Further, We pick the easiest number to use to represent the equivalence class, is divided by Deﬁnition 2: Thus, , . . , , , of integer : the remainder when and so on. . respec- denotes the set of all remainders Deﬁnition 3: tively, resulting in numbers expressed with the additive and multiplicative operations with operations . and , addition and multiplication 5 The Shift Cipher over
for any . Its encryption and decryption We are now in a position to understand the shift cipher and generalize it to rules are: Examples: : : : represents the English alphabet, where each letter is represented by a number represents the set of all bytes, represented as numbers is the set of all bits, represented as numbers . . 6 The Afﬁne Cipher over
for any . We get the following encryption and decryption rules: We can also generalize the afﬁne cipher to CSCI 124/Vora/GWU 6 As we proceed through this course, we try to abstract the commonalities between the operations in the shift and afﬁne ciphers. For Discussion Session Proofs of: Theorem: and part I of: Theorem: If and , then: is an equivalence relation; where if and only if . ...
View Full Document
- Spring '09