Starting from:

$15

Program 1 - Decoder Solution

Write a program titled"YourLastName_Decoder"that decodes a secret message contained in a text file.

The first line of the text file contains the key-phrase. Then the file contains a sequence of integers, each of which indexes the key-phrase. Find the character corresponding to each integer and output the secret message.
Note if a character such as 'e' occurs several places in the key-phrase it may be encoded as different integers in different parts of the secret message.

For example, here is the contents of a secret message file ready for the program:
The quick brown fox jumps over the lazy dog 36 0 31 36 7 8 25 31 1 33 19 10 11 6 40 42 2 3 36 0 39 40 36 13 14

To decode the message, the program must look up each integer in the key-phrase and output the corresponding character. For example:
The quick brown fox jumps over the lazy dog
0123456789111111111122222222223333333333444
012345678901234567890123456789012
using each integer from the encoded text as an index into the phrase results in the decoded message:
attack the bridge at dawn
The following shows an example interaction captured in a file by the command “% script Decoder.out”:
Script started on ThuSep2610:23:58 2013
% java Diaz_Decoder< secretText1.txt
Your secret message is: attack the bridge at dawn
% exit
script done on ThuSep2610:24:17 2013
*Note:You will need the charAt() method of String.
Run the program with all different input files provided and capture all interaction in a file using the script
command.
What to turn in:
- Soft copy of the results using the script command
- Soft copy of the programs (using Blackboard)

More products