Write a toolkit that helps a cryptographer decrypt a file that was encrypted using a monoalphabet cipher.

Question:

Write a toolkit that helps a cryptographer decrypt a file that was encrypted using a monoalphabet cipher. A monoalphabet cipher encrypts each character separately.

Examples are the Caesar cipher and the cipher in Exercise •• P21.1 . Analyze the letter frequencies as in Exercise • P21.2 . Use brute force to try all Caesar cipher keys, and check the output against a dictionary file. Allow the cryptographer to enter some substitutions and show the resulting text, with the unknown characters represented as ?. Try out your toolkit by decrypting files that you get from your classmates.

Data from exercise  P21.1 Random monoalphabet cipher. The Caesar cipher, which shifts all letters by a fixed amount, is far too easy to crack. Here is a better idea. For the key, don’t use numbers but words. Suppose the keyword is FEATHER. Then first remove duplicate let ters, yielding FEATHR, and append the other letters of the alphabet in reverse order. Now encrypt the letters as follows:

image text in transcribed

Write a program that encrypts or decrypts a file using this cipher. The keyword is specified with the -k command line option. The -d command line option specifies decryption. For example,

image text in transcribed

decrypts a file using the keyword FEATHER. It is an error not to supply a keyword.

Data from exercise  P21.2 Letter frequencies. If you encrypt a file using the cipher of Exercise •• P21.1 , it will have all of its letters jumbled up, and will look as if there is no hope of decrypting it without knowing the keyword. Guessing the keyword seems hopeless, too. There are just too many possible keywords. However, someone who is trained in decryption will be able to break this cipher in no time at all. The average letter frequencies of English letters are well known. The most common letter is E, which occurs about 13 percent of the time. Here are the average frequencies of English letters:

image text in transcribed

Write a program that reads an input file and prints the letter frequencies in that file.
Such a tool will help a code breaker. If the most frequent letters in an encrypted file are H and K, then there is an excellent chance that they are the encryptions of E and T.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  answer-question
Question Posted: