Question

this is about python.One ancient but still common method of encoding information is a substitution cipher

, in which all occurrences of each letter are replaced with some other symbol (often another letter).  One of the most common present-day ciphers is the Rotate-13, which simply replaces each letter in the English alphabet with the letter that appears 13 steps away.

Of course, it is easy to decode these ciphers if one already knows the encryption method (as is true with the Rotate-13). However, another mechanism that often works is to analyze the frequency of each character in the coded message. One can then assume that it has a similar frequency distribution to any other message in the same language.

One notable example of how to decode in this manner appears in the short story "The Gold Bug" by Edgar Allan Poe. Of course, there are other readily accessible illustrations all over the place, especially for solving puzzles called Cryptograms.

For purposes of this assignment, here is a sample English sentence:

'This is a sample of ordinary text with common letter frequencies'

And here is an encoded message that has similar letter frequencies in its plain-text version:

'Qswg ylqg lx ykg xgdwgy sh hwlgrfxklt ys qbro brlqbpx'

Use your functions above, plus any other additional Python code to help decode this sentence.

Some helpful Python functions:

''.join( list of characters )

creates a single string of those characters

message.translate( str.maketrans( given characters, new characters ) ) 

takes the 'message' and translates it as described

Not all sentences have identical frequencies, so it would only be profitable to translate the most frequent characters instead of all of them, and replace the less frequent with a placeholder, (like a . or ?). Then you could puzzle out the rest on your own.

If you figure out what the new sentence is, include something about it at the bottom of your program file, along with the code you used to discover it.

Answer & Explanation

Unlock full access to Course Hero

Explore over 16 million step-by-step answers from our library

Get answer

Our verified expert tutors typically answer within 15-30 minutes.