Question: Please use python programing. Breaking Substitution Ciphers It is possible to break simple substitution ciphers without even using a computer. This is why, for example,

Please use python programing.

Breaking Substitution Ciphers It is possible to break simple substitution ciphers without even using a computer. This is why, for example, such puzzles appear in newspapers. In this homework assignment, you will write a program that automatically decodes a variant of these codes without knowing the codestring in advance. Codeword Substitution One approach to dening a codestring for a substitution cipher is to specify a codeword instead. The idea is that a codeword (with no repeating letters is given) and that is used as the start of the codestring. The rest of the codestring is lled in with the remaining letters of the alphabet in reverse order. For example, if the codeword is ZEBRA , then the codestring would be: ZEBRAYXWVUTSQPONMLKJIHGFDC If the codeword is DOG , then the codestring would be: DOGZYXWVUTSRQPNMLKJIHFECBA You will want to be able to generate such a codestring from a codeword. Here is the code to extend the codeword into a codestring. w = 'ZEBRA' cs = w[:] for a in 'ZYXWVUTSRQPONMLKJIHGFEDCBA': if a not in w: cs = cs + a print(cs) ZEBRAYXWVUTSQPONMLKJIHGFDC Hiding Codewords in Plain Sight In the kingdom of Vulgaria, instead of choosing a cipher in advance, the spies send coded messages that all start with a string of 30 characters that we'll call the preamble. The codeword for the cipher is a substring of those rst 30 characters. They have some secret way of nding the codeword in there, so they can decode messages. Their idea is that they want anyone deciphering the messages to break a new code for each message. Maybe this would work until word gets out that the codeword is hiding in plain sight. Now code breakers can try all the dierent substrings of those rst 30 characters and see which one produces a message that looks like real words. Note: a substring is a sequence of consecutive characters in a string. You can get a substring of a string s using slicing, i.e., s[3:7] is the sting of length 4 consisting of the characters starting at index 3 and continuing up to but not including index 7. So, if s = 'abcdefghij' , then s[3:7] is defg . Incidentally, this is related to how the early versions of the German Enigma machine was cracked. Using data You can get a program to try dierent substrings and check if it is producing real words. You will be given a list of frequently used words. Use this list to check if you have the correct codeword. Then try all the dierent choices and see which one produces something the looks like a real message. If we have a guess at what the codestring is, we can try to decode the message. Then, we can look at it to see if it resembles a real message, for example by checking if the words are real words. If there is a small number of possible codestrings, we can choose between them by checking which produces the largest There is a le called words.py included in the skeleton. It contains a string with a big collection of words. Technically, I got this list from processing the text of Bram Stoker's Dracula and pulling out the unique words that appeared more than a certain number of times. You can import the variable w ordlist from words.py using the following line of python at the top of your ciphercracker.py le. from words import wordlist You will then be able to use the wordlist variable in your code. This approach is not considered great style, but it is easy and appropriate for this case. To Do: 1. Add support to the Cipher class for codeword substitution ciphers. 2. Implement a new class called CipherCracker that will be saved in a le called ciphercracker .py . A CipherCracker object should store a ciphertext that you are trying to decode. It should separate out the preamble from the beginning of the ciphertext. It should implement methods called decode , quality , mostlikelydecode , and mostlikelycodeword . The description of the desired input and output of each method is given in the skeleton.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!