This assignment on Cryptography consists of two parts. Part 1 (Assignment #8a) uses statistical means to...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
This assignment on Cryptography consists of two parts. Part 1 (Assignment #8a) uses statistical means to "crack" a basic shift-cipher, i.e. it will decrypt the data without pre-existing knowledge of the shift. Part 2 (Assignment #8b) uses two-phase encryption, first RSA to safely share a substitution cipher, followed by use of that substitution cipher to encrypt data. Submissions: Assignment08a.py (Python code) Assignment08a_decrypted.txt (output file showing successful description of the input file, encrypted.txt) Overview: Assignment08b.py (Python code) Assignment08b.txt (console output showing the encryption and decryption) A "shift cipher" is a simple cryptographic approach in which each letter of the alphabet in a text is consistently shifted by a fixed amount, including wraparound to the beginning of the alphabet. For example, with a shift of 2, we get this mapping: Your job is to decipher the encrypted text by programmatically analyzing all 26 possible shifts and determining which one would generate letter frequencies most consistent with the frequencies in the English alphabet. A C, B D, C E, ..., X Z, YA, Z B To map a character to the proper index in the list, you can say index = ord(c) - ord('A'). Thus, A will go to position 0, B to position 1, ..., Z to position 25 Then to calculate frequencies, you can say something like: for c in text: ord (c) ord ('A') index actual freqs [index] += 1 [6] Write a function shift_char(c, shift) that shifts a character c based on a given shift variable with syntax like. shifted_char = chr(ord('A') + ((ord(c) - ord('A') + shift) % 26)) [7] Write a function that shift_text(text, shift) that shifts a text based on a given shift variable by looping over the entire text and shifts each character using the shift_char function from the previous task. = [8] Write a function find_best_shift(text) that iterates over all possible shifts 0 to 25, recounts the character frequencies after the shift, and computes the "distance" between the expected frequencies and actual frequencies. If the distance for that shift is better (smaller) than the best previous distance, then assume that is the best shift. Once you have found the best shift, that is your decrypted text! [9] Write a function write_file(file_name, text) that writes the contents of the string text to the specified file. In this case, your output file can be called decrypted.txt Overview: In Part 2 of the assignment, we implement two-phase encryption, RSA public-key cryptography combined with a substitution cipher, in the context of a client-server model of communication. [For the purpose of this assignment, we will ignore other networking considerations such as headers, encapsulation, transmission in blocks, checksums, handshakes, etc.] To simplify the problem, all spaces, digits, punctuation marks, and other symbols in the text have been removed, and all lower-case letters have been converted to upper-case. Tasks: In this assignment, you will often need the following two built-in functions: ord(c) find the ordinal position of c in the ASCII character set (A is 65, B, is 66, etc.) chr(i) returns the character at position i in the ASCII character set (chr(65) is A, chr(66) is B, etc.) See the chart at https://en.wikipedia.org/wiki/ASCII#Printable characters I [0] Perform the usual preliminary tasks. [1] Download the input file Encrypted.txt" from Google drive > Assignments and place it in your PyCharm folder.. [2] Write a function read_file(file_name) which will read the file from your drive and return its contents as a string variable. [3] Create a letter-frequency list based on the chart at https://en.wikipedia.org/wiki/Letter_frequency: expected_freqs = [8.2, 1.5, 2.8, 4.3, 12.581, 2.2, 2.0, 6.1, 7.0, 0.15, 0.77, 4.0, 2.4, 6.7 7.5, 1.9, 0.095, 6.0, 6.3, 9.1, 2.8, 0.98, 2.4, 0.15, 2.0, 0.074] (The frequency of E has been adjusted from 13.0 to 12.581 to compensate for rounding of other frequencies) [4] Write a function distance(x, y), defined as sqrt[(x[0] - y[0]) + (x[1] - y[1]) + ... + (x[n-1] - y[n-1])] where n is the length of x and y. Use a for-loop. You will need the sqrt function, so "import math" at the beginning of your code. [5] Write a function count_letters (text) to determine the frequency of each letter and place it in a list called actual_freqs. First create a list of 26 values of zero (0) using this syntax: actual_freqs = [0] * 26 Tasks: characters to uppercase [1] Choose a text file and simplify it as follows: Convert any lowercase characters Remove anything that is not (after step a) an uppercase character (A-Z), digit (0-9), space or period. Your character set will now be of size 38 (26 + 10 + 2) which will simplify your substitution cipher in the next steps. [2] Randomly choose a substitution cipher, that is a random permutation of the 38 elements of your character set. (See Ch. 8, Slide 12 - except we have 38 characters instead of just 26.) You can use np.random.permutation to generate the permutation. [3] Use RSA to securely send the one-time substitution cipher (i.e. the permutation) from the client to the server. The client will be aware of the server's "public key". You can see the basics of using RSA in Python in Slide 13 of our supplement "LT_Network Security". More details, if required, can be found on the Internet, including official https://stuvel.eu/software/rsa/ the An elaborate example from https://bit.ly/2K60WHh 8a Program Source Code (.cpp, java, .py) * 1 Add file [4] The server should use RSA decryption to decipher the substitution cipher (the permutation) that is being used. Now both server and client know this substitution cipher for this one communication that follows. The server uses the substitution cipher to encrypt the file which it sends to the client. The client should decrypt the file using the inverse of the substitution cipher. You can compare against the original file (post step 1) to ensure that it worked. 8a Decrypted text (.txt) * 1 Add file 8b Program Source Code (.py) 1 Add file * 8b Program Console Output (.txt) 1. Add file Python-RSA * homepage at Tutorial Point at This assignment on Cryptography consists of two parts. Part 1 (Assignment #8a) uses statistical means to "crack" a basic shift-cipher, i.e. it will decrypt the data without pre-existing knowledge of the shift. Part 2 (Assignment #8b) uses two-phase encryption, first RSA to safely share a substitution cipher, followed by use of that substitution cipher to encrypt data. Submissions: Assignment08a.py (Python code) Assignment08a_decrypted.txt (output file showing successful description of the input file, encrypted.txt) Overview: Assignment08b.py (Python code) Assignment08b.txt (console output showing the encryption and decryption) A "shift cipher" is a simple cryptographic approach in which each letter of the alphabet in a text is consistently shifted by a fixed amount, including wraparound to the beginning of the alphabet. For example, with a shift of 2, we get this mapping: Your job is to decipher the encrypted text by programmatically analyzing all 26 possible shifts and determining which one would generate letter frequencies most consistent with the frequencies in the English alphabet. A C, B D, C E, ..., X Z, YA, Z B To map a character to the proper index in the list, you can say index = ord(c) - ord('A'). Thus, A will go to position 0, B to position 1, ..., Z to position 25 Then to calculate frequencies, you can say something like: for c in text: ord (c) ord ('A') index actual freqs [index] += 1 [6] Write a function shift_char(c, shift) that shifts a character c based on a given shift variable with syntax like. shifted_char = chr(ord('A') + ((ord(c) - ord('A') + shift) % 26)) [7] Write a function that shift_text(text, shift) that shifts a text based on a given shift variable by looping over the entire text and shifts each character using the shift_char function from the previous task. = [8] Write a function find_best_shift(text) that iterates over all possible shifts 0 to 25, recounts the character frequencies after the shift, and computes the "distance" between the expected frequencies and actual frequencies. If the distance for that shift is better (smaller) than the best previous distance, then assume that is the best shift. Once you have found the best shift, that is your decrypted text! [9] Write a function write_file(file_name, text) that writes the contents of the string text to the specified file. In this case, your output file can be called decrypted.txt Overview: In Part 2 of the assignment, we implement two-phase encryption, RSA public-key cryptography combined with a substitution cipher, in the context of a client-server model of communication. [For the purpose of this assignment, we will ignore other networking considerations such as headers, encapsulation, transmission in blocks, checksums, handshakes, etc.] To simplify the problem, all spaces, digits, punctuation marks, and other symbols in the text have been removed, and all lower-case letters have been converted to upper-case. Tasks: In this assignment, you will often need the following two built-in functions: ord(c) find the ordinal position of c in the ASCII character set (A is 65, B, is 66, etc.) chr(i) returns the character at position i in the ASCII character set (chr(65) is A, chr(66) is B, etc.) See the chart at https://en.wikipedia.org/wiki/ASCII#Printable characters I [0] Perform the usual preliminary tasks. [1] Download the input file Encrypted.txt" from Google drive > Assignments and place it in your PyCharm folder.. [2] Write a function read_file(file_name) which will read the file from your drive and return its contents as a string variable. [3] Create a letter-frequency list based on the chart at https://en.wikipedia.org/wiki/Letter_frequency: expected_freqs = [8.2, 1.5, 2.8, 4.3, 12.581, 2.2, 2.0, 6.1, 7.0, 0.15, 0.77, 4.0, 2.4, 6.7 7.5, 1.9, 0.095, 6.0, 6.3, 9.1, 2.8, 0.98, 2.4, 0.15, 2.0, 0.074] (The frequency of E has been adjusted from 13.0 to 12.581 to compensate for rounding of other frequencies) [4] Write a function distance(x, y), defined as sqrt[(x[0] - y[0]) + (x[1] - y[1]) + ... + (x[n-1] - y[n-1])] where n is the length of x and y. Use a for-loop. You will need the sqrt function, so "import math" at the beginning of your code. [5] Write a function count_letters (text) to determine the frequency of each letter and place it in a list called actual_freqs. First create a list of 26 values of zero (0) using this syntax: actual_freqs = [0] * 26 Tasks: characters to uppercase [1] Choose a text file and simplify it as follows: Convert any lowercase characters Remove anything that is not (after step a) an uppercase character (A-Z), digit (0-9), space or period. Your character set will now be of size 38 (26 + 10 + 2) which will simplify your substitution cipher in the next steps. [2] Randomly choose a substitution cipher, that is a random permutation of the 38 elements of your character set. (See Ch. 8, Slide 12 - except we have 38 characters instead of just 26.) You can use np.random.permutation to generate the permutation. [3] Use RSA to securely send the one-time substitution cipher (i.e. the permutation) from the client to the server. The client will be aware of the server's "public key". You can see the basics of using RSA in Python in Slide 13 of our supplement "LT_Network Security". More details, if required, can be found on the Internet, including official https://stuvel.eu/software/rsa/ the An elaborate example from https://bit.ly/2K60WHh 8a Program Source Code (.cpp, java, .py) * 1 Add file [4] The server should use RSA decryption to decipher the substitution cipher (the permutation) that is being used. Now both server and client know this substitution cipher for this one communication that follows. The server uses the substitution cipher to encrypt the file which it sends to the client. The client should decrypt the file using the inverse of the substitution cipher. You can compare against the original file (post step 1) to ensure that it worked. 8a Decrypted text (.txt) * 1 Add file 8b Program Source Code (.py) 1 Add file * 8b Program Console Output (.txt) 1. Add file Python-RSA * homepage at Tutorial Point at
Expert Answer:
Related Book For
Posted Date:
Students also viewed these algorithms questions
-
Q1. You have identified a market opportunity for home media players that would cater for older members of the population. Many older people have difficulty in understanding the operating principles...
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
How often is the lifecycle sustainment plant updated? A. Before in initial operation, test and evaluation. B. At each milestone decision. C. Prior to each major change to the product of strategy. D....
-
Why are there probably no permanently aligned magnetic domains in Earth's core?
-
Draw and label the given streams and derive expressions for the indicated quantities in terms of labeled variables. The solution of Part (a) is given as an illustration. (a) A continuous stream...
-
What is the role of cooling towers in surface condenser ?
-
On 1 April year 1, a deep discount bond was issued by DDB AG. It had a face value of 2.5 million covering a five-year term. The lenders were granted a discount of 5%. The coupon rate was 10% on the...
-
Write a complete Python program that computes some measurements related to a swimming pool. Our pool does not have a shallow end, the depth is the same along the length of the pool. From a diving...
-
You have been presented with the following set of financial statements for National Property Trust, a REIT that is about to make an initial stock offering to the public. This REIT specializes in the...
-
An HR manager asks about a manual-dexterity test that has been used to select automobile assembly-line workers "Does this test predict on-the-job performance for these types of workers?" On which...
-
Considering the impact of climate change and urbanization on thermal comfort and energy demand in buildings, how do architects, engineers, and urban planners employ passive design strategies, green...
-
Conduct a DFMEA for a concept of Gas Snow Blower Select any existing concept of Gas Snow Blower to perform the DFMEA study and answer the following questions in a report format (See assignment report...
-
Kingsgrove Ltd sells 1,000 tonnes of soil each year and demand is constant over time. The purchase cost of each tonne is $1 and the cost of placing and handling an order is estimated to be $5. The...
-
How do advancements in materials science and nanotechnology enable the development of novel heat transfer enhancement techniques, such as nanostructured surfaces, phase-change nanofluids, and thermal...
-
The retailers cost is $86 and their markup on selling price is 26%. Calculate the selling price
-
Determine each of the following areas and show these graphically. Use probability notation in your final answer. a. above z = 1.46 b. below z = - 0.50 c. between z = 2.20 and z =1.00
-
The area of a rectangle is 30 cm 2 and its perimeter is 26 cm. Find the length and width of the rectangle.
-
A square wood platform, 8ft x 8ft in area, rests on masonry walls (see figure). The deck of the platform is constructed of 2in nominal thickness tongue-and-groove planks (actual thickness 1.5in; see...
-
The strains for an element of material in plane strain (see figure) are as follows: (x = 480 ( 10-6, and (xy = - 350 ( 10-6. Determine the principal strains and maximum shear strains, and show these...
-
At a point in a structure subjected to plane stress, the stresses are (x = - 4100 psi,(y = 2200 psi, and Txy = 2900 psi (the sign convention for these stresses is shown in Fig. 7-1), A stress element...
-
With reference to Exercise 10.55, find a large sample 95% confidence interval for the true difference of probabilities. Data From Exercise 10.55 10.55 As a check on the quality of eye glasses...
-
As a check on the quality of eye glasses purchased over the internet, glasses were individually ordered from several different online vendors. Among the 92 lenses with antireflection coating, 61...
-
Two bonding agents, \(A\) and \(B\), are available for making a laminated beam. Of 50 beams made with Agent \(A, 11\) failed a stress test, whereas 19 of the 50 beams made with Agent \(B\) failed. At...
Study smarter with the SolutionInn App