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

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.

Submit your Program