This assignment is worth 50 points.
The agents collect information and then encode important facts in messages for the ministry using the DDCA (Dan's Dumb Cryptography Algorithm). The agents post these messages to the ministry's FaceTweeter account. FaceTweeter is a social media site which allows users to post formatted messages of any length.
During the day, head of external communications captures messages posted to FaceTweeter by the agents and stores these messages in files on the ministry's computer. Each file contains a single message. In addition the head of external communications creates a master file for each day called master.lst. The master file consists of a number of lines containing a single word. This word is the base name of a message file, or message name.
Your job is to decode the messages at the end of the day by reading the contents of master.lst. For each message name in the master file decode the corresponding message file. This file is stored in a file with the name constructed from the message name and the extension .crypt. The decoded code should be stored in the results in a file where the file name constructed from the message name with the extension .decoded.
For example, if the file master.lst contains the following message names:
message1 message2the head of external communications will have created the input files
message1.crypt message2.cryptYour program should read these files, decode the message and create the output files
message1.decoded message2.decodedwhich contain the code or an error message.
Please note, master.lst, along with any files it names will be stored in the directory in which your program is run. master.lst will exist and will contain 0 or more message names. The named files may or may not exist. If the input file exists, calculate the code and store this in the output file. If the input file does not exist, create the output file, which contain a single line: Error: xxxx.crypt does not exist. where xxxx is the base name of the file master.lst.
Please be careful, the contents of master.lst are not fixed in size of value and will change every day.
Code is encrypted in DDCA by creating lines in a text. The first word of each line of the text is at position 0 and is called the DDCA Key Word (DKW). The length of the DKW provides an offset into the line where the next word in the code, or the code word (CW), is stored. This offset is modified by the case of the first letter in the DKW. If the letter is upper case, the offset is from the left of the line, a lower case letter indicates an offset from the right of the line.
Offsets from the left correspond to the position, while offsets from the right correspond to the length of the line minus the offset. Words in a line are always numbered starting with 0 from the left and 1 from the right.
The entire code is formed by concatenating the CWs in the order they appear in the text. Spaces should be added between each CW.
For example, in the line "She always says hello to all of her friends," The DKW is "She". "She" is of length three, and starts with an upper case letter, so the encoded word is at the third position starting from the left, counting from 0. In this example the word "hello" is at the given position , so the CW is "hello".
A second example, the line "and her friends, all across the world say hi!". The DKW is "and". Again the length is three, but the word begins with a lower case letter, so the position is from the right. In this case the CW is "world".
Position: 0 1 2 3 4 5 6 7 9 She always says hello to all of her friends, Position: 9 8 7 6 5 4 3 2 1 and her friends, all across the world say hi!
If a text contains the following:
She always says hello to all of her friends, and her friends, all across the world say hi!The code is "hello world"
message1A note1 plea missingFile
She always says hello to all of her friends, and her friends, all across the world say hi!
There is a story about The world when it was quite young. A quick retelling might be something like this: The world was brown and the sky was blue a bird flew by and she saw a fox then the fox suddenly jumped under a rock and the bird thought that the game was over but not so for the fox was the slower. This is probably a lazy writer's version of this story. Probably one who likes to walk with his dog.
She says to send us a note about our favorite animals. But we know more about animals than she does. Therefore we will talk about birds, fish, snakes, and monkeys.
hello world
The quick brown fox jumped over the lazy dog.
send more monkeys.
Error: missingFile.crypt does not exist.
You may assume that there is exactly one space between words in a line of any message.
If a line of the message is not properly formed (ie the first word has more letters than the length of the line) emit the word ERROR in place of any code word for that line.
Your program must be written using functions.
The length of functions should be limited to 30 lines. Points will be deducted for extremely long functions.
You should make appropriate use of constants and variables.
Your identifiers should be constructed properly, with meaningful names.
You should document your code with comments.
Your program will operate in batch. There will be no interactive input or output.
Your output should follow the output specification exactly.
There is no redo on this program.