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
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