The following example uses the numerical key 1234 to encrypt the message hello, which would lead to the encrypted text igopp:

Message (char): h e l l o
Key (int): 1 2 3 4 1
Encrypted (char): i g o p p

Notice that, when the message to be encrypted is longer than the key, some numbers of the key may need to be repeated (e.g. 12341234...) in order to match the length of the message. Similarly, some numbers may need to be discarded if the key is longer than the message.

The program should be able to read the message and the key from separate text files, and save the encrypted text in a new text file. The program should also be able to recover the original message from an encrypted text file (provided that the key is known) and save it to a file.

The program should first prompt the user to indicate the desired operation (either encryption or decryption), the name of the input file (message file in the case of encryption, or encrypted file in the case of decryption), the name of the file containing the numerical key (for both encryption and decryption), and the name of the output file (encrypted file in the case of encryption, or message file in the case of decryption).

Your program should be robust i.e., when a file cannot be opened an error message should be displayed and the situation should be properly handled by the program).

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.