Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program SpecificationsYour task is to write a program that can decrypt a message that has been encoded using a Caesarcipher. Stated another way, you need

Program SpecificationsYour task is to write a program that can decrypt a message that has been encoded using a Caesarcipher. Stated another way, you need to find the shift for the cipher. Once you have the shift,you know the mapping so you can decrypt the message.Caesar Cipher CrackingTo find the shift you need to know about cracking Caesar ciphers using a technique that hasbeen around for over a thousand years. Any language such as English has a known distributionfor each letter. For example, the letter E is the most common letter in English making up12.702% of the letters on average (ignoring case). The letter T is next (9.056%), followed byA (8.17%), and so on. The order E-T-A is what matters, not the percentage, but weprovide the complete distribution for the curious (in the file letter_frequencies).The procedure begins by finding the most common letter. You can guess that the most commonletter maps to E. You can now find the shift from the most common letter in the cipher-textto the expected most common letter E. For example, if the most common letter in the cipher-text is H, you know that the shift from E to H is 3. You should check that the shift for thenext most common letter T, and third most common letter A is also 3. Once you know theshift, you can apply the shift to all the letters in the cipher-text and get the original plain-textmessage.What about spaces between words and punctuation? In real world cipher-text there are no spacesor punctuation because those are useful clues for deciphering. In the cipher-text we provide forthis project there is no punctuation, but we have left spaces in the cipher-text because they willbe helpful for you to recognize that your deciphering is correct or not. You will need to ignorespaces when counting letters (if you forget to ignore them, beware that the space will be the mostcommon character).Your high level algorithm will be:1. Read the cipher-text (explained below)2. Get a count of each character in the entire cipher-text (ignore spaces)3. Find the most common character4. Find the shift from E to that most common character.5. Check that the shift also works for the next most common.6. Using the shift, decode each character of the cipher-text and printDeliverablesYou must upload your executable on BB Please be sure to use the specified file name, and savea copy of your proj01.py file to your H drive as a backup.Assignment Notes1. Reading the cipher-text file. You need to import file reading from the os module to getthe file command. Copy the cipherText file to the same folder as your program andcreate this program that will read in the file and print it out. (Be careful that this\ document does shows fancier double quotes than you need to use in IDLE.)words = for line in file(cipherText):print line # print the next file linewords = words + line + print words # print all the words in the file2. The ord() function will be very useful. It generates the ASCII integer value of acharacter. For example type ord(a) into a Python shell and it will return the integer97. If you create a list of countsone count for each letteryou can use the ord()function to index into that list. For example, if letter = c you can find its indexusing index = ord(letter) ord(a). Try it in the Python shell. Theindex for a will be 0, for b it will be 1, for c it will be 2, and so on.The inverse to the ord() function is the chr() function. You may or may not need thechr() function for this projectit depends on how you implement it. Try it out in thePython shell.3. The ord() function is also useful for applying the shift to letters. For example, usingthe formula from above for a shift of shift begins with plainTextChar as anumber.cipherTextChar = (plainTextChar + shift) % 26Deciphering works the same way:plainTextChar = (cipherTextChar + shift) % 26results in plainTextChar being a number which you can then must convert to a letter.4. We provide three files. There is a pair for you to use for testing: both cipherText(cipher1) and plainText (plain1) are provided. The final file (cipherText) is the one yourprogram will be tested on.5. The max(List) function finds the maximum value in a list. TheList.index(value) method will return the index of the value in the List. Trythem out in the Python shell. For example:List = [4, 2, 12, 5]value = max(List)index = List.index(value)If List had 26 values, one for each letter, can you use the ord() function to find the\ letter associated with a particular index? (See suggestion #2 above.)6. Do the Algorithm steps separatelyuse the Python shell for testing.a. Step 1 to read in is provided above. Test it separately.b. Once you have things in a string word you can write a small loop that countsoccurrences of each character. You can test out indexing into counters usingord() within the Python shell before you try to write the loops. If you run Step1, you will have the word string available

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

Databases Illuminated

Authors: Catherine M. Ricardo, Susan D. Urban, Karen C. Davis

4th Edition

1284231585, 978-1284231588

More Books

Students also viewed these Databases questions

Question

=+Are you interested in working on global teams?

Answered: 1 week ago

Question

=+Do you want to work from home?

Answered: 1 week ago

Question

=+ What skills and competencies will enable someone

Answered: 1 week ago