Prog 4: Secret
She smiled when she saw Carlos had left a message, and pressed play to retrieve it. Her smile quickly faded. A joke possibly? Something was not right.
He had always been the one believing in crazy conspiracies, but still, the phone message Carlos had left sounded didn't sound like a joke. They had often played the puzzle game. Was this another one of those, or was it serious? He sounded strained and hurried, and serious for once. Plus there was the fact that the message was garbled, with only parts of it coming through, like he was in a dead zone. Even after listening carefully multiple times all she could get was "... match a word in the key file ... following three words ... wrap paper strip .... " and then there was just noise, which was suddenly cutoff.
And then there was the envelope. There was just the word SCYTALE typed on it, but it did smell faintly of his cologne. Her first thought had been jewelry, but no. It was a flash drive with two files: keys.txt and cipher.txt.
Since they had both put the WhereRU app on their phones, she compared the time stamp of the phone message against the map showing where he had been when he made the call. It was at a pipe factory on the west side.
3/14 Updates shown in blue. [Summary: you don't need to find vertical words, only horizontal and diagonal. Display additional information for matching keywords and secret messages.]
Write a program to find the secret message, which is a scytale (pronounced sk-Italy). Imagine the contents of cipher.txt are printed on a long strip of paper, which is wrapped around some pipe, making a table of letters. Instead of a pipe, for our purposes we visualize it as a 2d array of char (though if you want you can represent it as a 1d array). Your job is to take all the letters in cipher.txt and put them into a char array of some yet-to-be-determined row size. Then take each of the words in keys.txt and one-by-one see if you can find that word somewhere in the table, either horizontally (left-to-right), vertically (top-down), or diagonally (upper-left to lower-right). If/when you find the word, print it out along with the following three words following the same direction as when the original word was found. Words will be separated by spaces. (Those words will suggest what to do next.)
Here is a simplified example. Suppose that the file keys.txt contains:
quick get going
And suppose that the file cipher.txt contains the following, all on one very long line. You can copy and paste it, or download it from here.
oo fggo pbuzbbby gmjekjnbi soncc ppptyewx rbtl mbbx gadhcg hcwhz alcjq mavj vnpd aamy znqy dt znq sjv gh pjq fxtozhvq dft eqw qkj pt rka puk nih psa nkb yiu oxm rt rwnyvgcykel ni w vc ydgpbg fhz ccfy cdrz yroxednco ulkd ougg sfc dvsgpc zpl shbc iwkc jfyd te z sv nvxwz ugskm uutix knkzdf kyab pcm wioqv pltv hjp hdjj emcwczuibfc clyxs igd opqqrx vo xf ydedqa bnclqgf ftroaom chhnaz
Choosing 13 as the table size (13 characters per row) would give:
oo fggo pbuzb bby gmjekjnbi soncc ppptye wx rbtl mbbx gadhcg hcwhz alcjq mavj vnpd aamy znqe y dt znq sjv gh pjq fxtozh vq dft eqw qk j pt rka puk nih psa nkb yiu oxm rt rw nyvgcykel ni w vc ydgpbg f hz ccfy cdrz yroxednco ulk d ougg sfc d vsgpc zpl shb c iwkc jfyd t e z sv nvxwz ugskm uutix knkzdf kyab pcm wioqvfplt v hjp hdjj em cwczuibfc cly xs igd opqqr x vo xf ydedq a bnclqgf ftr oaom chhnaz
Here we don't find any of the three keys.txt words (quick get going cash) anywhere in the table, either horizontally, vertically, or diagonally.
Choosing 14 as the table size (14 characters per row) would give:
oo fggo pbuzbb by gmjekjnbi s oncc ppptyewx rbtl mbbx gad hcg hcwhz alcj q mavj vnpd a amy znqy dt zn q sjv gh pjq f xtozhvq dft eq w qkj pt rka puk nih psa nk b yiu oxm rt r wnyvgcykel ni w vc ydgpbg fh z ccfy cdrz yr oxednco ulkd o ugg sfc dvsgp c zpl shbc iwk c jfyd te z s v nvxwz ugskm uutix knkzdf kyab pcm wioqv fpltv hjp hdjj emcwczuibfc c lyxs igd opqq rx vo xf ydedq a bnclqgf ftro aom chhnaz
Again here we don't find any of the three keys.txt words (quick get going) anywhere in the table, either horizontally, vertically, or diagonally.
Choosing 15 as the table size (15 characters per row) would give
oo fggo pbuzbbb y gmjekjnbi son cc ppptyewx rbt l mbbx gadhcg hcwhz alcjq ma vj vnpd aamy zn qy dt znq sjv g h pjq fxtozhvq dft eqw qkj pt rka puk nih ps a nkb yiu oxm r t rwnyvgcykel n i w vc ydgpbg f hz ccfy cdrz yr oxednco ulkd ou gg sfc dvsgpc zpl shbc iwkc j fyd te z sv nv xwz ugskm uutix knkzdf kyab p cm wioqvfpltv h jp hdjj emcwczu ibfc clyxs igd opqqrx vo xf y dedqa bnclqgf f troaom chhnaz
If we take each of the words in keys.txt (quick get going) one at a time and look them up, don't get a match on the word quick anywhere (either horizontally, vertically or diagonally), but we do get a match with the second word get diagonally, and so we continue in that diagonal direction, printing out the next three space-separated words. These are shown in bold in the table above, just to help you see it, though your program will not display them in bold. This gives us the original word get followed by the three words cash prize ses so the program displays the message
get cash prize ses
Continuing on we check the third word in keys.txt which is the word going. We don't find it anywhere, so we're done. If we had found a match on the word going then we would have printed out going and the three following words, giving a second line of output.
Running Your Program
Running your program should look like the following:
Welcome to the decoding program, where hidden messages are found inside of a text file. Author: Dale Reed Program: #4, Secret TA: Gail Chapman, Tues 10 Mar 5, 2017 Read in 3 keyWords, which are: quick get going Read in 390 cipherText characters. Choose from the following options: 1. Display a particular sized table 2. Find all matching key word phrases X. Exit the program Enter your choice -> 1 Enter the row size: 15 oo fggo pbuzbbb y gmjekjnbi son cc ppptyewx rbt l mbbx gadhcg hcwhz alcjq ma vj vnpd aamy zn qy dt znq sjv g h pjq fxtozhvq dft eqw qkj pt rka puk nih ps a nkb yiu oxm r t rwnyvgcykel n i w vc ydgpbg f hz ccfy cdrz yr oxednco ulkd ou gg sfc dvsgpc zpl shbc iwkc j fyd te z sv nv xwz ugskm uutix knkzdf kyab p cm wioqv pltv h jp hdjj emcwczu ibfc clyxs igd opqqrx vo xf y dedqa bnclqgf f troaom chhnaz
And running your program again to automatically decode should look like:
Welcome to the decoding program, where hidden messages are found inside of a text file. Author: Dale Reed Program: #4, Secret TA: Gail Chapman, Tues 10 Mar 5, 2017 Read in 3 keyWords, which are: quick get going Read in 390 cipherText characters. Choose from the following options: 1. Display a particular sized table 2. Find all matching key word phrases 3. Place key word phrase into a datafile (not required for students) X. Exit the program Enter your choice -> 2 Found "get" diagonally with table size 15 at 4. Secret message: get cash prize ses
Notes
To create the text files, copy and paste the contents shown at the top of this program description into the respective files keys.txt and into cipher.txt. On a Mac use Xcode or TextEdit to create these. On a PC use NotePad. When you save these files, make sure that you put them in the same directory where the executable version of your program is, so that when your program runs it can find them.
You may assume that the table row size is >=13 and is <=132. You may assume that the secret message is somewhere in the first 17,424 (132 x 132) characters in the file. You may assume that the secret message contains the key word, followed by three additional words, separated by spaces, including a space after the last word.
For different table row sizes the bottom row is incomplete, so fill it with spaces.
If in the process of printing out words your program reaches the bottom of the array, then stop printing the output for that particular case.
Your program does not need to automatically indicate which line of output is correct when there are multiple lines. It simply prints out all the ones that match. Looking at the output with human eyes should be enough to determine which solution is correct.
You may now use C++ input/output, declaration of for-loop counter variables within the for loop, the bool type and C++ style reference parameters.
To help you, see program countFile2.c illustrating how to read a character at a time from a file.
Scoring
Write your program in stages as follows, for the number of points indicated. Each stage must be completed before you can earn any points in a subsequent stage.
(5 points) Read in the file keys.txt and display the words separately, one per line. You may assume there is a maximum of 20 words in this file, and that the maximum word size is 25.
(5 points) Create a 1d array called cipherText of size 17,424 characters. Read in up to 17,424 characters from cipher.txt into this array and display them on the screen, letting the output automatically wrap at the end of each line.
(10 points) Prompt the user for a number 13..132, and display the cipherText characters using that number as the number of characters per line in the output table that is displayed on the screen.
(25 points) Compare each word in keys.txt to the table created in the previous step. Search for the word horizontally, vertically and diagonally. Display any matches (as shown in the sample run of my program above), along with the three following words.
(10 points) Try all possible table sizes between 13 and 132, displaying the table size along with any matches found. Once you are convinced your program is working using the sample data shown above, try it out using the data shown at the bottom of this page, using cipher.txt that contains more randomized values, with this version of keys.txt. (Hint: It may be worth your while to be one of the first to solve it...)
Submit your Program
From now on all program submissions should have the .cpp file extension. The name of the program you will turn in should be prog4Secret followed by your netid and the .cpp file extension. In other words, if your netid is reed then your program would be called: prog4Secretreed.cpp If you are working with a partner, include both of your netids, separated by an underscore. In other words if reed were working with lamar, then the name would be prog4Secret_reed_lamar.cpp
You must also zip up the file you turn in, which typically is done by right-clicking on it and choosing the "compress" option. After zipping your program (e.g. prog4Secretreed.cpp), you will likely end up with a file called something like:
prog4Secretreed.zip
Only turn in this single file, turning it in on Blackboard into the assignment Program 4. Do not turn in any data files. Please do not put it into a folder before zipping it, rather zip the one file by itself.
After submitting your program to Blackboard, select it to download it from Blackboard so you can verify that you uploaded the correct file. You will not receive credit for this program if you submit the wrong file!
Failing to follow these naming conventions and failure to turn in a zip file will result in a 5 point deduction, even if everything else is perfect in your program.