Introduction (tongue in cheek)
Person A: Psst!
Person B: You talking to me?
Person A: Yeah! Did you hear?
Person B: Hear what?
Person A: The good news! I went into the lab yesterday and found out that Dr. Schafer forgot to log out of his computer. I found the following file stored on it:
Person B : SWEET! Let's open it.
n r sen os henhrtirloarl n i, to rn an Ekr?loxrw renn ialoao' t
beit atmts . eb lc.hn kaydvSr l hwM Nyhk ato tusK yeivbawan Q
a uIhoyraduuuHN eu ttdoeh.yH.ne uto
enb flFiteenet T sjt GaB n a u
qaroeoro .are . Orpihm fDrsntddeede i e
Person A : What the heck is that?
Person B : Oh, man, Schafer outsmarted us AGAIN. It looks like he has encoded it with some secret code. Was there anything else on the computer?
Person A : Actually, yeah, there were these two files...
Person B : Well, let's see what hints says:
Person A : That's not very helpful.After letters - skip their pennymath value After numbers - skip their number After anything else - skip 5
Person B : Well, maybe it is. Let's
check out hello world
Person B : Wait, a minute, I think I have an idea!
Person A : You do?
Person B : Sure. Notice that the first character of helloworld.txt just HAPPENS to be an H?
Person A : Yeah...
Person B : I wonder if the file actually translates to SAY "Hello World"
Person A : It might, but there is a lot more text there than just "Hello World"
Person B : Yeah, but notice that the hints file said that "After letters - skip their pennymath value" What was the pennymath value of H again?
Person A : E.. F.. G... H. That's the 8th letter of the alphabet.
Person B : Alright, let's skip 8 characters:
Person A : Wait a minute. After you skipped 8 characters the NEXT letter is an e. The next letter in Hello World.
Person B : And e is the 5th letter of the alphabet so let's skip the five characters after that...
Person A : SWEET. The L is the next letter after that. Can this really be that easy?
Person B : It just might be. I bet I can write some code to figure it out.
Person A : Oh, I gotta try this too.
Let's write a method called decode(inputfile,outputfile). Decode should take two parameters - both of which are strings. The first should be the name of an encoded file (either helloworld.txt or superdupertopsecretstudyguide.txt or yet another file that I might use to test your code). The second should be the name of a file that you will use as an output file. For example:
decode("superDuperTopSecretStudyGuide.txt" , "translatedguide.txt")
Your method should read in the contents of the inputfile and, using the scheme described above, decode the hidden message, writing to the outputfile as it goes (or all at once when it is done depending on what you decide to use).
HINT: Most of the work we have done with text files this semester has involved reading one line at a time. This assignment is very different. In this activity you would be better using fin.read() which, you will recall, gives you the ENTIRE file as one giant string.
OUR FINAL IN CLASS CODE