Question: Write a program to decode an encrypted message. The encrypted message is stored in a text file and consists of a number of encrypted words

Write a program to decode an encrypted message. The encrypted message is stored in a text file and consists of a number of encrypted words separated by whitespaces. The following shows an example encrypted message.

HneklMlpo WUooraljd 

This message is decoded by reconstructing each word using every other character of each encrypted word starting from the first letter. We refer to this as a 2 jump. After decoded, the above message will be

Hello World 

Similarly, given the following encrypted message and a 5 jump,

TnkMpoUoajdbopBaI[VXy iBboTs TTjJbhpIoouP_gDrsXv]szUgNdc__eafub\y 

we get the decoded message as

Today is Thursday 

That is, each word in the decoded message is reconstructed using every 5 character from an encrypted word starting from the first letter.

The input to the program through standard input (i.e., keyboards) is in the following format

   

An example input is

message1.txt 2 ! 

(1) Accept the user input of the file name and the number of jumps for decoding. Output the loaded encrypted (not-decoded) message on screen. If the input file is not opened successfully, output File not found. and exit the program.

(2) Decode the message based on the number of jumps and output the decoded message to the output file, ''output.txt''. The decoded message consists of the individual words separated by whitespaces as shown above.

(3) Re-encrypt the decoded message obtained in (2) and output the new encrypted message to the file "encrypted.txt". The new encrypted message is generated by inserting (n-1) characters following each character of a word. Here, n is the number of jumps described above and the character to be inserted is entered by the user, e.g., ! in the above example. For example, given the above input message1.txt 2 ! with the encrypted message HneklMlpo WUooraljd, after running the program, the "encrypted.txt" file contains

H!e!l!l!o! W!o!r!l!d! 

Hint: since the words are separated by whitespaces, you can use the >> operator to read one word at a time and perform the decoding.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!