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).