For this program, you will write a substitution cipher. Consider, for example, the string "Hello". If you substitute an "a" for every "e" and a "p" for every "l", the string becomes "Happo".

Write a program that reads the file name of a file name of a file which holds character substitutions. The program will open and read the file. Once a substitution file is read, your program would then prompt the user for a file containing a message. Once the user has entered the message file, your program will then open and read that file, and then substitute each character in the plaintext file with the corresponding character in the substitution file. THe resulting message should be written to the screen.

For example, consider the following substitution file:

almnopqrstuvwxyzbcdefghijk

In the above exaple file, "a" is substituted for "a". "l" is substituted for "b", m is substituted for "c", and so on.

Now consider the following message in a message file:

The secret meeting place is DerryBerry Hall!

Then, the output would be: Ero domcoe wooesxq zvamo sd NocojLoccj Ravv!

For this assignment, when substituting, that you should keep the case of the original character, and you should not substitute for any character that is not alphabetic character (a-z or A-Z).

Below is an example run:

$ ./Cipher
Please enter the name of the substitution file: key.txt
Please enter the name of the plaintext file: msg.txt
Ero domcoe wooesxq zvamo sd NocojLoccj Ravv!

Once you have part 1 working, add a feature to decode the message. After reading the file names for the substituion key and the message text, your program should ask the user if the user wants to decode the message or encode the message. If the user enter 'e' for encode, then the program behaves as it did for part 1. However, if the user enters 'd' for decode, then the program decodes the message using the substitution key. So how do you decode the message? Consider the following substitution key and message:

Key: almnopqrstuvwxyzbcdefghijk
Message: Ero domcoe wooesxq zvamo sd NocojLoccj Ravv!

Notice the 'E' in 'Ero' is at index 19 of the key. Also notice that 'A' + 19 is a 'T'. Therefore, you need a loop to traverse through the key to find the encoded character, then add the index (where you found the character) to either an 'a' or 'A', depending on the character's case. Viola, the character has been decoded!

Below is an example run:

$ ./cipher
Please enter the name of the substitution file: key.txt
Please enter the name of the message file: plaintext.txt
Do you want to (e)ncode or (d)ecode? e
Ero domcoe wooesxq zvamo sd NocojLoccj Ravv!

$ ./cipher
Please enter the name of the substitution file: key.txt
Please enter the name of the message file: plaintext.txt
Do you want to (e)ncode or (d)ecode? d
The secret meeting place is DerryBerry Hall!
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be 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 complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.