In this assignment you are asked to write a program to break the code of an encoded message. Code breaking can be very complicated. Today’s computers can do much of the work but it still needs human skill to find the clues.

Many code-breakers begin by checking how often certain letters and words appear in a message. In English, for example, E, T, A and O are the commonest letters. TH, HE, AN and RE are common combinations. THE, OF, AND and TO are common words. You cannot write long messages without repeating some of these. The code-breaker can begin to guess the meanings by studying these repetitions. Before the computers were used, it could take weeks or months of intense study and mathematical calculation to crack the code.

In the encoded message you are asked to decipher, each letter of the alphabet was substituted for another letter and it was a one-to-one mapping. To find the cipher you could make use of the fact that some letters of the alphabet occur in any piece of text more often than the others.

You could start by writing a program to count the number of times each letter occurs in a text file, then use this program to find the percentage of the occurrences of each letter in the training text (any long enough piece of English text) relatively to the total number of the letters in the text. You could then do the same thing with the encoded message. You could then write a program to substitute the most frequent letter from the encoded message with the most frequent letter from your training text, and so on.

Possibly you will not get all the letters absolutely right, because some letters, which normally occur with more or less the same frequency could give different results in the training and the encoded messages. You will have to deal with that eventuality by applying your own logic and substituting the letters in the text using interactions with the computer. For example, if in the encoded message you have the word ‘mln’, and it got decoded as the word ‘tge’, which does not exist, it is possible that the correct decoded word is ‘the’. Therefore you should substitute ‘l’ for ‘h’ rather than for ‘g’ in the whole encoded message.

Part A.

Develop two programs, one procedural and another object-oriented. Develop the procedural code first and the object-oriented code second. You can reuse suitable parts of the procedural program to create the object-oriented code. Make sure both programs generate the same results. Submit both programs. Both programs should operate as follows:

  • Read text from a file and store its content in any array of characters A.
  • Calculate the number and percentage of occurrences of each letter in A using two parallel arrays (B and C): one containing 26 alphabet letters and the other containing their corresponding percentage of occurrence.
  • Use a sorting algorithm (for example, bubble sort algorithm) to sort the above two parallel arrays in descending order of the percentage of occurrence.
  • Apply (b) and (c) to the training and the encoded texts. Store both sets of parallel arrays (for the training and the encoded texts) for further use.
  • Use the above two sets of sorted parallel arrays to find and display a one-to-one mapping of letters in the training and encoded texts.
  • Substitutes the letters in the encoded message for letters they represent
  • Save the decoded text stored in an array of characters to a file.
  • Be able to repeat (f), (g) and (h) as many times as the user wishes.

Implement a simple option menu to make your programs easier to use.

Test your programs. Provide sufficient evidence of testing.

Improve your programs. Consider special cases such as choosing an option that is not available in the menu, requesting the user interactively for a text file name and reading the data from that file, etc.

Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.