Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use python to resolve it. (d) You might be surprised to know that the shift cipher we've been working with-one key for the whole

image text in transcribed

Please use python to resolve it.

(d) You might be surprised to know that the shift cipher we've been working with-one key for the whole message, spaces and punctuation unchanged-is pretty easily breakable by hand with messages as short as one moderate-length sentence. People even do it for fun: Google the term cryptogram, which is the name of that kind of puzzle (d.1) Now we're going to do some cryptanalysis of our own. Write a function called shift_recover_plaintext that takes a ciphertext string (encrypted using a shift cipher as we did last week) and returns the plaintext for that string, without having the key We'll take a "brute force" approach: There are 26 possible keys; we'll generate a decryption alphabet for each of these 26 keys. . We'll "decrypt" the ciphertext using each of the 26 alphabets. (Only one of these attempted decryptions will be the correct plaintext message, of course But we don't know which one in advance. Trying all the possibilities is what we mean when we call this a "brute force" approach.) For each of the 26 possibly-decrypted messages, our program needs to figure out whether it "looks like English" instead of encrypted gibberish. Here's how: We'll take each word in the possibly-decrypted message and look it up in a dictionary (a list of English words). If the word is in the dictionary, then it's an English word; if there are a lot of English words in this possibly-decrypted message, it's likely that this message is the correct decrypted plaintext. (If very few words in the message are in the dictionary, then this message isn't the English plaintext.) So we need to count up how many of the words in each possibly-decrypted message we find in the dictionary, saving that total along with the message that produced it. Once we're done with all 26 possible decryptions, we should expect that the possibly-decrypted message that had the most "hits" in the dictionary is in fact the correctly decrypted plaintext, and that's the message we return. To get the dictionary, download the file http://www.ics.uci edu/-kay/wordlist.txt onto your machine and read it in to your program. Remove newline characters if necessary Here are some other suggestions and hints. Don't automatically read them; use them just as needed. Trying to think out the solution yourself is what builds the new neural pathways in your brain (i.e., that's how you learn) (i) Use your rotated-alphabet function from last week to help in making your list of 26 encryption/decryption tables. (ii) Choose a few sentences, encrypt them with your shift encrypt function from last week, and use them to test your shift recover_plaintext function (ii) At some point you'll want to break your possibly-decrypted string into words, removing white space and punctuation, so you can look each word up in the dictionary. But also hang on to the original possibly-decrypted string with the spaces and punctuation, because that's the version you'll want to return if it's identified as the plaintext.]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OCA Oracle Database SQL Exam Guide Exam 1Z0-071

Authors: Steve O'Hearn

1st Edition

1259585492, 978-1259585494

More Books

Students also viewed these Databases questions