EE418-Assignment#2-Sol

pdf

School

University of Washington *

*We aren’t endorsed by this school

Course

418

Subject

Electrical Engineering

Date

Dec 6, 2023

Type

pdf

Pages

18

Uploaded by ChefDove1401

Report
EE 418 - Assignment 2 - Solutions Total Points: 100 Autumn Quarter, 2023 Prof. Radha Poovendran Department of Electrical and Computer Engineering University of Washington, Seattle, WA 98195 November 4, 2023 Note: This homework contains both computation questions (marked as [Com] ) which are required to do by hand calculations and programming questions (marked as [Pro] ) which are required to write Python /MATLAB codes. Zero points will be awarded if [Com] questions are solved via Python/MATLAB scripts and if [Pro] questions are solved by hand calculations. Show the computation steps and/or justify your answers in all the [Com] questions. Failure to show any intermediate computation steps in [Com] questions will result zero points. You can use and modify the Python functions provided in the file section of the EE 418 canvas page when answering the [Pro] questions. In addition to problems 1-9, Graduate students are required to solve questions 10-13 marked as [GRAD] . Undergraduate students may attempt these questions. However, undergraduate students will not be awarded any extra points for attempting [GRAD] questions. Total number of points for graduate students will be scaled back to 100 points. You can discuss with others but you need to write your own computation steps, justifications and/or Python/MATLAB codes. Your answers to this homework must be submitted through canvas as a single zip file containing the following: i ) hand written and scanned or word or pdf answers to all the computational and discussion questions as single pdf file. ii ) Python/MATLB codes for programming questions as in filename.py or filename.m respectively. Name of your submission zip file should follow the following format. “ # $ EE418 HW2.zip ”, where “#” and “ $ ” should be replaced with your first name and last name, respectively. 1
1. [Pro] (Affine Cipher Decryption) Please answer the following questions. (a) (10 pts) Please write a Python/MATLAB function for affine cipher decryption. This function should take the ciphertext ( Y ) and key value pair ( a, b ) as inputs and output plaintext ( x ). (b) (5 pts) Use your function developed in part ( a ) to decrypt the provided cipher text file “ sampleA- CAD.txt ”. Use the key value pair, ( a, b ) = (9 , 17). i ) Write the decrypted text to a file name “# $ affine output.txt ”, where “#” and “ $ ” should be replaced with your first name and last name, respectively. ii ) Print the 30 th to 39 th ciphertext characters in the file “ sampleACAD.txt ” and their corre- sponding plaintext. Answers: (a) Sample Python code is provided in Figure 1 below. Figure 1: Sample Python function for affine cipher decryption. (b) Answer is “sture cont”. 2
2. [Com] (Extended Euclidean Algorithm, 5 pts × 2 = 10 pts) (a) Using the extended Euclidean algorithm , compute integers x and y such that 754 x +233 y = 1. Show all the steps in your calculations. (b) Find 754 1 mod 233 and 233 1 mod 754 Answers: (a) First using Euclidean algorithm, 754 = 2(233) + 288 (1) 233 = 0(288) + 233 (2) 288 = 1(233) + 55 (3) 233 = 4(55) + 13 (4) 55 = 4(13) + 3 (5) 13 = 4(3) + 1 (6) Next we rewrite equation (6) as follows. 1 = 13 4(3) (7) Substituting “3” in equation (7) by equation (5) gives: 1 = 13 4(55 4(13)) 1 = 4(55) + 17(13) (8) Substituting “13” in equation (8) by equation (4) gives: 1 = 4(55) + 17(233 4(55)) 1 = 17(233) 72(55) (9) Substituting “55” in equation (9) by equation (3) gives: 1 = 17(233) 72(288 233) 1 = 89(233) 72(288) (10) Substituting “288” in equation (10) by equation (1) gives: 1 = 89(233) 72(754 2(233)) + 1 = 72(754) + 233(233) (11) Hence, x = 72 and y = 233. (b) Applying (mod233) to the both left and right sides of equation (11) yields, 72(754) mod 233 = 1 mod 233 754 1 mod 233 = 72 mod 233 754 1 mod 233 = 161 mod 233 Applying (mod754) to the both left and right sides of equation (11) yields, 233(233) mod 754 = 1 mod 754 233 1 mod 754 = 233 mod 754 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
3. [Com] (Hill and Affine Ciphers, 5 pts × 2 = 10 pts) This is an example of cascading encryption scheme with two consecutive Hill cipher encryptions followed by an affine cipher encryption. Consider the following cryptosystem with a smaller set of 11 English letters, i.e., a through k , which map to 0 through 10, respectively. The cryptosystem consists of hill ciphers with keys K 1 and K 2 that are both 2x2 matrices, and an affine cipher with key K 3 . Suppose that K 1 = 1 3 0 1 , K 2 = 2 1 1 0 , K 3 = (7 , 2). For example, if the plaintext is x = (5 , 8), then the encryption process is: First plaintext x is encrypted using Hill cipher with key K 1 , then the resulting ciphertext is encrypted again using Hill cipher with key K 2 , and finally, the ciphertext obtained from 2nd Hill cipher is encrypted using an Affine cipher with key K 3 to obtained the ciphertext y of plaintext x . This process is also shown in the following equations. First Hill Cipher: (5 , 8) · 1 3 0 1 mod 11 = (5 , 1) (12) Second Hill Cipher: (5 , 1) · 2 1 1 0 mod 11 = (0 , 5) (13) Affine Cipher: (7 · 0 + 2 , 7 · 5 + 2) mod 11 = (2 , 4) (14) In general, the plaintext is x = ( x 1 , x 2 ), and the ciphertext is y = ( y 1 , y 2 ). Next, you will combine the above three ciphers with the given keys into one single cipher. (a) Please write down encryption rule (i.e, Find a matrix K and a scalar b such that xK + b 1 1 × 2 = y ). Simplify your answer and express the numbers in Z 11 if possible. (b) Please write down decryption rule(i.e, Find a matrix ¯ K and a vector ¯ b such that y ¯ K + ¯ b = x ). Simplify your answer and express the numbers in Z 11 if possible. Answers: (a) We first derive the single-cipher encryption rule: In the first Hill cipher, we get ( y (1) 1 , y (1) 2 ) = ( x 1 , x 2 ) K 1 = ( x 1 , x 2 ) 1 3 0 1 = ( x 1 , 3 x 1 + x 2 ) mod 11 In the second Hill cipher, we get ( y (2) 1 , y (2) 2 ) = ( y (1) 1 , y (1) 2 ) K 2 = ( x 1 , 3 x 1 + x 2 ) 2 1 1 0 = (5 x 1 + x 2 , x 1 ) mod 11 In the Affine cipher, we get ( y (3) 1 , y (3) 2 ) = (7 · y (2) 1 + 2 , 7 · y (2) 2 + 2) = (7(5 x 1 + x 2 ) + 2 , 7 x 1 + 2) = (35 x 1 + 7 x 2 + 2 , 7 x 1 + 2) mod 11 = (2 x 1 + 7 x 2 + 2 , 7 x 1 + 2) mod 11 Thus, the single-cipher encryption rule is ( y 1 , y 2 ) = (2 x 1 + 7 x 2 + 2 , 7 x 1 + 2) mod 11 or equivalently, [ y 1 , y 2 ] = [ x 1 , x 2 ] 2 7 7 0 + 2[1 , 1] mod 11 4
Therefore, K = 2 7 7 0 mod 11 and b = 2 mod 11. (b) The decryption rule is given by: [ x 1 , x 2 ] = ([ y 1 , y 2 ] [2 , 2]) 2 7 7 0 1 . First note that det K = 2 × 0 7 × 7 = 49 and gcd( 49 , 11) = 1. Hence, K 1 mod 11 exists. Now we have, 2 7 7 0 1 mod 11 = ( 49) 1 0 7 7 2 mod 11 Note that ( 49) 1 mod 11 = 6 1 mod 11 = 2 mod 11 since 6 × 2 mod 11 = 12 mod 11 = 1 mod 11. Hence, 2 7 7 0 1 mod 11 = 2 0 7 7 2 mod 11 = 0 14 14 4 mod 11 = 0 8 8 4 mod 11 These yield: [ x 1 , x 2 ] = ([ y 1 , y 2 ] [2 , 2]) 2 7 7 0 1 = ([ y 1 , y 2 ] [2 , 2]) 0 8 8 4 = [ y 1 , y 2 ] 0 8 8 4 + [6 , 9] Therefore, ¯ K = 0 8 8 4 and ¯ b = [6 , 9]. 5
4. [Com] (Cryptanalysis, 2.5pts × 4 = 10 pts) We use “X”, “Y”, and “Z” to denote Sender, Receiver, and Eavesdropper, respectively. “X” is sending a message to “Y” using one of the following cryptosystems. The plaintext of the message consists of the letter a repeated a few hundred times. “Z” knows what cryptosystem is being used, but not the key, and intercepts only the ciphertext. For systems (a), (b), (c) and (d), state how “Z” will recognize that the plaintext is one repeated letter and decide whether or not “Z” can deduce the letter and key. (Note: for system (c), the solution very much depends on the fact that the repeated letter is a , rather than b, c, . . . ) (a) Shift cipher (b) Affine cipher (c) Hill cipher (with a 2 × 2 matrix) (d) Vigen` ere cipher Answers: (a) Recall shift cipher encryption is defined as: y i = x i + k mod 26 , (15) where x i , y i , and k denote the i th plaintext, the i th ciphertext and the shift cipher encryp- tion key, respectively. Let i ∈ { 1 , 2 , . . . , l } , where l denotes the length of the plaintext. Note that from equation (15), when the plaintext is composed of a one repeated letter (i.e., x 1 = x 2 = . . . = x l = x ), ciphertext will also be composed of one repeated letter (i.e., y 1 = y 2 = . . . = y l = y ). On the other hand for any two i, j ∈ { 1 , 2 , . . . , l } such that i ̸ = j , if x i ̸ = x j , then y i ̸ = y j . Since in this case “ Z ” will observe a ciphertext with a repeated letter which indicates “ Z ” that the plaintext is composed of an one repeated letter. Let y denote the repeated ciphertext letter observed by “ Z ” and x be the repeated plaintext letter. With this information “ Z ” can construct the following formula. y = x + k mod 26 When “ X ” is encrypting only one plaintext letter this is the only equation that can be formulated by “ Z ”. However, this equation has two unknowns x and k . Therefore, “ Z will not be able to deduce the plaintext x or shift cipher encryption key k . (b) Recall shift cipher encryption is defined as: y i = ax i + b mod 26 , (16) where x i , y i , and ( a, b ) denote the i th plaintext, the i th ciphertext and the affine cipher encryption key, respectively. Let i ∈ { 1 , 2 , . . . , l } , where l denotes the length of the plaintext. Then assume there can be a case such that y i = y j for any two x i ̸ = x j , where i, j ∈ { 1 , 2 , . . . , l } and i ̸ = j . Then from equation (16), we get: ax i + b mod 26 = ax j + b mod 26 a 1 ax i + b mod 26 = a 1 ax j + b mod 26 (17) x i + b b mod 26 = x j + b b mod 26 x i mod 26 = x j mod 26 (18) Note that in equation (17), we are allowed to multiple both sides of the equation with a 1 mod 26, since valid key in affine cipher is always chosen such that gcd( a, 26) = 1. Equation (18) suggests that x i = x j , which contradicts our original assumption of x i ̸ = x j . Then by contradiction for any two i, j ∈ { 1 , 2 , . . . , l } such that i ̸ = j , if x i ̸ = x j , 6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
then y i ̸ = y j . Conversely, it proves that y i = y j if x i = x j . Therefore, by observing a ciphertext with a repeated letter, “ Z ” can deduce the plaintext is composed of a one repeated letter. Let y denote the repeated ciphertext letter observed by “ Z ” and x be the repeated plaintext letter. With this information “ Z ” can construct the following formula. y = ax + b mod 26 When “ X ” is encrypting only one plaintext letter this is the only equation that can be formulated by “ Z ”. However, this equation has three unknowns x and ( a, b ). Therefore, Z ” will not be able to deduce the plaintext x or affine cipher encryption key ( a, b ). (c) Recall 2 × 2 Hill cipher encryption is defined as: [ y i , y i +1 ] = [ x i , x i +1 ] · K mod 26 , (19) where x i , y i , and a 2 × 2 matrix K denote the i th plaintext, the i th ciphertext and the Hill cipher encryption key, respectively. Let i ∈ { 1 , 2 , . . . , l 1 } , where l denotes the length of the plaintext. In this case, for any matrix K , “ Z ” will always observe a ciphertext consists of a series of 0s (i.e., y 1 = y 2 = . . . , = y l = 0) as “ X ” is repeatedly encrypting the letter a (i.e., x 1 = x 2 = . . . , = x l = 0). Next we show only way to “ Z ” to observe a series of 0s as a ciphertext is when “ X ” is repeatedly encrypting the letter a . Let K = a b c d mod 26. Then if [ y i , y i +1 ] = [0 , 0], we get [0 , 0] = [ x i , x i +1 ] · a b c d mod 26 . This yields the following two equations. ( ax i + cx i +1 ) mod 26 = 0 mod 26 (20) ( bx i + dx i +1 ) mod 26 = 0 mod 26 (21) First let’s assume x i ̸ = x i +1 , then we get ( ax i + cx i +1 ) mod 26 = ( cx i + dx i +1 ) mod 26 (( a c ) x i + ( b d ) x i +1 ) mod 26 = 0 mod 26 (22) Since x i ̸ = x i +1 either x i or x i +1 is nonzero. Hence, equation (22) is always satisfied if ( a c ) mod 26 = 0 mod 26 and ( b d ) mod 26 = 0 mod 26. This gives the conditions a mod 26 = c mod 26 and b mod 26 = d mod 26. This yields K = a b a b mod 26. However, this gives det( K ) = ab ab = 0 making gcd(det( K ) , 26) = 0 ̸ = 1. Therefore in this case K is not a valid key and hence we note that x i = x i +1 for all i ∈ { 1 , 2 , . . . , l 1 } . Next let’s analyze the case when x i = x i +1 = x ̸ = 0. In this scenario equations (20) and (21) yield: ( a + c ) x mod 26 = 0 mod 26 ( b + d ) x mod 26 = 0 mod 26 Aforementioned set of equations are satisfied for any x ̸ = 0 only if a mod 26 = c mod 26 and b mod 26 = d mod 26. This yields K = c d c d mod 26. However, this gives det( K ) = cd ( cd ) = 0 making gcd(det( K ) , 26) = 0 ̸ = 1. Therefore this case also 7
results in a K that is not a valid key. Therefore we finally note that x i = x i +1 = 0 for all i ∈ { 1 , 2 , . . . , l 1 } if we observe y i = y i +1 = 0. This proves that “ Z ” can deduce one plaintext letter is repeated and the repeated letter is a . However, now when using equation (19), “ Z ” can only get the trivial relation [0 , 0] = [0 , 0]. Therefore, “ Z ” can not deduce the 2 × 2 Hill cipher encryption key K . (d) Recall Vigenere cipher encryption with length m key [ k 1 , k 2 , . . . , k m ] is defined as: [ y 1 , y 2 , . . . , y m ] = [ x 1 , x 2 , . . . , x m ] + [ k 1 , k 2 , . . . , k m ] mod 26 , (23) where [ x 1 , x 2 , . . . , x m ] and [ y 1 , y 2 , . . . , y m ] denote the length m non-overlapping blocks of plaintext and ciphertext, respectively. Therefore, by equation (23), “ Z ” can observe a repeated blocks of ciphertexts of length m when “ X ” is encrypting one repeated letter. However, note that “ Z ” can also observe similar patterns if a word of length m is repeated in plaintext. Therefore, in this case “ Z ” can not deduce “ X ” is encrypting one repeated letter. Without being able to know one letter is repeated, “ Z ” can only be able to derive m equations of the form y i = x i + k i , for i ∈ { 1 , . . . , m } . Note that each of these equation will have two unknowns x i and k i . Therefore, “ Z ” can not solve for x i and k i . Note that in this case “ Z ” can guess the length of the key m , by observing the length of the repeating patterns in ciphertext. However if correlation analysis is used, m sub- strings corresponding to each key k i , will be composed of exactly one repeated letter. Cryptanalysis approaches such as Kasiski test and correlation analysis are based on the assumption that the ciphertext is diverse enough (adequate amount of letters in English alphabet is present in the ciphertext). Therefore, in this case “ Z ” can not use Kasiski test or correlation analysis effectively. 8
5. [Com] (Stream Cipher, 10 pts) Given the plaintext and corresponding ciphertext generated using stream cipher Plain = [1 , 0 , 1 , 1 , 0 , 0 , 1 , 0 , 1 , 1 , 0 , 0 , 1 , 0 , 1] (24) Cipher = [1 , 1 , 1 , 0 , 1 , 1 , 1 , 1 , 0 , 1 , 0 , 0 , 0 , 1 , 0] (25) Find the 5-stage linear recurrence used to generate the key stream. Answers: First we can obtain the key stream z by adding the plain and ciphertext modulo 2. We obtain z = [010111011000111] (26) From this, we can form a system of equations c 1 + c 3 + c 4 = 1 (27) c 0 + c 2 + c 3 + c 4 = 0 (28) c 1 + c 2 + c 3 = 1 (29) c 0 + c 1 + c 2 + c 4 = 1 (30) c 0 + c 1 + c 3 + c 4 = 0 (31) By adding the first equation with the last equation modulo 2, we obtain that c 0 = 1. After substituting c 0 in the system of equations, and by adding equations modulo 2, we obtain the information c 1 = c 2 = c 4 mod 2. Moreover, from the second equation, we have c 2 + c 3 + c 4 = 1. Since c 2 = c 4 , we must have c 3 = 1, and c 1 = c 2 = c 4 = 0. 9
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
6. [Pro] (Stream Cipher, 5pts × 2 = 10 pts) The following sequences in part (a) and part (b) were generated by a linear feedback shift register (stream cipher). Find the coefficients of the recurrences that generate each of these sequences. (a) 1 , 0 , 0 , 1 , 1 , 0 , 0 , 1 , 0 , 0 , 1 , 1 , 1 , 0 , 0 , 0 , 1 , 1 , 0 , 0 , 0 , 1 , 0 , 1 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 0 , 1 , 1 , 0 , 0 , 1 , 1 , 1 , 1 , 1 , 0 , 1 , 0 , 1 , 0 , 1 , 0 , 0 , 1 , 0 , 1 , 1 , 0 , 1 , 1 , 0 , 1 , 0 , 1 , 1 , 0 , 0 , 0 , 0 , 1 , 1 , 0 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 1 , 0 , 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 0 , 0 (b) 1 , 0 , 1 , 0 , 0 , 1 , 1 , 0 , 1 , 1 , 0 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 1 , 0 , 1 , 0 , 0 , 0 , 1 , 1 , 0 , 0 , 1 , 1 , 1 , 1 , 0 , 1 , 1 , 1 , 0 , 1 , 0 , 1 , 1 , 0 , 1 , 0 , 0 , 1 , 1 , 0 , 1 , 1 , 0 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 1 , 1 , 1 , 1 , 1 , 1 Answers: Since both key streams only have digits of 0s and 1s, we can make a guess that the key streams are in (mod 2). However, we do not know the recurrence length of the key streams. In such situation brute force approaches given in Figure 4, and Figure 5 can be taken to find the coefficient of the recurrences. Function “key stream gen” in Figure 3 generates a length len z key stream in (mod m ) corresponding to the coefficient vector c and initial conditions vector z init . Figure 2: Python code for generating key streams. (a) Sample code is given in Figure 4 below. Shortest length coefficients are (1 , 1 , 0 , 0 , 1 , 0 , 0 , 0). Figure 3: Answers to Problem 6-(a). 10
(b) Sample code is given in Figure 5 below. Shortest length coefficients are (1 , 1 , 0 , 1 , 1 , 0). Figure 4: Answers to Problem 6-(b). 11
7. [Pro] (Substitution Cipher Cryptanalysis, 10 pts) You are given the following ciphertext generated based on the substitution cipher: BCDCEFG BCHFIJEB KECBBCU LCGGCH JH MNCINCE INC OCUB CFBL PJHCL KJGQRQCB MCEC OTCGQHV FBBCI ATAAGCB INFI RJTGU INECFICH INC BLBICP. You are given the following plaintext/ciphertext relationship table: Ciphertext Plaintext A b F a L y T u O f Q i U d J o Using your linguistic skills (which may include the knowledge of frequencies of occurrence of letters) and command of the English language, decode the sentence correctly. (Hint, this is about the recent senate inquiry about the fiscal policies of the us federal reserve.) Note: please provide brief steps. Answer: Step 1: Using the plaintext/ciphertext mappings given as hints, the plaintext is given by a a o d y o f d a y o l o i i fu i a bubb a ou d a y Step 2: We see that the most frequent letter in the ciphertext is letter ’C’, so the first guess is to map ’C’ to ’e’. This results in two incomplete words (fed , ea y) with the missing corresponding cipher letter of ’B’. Based on these two words, we also conclude that the letter ’B’ maps to ’s’. Based on these observations, we obtain se e a se a o s essed ye e o e feds easy o ey o i ies e e fue i asse bubb es a ou d ea e e sys e Step 3: Additional observation that we can make is there are two three letter words both ending in ’e’ that appear twice in the text. Most common three letter words such that ends in ’e’ is ’the’. This leads to the guess ’I’ maps to ’t’ and ’N’ maps to ’h’. se e a se ato s essed ye e o ethe the feds easy o ey o i ies e e fue i asset bubb es that ou d t eate the syste Step 4: At this point, we can map several other cipher letters by completing the words. We map ’P’ to ’m’, ’G’ to ’l’, ’H’ to ’n’ and so forth. Using the hint that this text is related to the financial asset hearing, we conclude that the plaintext was several senators pressed yellen on whether the feds easy money policies were fueling asset bubbles that could threaten the system. 12
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
8. [Com] (Vigen` ere Cipher Cryptanalysis, 10 pts) Suppose we have a language with only three letter a, b, c , and they occur with probabilities 1 2 , 1 3 and 1 6 . A message was encrypted using the Vigen` ere Cipher (shift of mod 3 instead of 26). ABCBABBAACBA You are given that the possible key length is either 1, 2 or 3. Find the most likely key length, and the most probable encryption key. Answers: For key length of m = 1, the frequencies of A, B, C are given as 5 12 , 5 12 , and 2 12 . For key length of m = 2, we obtain two cipherblocks y 1 = ACABAB y 2 = BBBACA For both of the cipher blocks, the frequency vectors are given as [ p A , p B , p C ] = ( 1 2 , 1 3 , 1 6 ) for y 1 and [ p A , p B , p C ] = ( 1 3 , 1 2 , 1 6 ) which result in the same auto-correlation as the language. For m = 3, the cipher blocks are given as y 1 = ABBC y 2 = BAAB y 3 = CBAA It can be seen that the auto-correlations for the cipherblocks are not as near to the true auto- correlation as in the case of m = 2. Therefore, m = 2 is the most likely key length. For y 1 , the most frequent letter is A , therefore, the most likely corresponding plaintext is a . Therefore a maps to itself, and K 1 = 0. For y 2 , the most likely corresponding plaintext is a , and K 2 = 1. The most probable key is given as ( K 1 , K 2 ) = (0 , 1). 13
9. [Pro] (Vigen` ere Cipher Cryptanalysis, 5pts × 3 = 15 pts) The following ciphertexts in part (a) and part (b) are encrypted using the Vigen` ere cipher. Use correlation analysis to decrypt each of them, separately. (a) KTSVFVMHMCHJUBFDYLMGRWZXNHMVDSVNUBJOJULFZNAQILXSXOJYOROEFJTD XWCNERALABFMLVJFFSEFVXLUJQBORDKMLFBVGYNXLSNJQDWARDXQHAMBRHUP GTYXVVUYXEXHAQJVMLJEZFZBVQPBYPQMPBCUJHBUDSKQFOTVTFGKYXNPDWXJ QYVOWLJDUJNJHBUUFUPFOFUTCLWKFJWMKDMOLYNZSQBVBJJHWEEQHLLWTWTO RYZXXDYZXOVFPMIHXBMEHSSHZRZKXORYWAPSTZNURNUEFVYPWTRZAQBIWPLB QXLLVUNARFVNNJWHFZCBUYVOBVYVWJVMTNOWFJLVVYVVFGFZRXDXAXIRQTNT VHBAJRZZOBFZSCJHXAQJVXBMEHSPWUUZZRPQNUCPPDTXTWNUCJPFANUKTBPI WXDJTXYANSODPWFAUSRDDGSN (b) KSQRAUHSQGGBFDQSXOIXMRWCSYFWAAPPOSELGYQGWZGLDCXVFZZIHLCAXIL VRTEWGSJPFLWWCWUXAJOWNEFKGHTMUOVLHIUVBYQGLLRETIEDWETEFVHSQV SUREAEKZIXQEEVBRFLWWCHQVKVTETIWHFETXZLGPBEJHHPMRVLEFMPKAOEU SFACHTMUOHSQPSDGZRRSAICQEFKCQZELBFPEKGKSYFMLSSETIEHRPOIFAFP ETWJHEAXZLCAURAVBDAJEHBVURVYSBGMJLGETELAVPKWZVIWPHWJZLDILOS NMYKLGHTMUOWXBIDAVPYXGAVPEIHHFLFMGU (c) GGAMGHUMEDWXUFFAOQLYYSALSHUMEDDXPDVUMAKREIKLAZFEMJQHKKBYKQKY SHVRQFATXMMSFBAHZBXHXHQCGOLERXXTOPPYFBMFRPNVFPZULZWTFQBIYQTH LRTVCAVSKFTWKZFLJGKNXNUVFALYLFRSIXVUHOVJWHVLGOLOHSXTPQFVMQGH VNRQRKTQLXEVGPRCLZBKXWGZEFWFHLVPREVJRQRNWJPHAVDZBSESFFGPVZMT QPVERTHFBHEACKNSFEBXSUEOLWAAZWEEJFPHSSHWMIJJFJYKIYECCILZPEBS GAWARZATXXXJFVBMZUWJGWCKALSMMYERMPGOHFWTRDVQNYNQMBIPMKRZZQLN RIJBPYFBMTKGCMUPJMELSGKQUTZFAJQHGIILZNNYMCUQRHKQQUPDKQJLHWGJ WHGPVUATXNVXOMYLTQGYEIKLALCQGYLDWDUAOQZTEAJXFILQGYLTUXZLATXR IIJLQZHZWYIRJKVXBQLTJRTVCAHZTQCHKPUHCQVMECIBQKYMLYMRCIYFATKT YVJQULOULYSGALSJYKIYSVTXCOFMWFTIKKTAVUGHVTCPVUNOKDTIQDEHWTBH GDOMYLEUMDVPPDVUNRKTQIJBCLUMGITPRBETLFATHHQCGOLBTXXIJOBBNTFF GWKKRZSUDJXWGYEPAULMFDOYRZHZWHSAQPFBZOHRTJVBEZHFUQIIEEYLFBTW OXPTBYSPPFVXKQBAOQFFXWGJNAPOTQPNCAIHUOXIGDOMHALDBEISUZULTQLT JIJBCYLEXSXBGQUVKEYTVQTBNRPZZRSSGOAJYKIYSHAPGLTEHKXTPFACVXOJ WDNSVUNOTWIUWIYFJAGXXGWZGLKBKTFAGJFPUBNWIBCQULTMMNGHVERILEMP RDYKOLPZZNRIGDRYMMVYSGKWNAPAG Answers: Please refer to “EE-418-2021-Assignment-2-Q9-solutions.ipynb” for the detailed steps and sample Python code. (a) Vigen` ere cipher encryption key is [3, 5, 7, 9, 1] (b) Vigen` ere cipher encryption key is [14, 11, 12, 4, 18, 7] (c) Vigen` ere cipher encryption key is [4, 15, 2, 23, 13, 7, 7, 12, 19, 5] 14
10. [GRAD] (Permutation Cipher, 5 pts x 2 = 10 pts) (a) Prove that a permutation π in the Permutation Cipher is an involutory key if and only if π ( i ) = j implies π ( j ) = i , for all i, j ∈ { 1 , 2 , ..., m } . (b) Determine the number of involutory keys in the Permutation Cipher for m = 2 , 3 , 4 , 5 and 6. Answers: A key K is involutory if E K ( x ) = D K ( x ) for any plaintext x . In the case of the permutation cipher, this relation holds if the permutation π satisfies π ( π ( i )) = i for each i . π ( π ( i )) = i holds under two cases: first, if π ( i ) = i ; and second, if π ( i ) = j for some j ̸ = i and π ( j ) = i . (a) The proof requires two direction. First, suppose there is a permutation function π such that π ( i ) = j , and then π ( j ) = i . Then it is clear that π ( π ( i )) = i , hence the forward direction completes. On the other hand, suppose the permutation function is an involutory key, such that π ( π ( r )) = r , for some number r (1 , ..., m ), then suppose π ( r ) = q for some number q (1 , ..., m ), then it is clear that π ( q ) = r , which satisfies the requirement and hence completes proof. (b) This problem can be solved through a recursive approach. Let P m denote the number of involutory keys of block size m . We have P 1 = 1 and P 2 = 2. Now, suppose that we have computed the values of P k up to k = m 1. Consider an involutory permutation π of size m , and in particular consider the value of π ( m ). By the paragraph above, there are two cases on π ( m ). First, if π ( m ) = m , then it suffices to choose the π ( i ) for all i ̸ = m such that an involutory permutation is formed. This is equal to the number of involutory permutations of the integers up to ( m 1), which is equal to P m 1 . Now, in the second case, π ( m ) = i and π ( i ) = m for some i ̸ = m . The permutation π will be involutory if and only if the remaining ( m 2) integers is an involutory permutation. There are P m 2 such permutations for each of the ( m 1) possible values of i , implying that there are ( m 1) P m 2 involutory permutations of this form. Hence the total number of involutory permutations of size m is equal to P m = P m 1 + ( m 1) P m 2 . For m up to 6, we have that P 1 = 1, P 2 = 2. P 3 is given by P 3 = P 2 + 2 P 1 = 4. P 4 is given by P 4 = P 3 + 3 P 2 = 10. P 5 is given by P 5 = P 4 + 4 P 3 = 10 + 16 = 26. Finally P 6 is given by P 6 = P 5 + 5 P 4 = 26 + 50 = 76. 15
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
11. [GRAD] (Affine Cipher, 5 pts x 2 = 10 pts) Suppose that K = (5 , 21) is a key in an Affine Cipher over Z 29 . (a) Express the decryption function d K ( y ) in the form d K ( y ) = a y + b , where a , b Z 29 . (b) Prove that d K ( e K ( x )) = x for all x Z 29 . Answers: (a) From class, we have that the decryption operation for affine cipher is given by d K ( y ) a 1 ( y b ) mod m (32) where m is the modulus, in this case m = 29. We then have a y + b d K ( y ) mod 29 a 1 ( y b ) mod 29 a 1 y a 1 b mod 29 and hence a a 1 mod 29 and b ≡ − a 1 b mod 29. Using the values ( a, b ) = (5 , 21), one can first find a mod 29 using the extended Euclidean algorithm. However, in this case, the inverse can be found by visual inspection since 5 · 6 1 = 29. Therefore, a = 6, and the resulting b = 126 mod 29, which equals to b = 19. In conclusion, the decryption function is d K ( y ) 6 y 126 mod 29 6 y + 19 mod 29 (33) (b) To prove this, use the fact that d K ( y ) = a 1 ( y b ) mod 29 and e K ( x ) = ax + b mod 29. This gives d K ( e K ( x )) a ( e K ( x )) + b mod 29 6(5 x + 21) + 19 mod 29 30 x + 126 + 19 mod 29 30 x + 145 mod 29 x mod 29 where the third congruence relation follows from the distributive property. The final congru- ence comes from the fact that 30 1 mod 29 and 145 is a multiple of 29, i.e. 145 0 mod 29. 16
12. [GRAD] (Affine Cipher, 5 pts x 2 = 10 pts) An involutory key is a key K such that e K ( x ) = d K ( x ) for any message x . See Chapter 1 of Stinson, Problem 6. (a) Suppose that K = ( a, b ) is a key in an Affine Cipher over Z n . Prove that K is an involutory key if and only if a 1 mod n = a and b ( a + 1) 0 (mod n ). (b) Determine all the involutory keys in the Affine Cipher over Z 15 . Answers: (a) We need to prove the statement in both directions. In the forward direction, assume that K is an involuntary key. By definition, we have ax + b = a 1 ( x b ) (34) Then ( a 1 a ) x b + a 1 b (mod n ) (35) Since Eq. (35) is true for all x Z n = { 0 , 1 , ..., n 1 } , it must also be true for x = 0. Thus, b + a 1 b 0 mod n , namely, b ( a + 1) 0 mod n . On the other hand, ( a 1 a ) x 0 mod n . Since this is also true for x ’s that are relatively prime to n , i.e., gcd( x, n ) = 1, then we have a 1 a 0 mod n , i.e., a 1 mod n = a . Next, we prove the statement in the backward direction. Assume that a 1 mod n = a and b ( a + 1) 0 mod n . Then a 1 a 0 mod n and b + a 1 b 0 mod n . Therefore, ( a 1 a ) x b + a 1 b 0 mod n . Rearranging the above, we have ax + b = a 1 ( x b ). (b) The key is involuntary if and only if a 1 mod n = a (or a 2 1 mod n ), and b ( a + 1) 0 mod n , where n = 15. Since ( a 1)( a + 1) 0 mod 15, it implies that the following four cases: (i) 15 | ( a 1) a = 1; (ii) 15 | ( a + 1) a = 14; (iii) 3 | ( a 1) and 5 | ( a + 1) a = 4; (iv) 5 | ( a 1) and 3 | ( a + 1) a = 11. Then we can consider b for each value of a : (i) When a = 1, b = 0; (ii) When a = 14, b could be anyone in Z 15 ; (iii) When a = 4, b = 0 , 3 , 6 , 9 , 12; (iv) When a = 11, b = 0 , 5 , 10. Therefore, the total number of involuntary keys is 1 + 15 + 5 + 3 = 24. 17
13. [GRAD] (Euclidean Algorithm, 10 pts) In the Euclidean Algorithm (Fig. 1 in Handout 2, or Algorithm 6.1 of Stinson, 4th ed, pg. 189), prove that gcd( r 0 , r 1 ) = gcd( r 1 , r 2 ) = ... = gcd( r m 1 , r m ) = r m (36) and hence, r m = gcd( a, b ). Answers: This proof uses 2 lemma, stated as follows: Lemma 1: If a positive integer b divides a, then b must be the greatest common divisor of a and b, i.e. gcd(a,b) = b. Proof is omitted. Lemma 2: For non-zero integer a and b suppose that a = bq + r where q, r Z (37) Then gcd(a,b) = gcd(b,r) Proof: If c divides a and c divides b then a = cq 1 and b = cq 2 for some integer q 1 , q 2 . In this case r = a bq = cq 1 cq 2 q = c ( q 1 q 2 q ), so that c divides r. Thus c is common divisor of a and b implies c is a common divisor of b and r. Conversely, if c is a common divisor of b and r then c is common divisor of a and b. Hence the common divisors of a and b are the same as the common divisors of b and r and so their greatest common divisors are the same. Proof of Algorithm 5.1: We first prove the statement P(m), a statement that, given any sequence of pos- itive numbers, r 0 , r 1 , ..., r m generated by m-1 step of Euclidean algorithm, gcd( r 0 , r 1 ) = gcd( r m 1 , r m ) by induction on m. Base case: P(1) simply says gcd ( r 0 , r 1 ) = gcd ( r 0 , r 1 ), and it is certainly true. Inductive step: suppose we have some k greater than 1 the result is true for m=k. Then, given a sequence of numbers r 0 , r 1 , ..., r k +1 generated by k steps of Euclidean Algorithm, r k 1 = r k q k + r k +1 , so by Lemma 2 proved above, we know gcd ( r k 1 , r k ) = gcd ( r k , r k +1 ). But by inductive hypothesis, gcd ( r 0 , r 1 ) = gcd ( r k 1 , r k ) and so gcd ( r 0 , r 1 ) = gcd ( r k , r k +1 ). Hence, by induction the statement P(m) is true for all positive integers m. Now complete the proof, using the notation of theorem it follows that gcd ( a, b ) = gcd ( r 0 , r 1 ) = gcd ( r m 1 , r m ). But since the last reminder is 0 when algorithm finishes, it follows that r m divides r m 1 , and so gcd ( r m 1 , r m ) = r m , i.e. gcd(a,b) = r m . 18
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help