Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(d) You might be surprised to know that the shift cipher we've been working withone key for the whole message, spaces and punctuation unchangedis pretty

(d) You might be surprised to know that the shift cipher we've been working withone key for the whole message, spaces and punctuation unchangedis 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_break 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 (Links to an external site.)Links to an external site. 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_break function. (iii) 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.]

(d.2) Each partner should do this part independently: Make up a message without telling your partner what it is. Encrypt the message with a key of your choosing. Copy the encrypted message into an email message and send it to your partner, without including the key. When you receive the email your partner sent you, decrypt it using the shift_break function.

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_2

Step: 3

blur-text-image_3

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

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions