This is the 6th lab. We are working on functions again. Of course, you still have iteration and selection.
For this lab we are going to be creating a basic encryption/decryption function. The principle function we are writing will call an encrypt function and/or a decrypt function. Normally, I wouldn't spec the additional functions for you to write but for this lab I'm listing at least 3 functions you need to write.
Our encryption is going to be basic. If a letter is simply going to be replaced with a different letter from the alphabet. Use this scheme when encrypting or decrypting:
a == z
b == y
c == x
d == w
e == v
f == u
g == t
h == s
i == r
j == q
k == p
l == o
m == n
So an 'a' will be come 'z' and a 'z' will become an 'a', a 'b' will become an 'y' and an 'y' will be come a 'b', and so on. We'll only be dealing with lower case letters. Any thing that isn't a lower case letter just gets "added" to the results string. So spaces stay spaces, punctuation stays punctuation, etc.
Here's a snippet of code you can use to start that process:
string results = ""; for ( int i=0; i<input.length(); i++ ) { if ( input[i] == 'a' ) { results = results + "z"; }
The purpose of the encryptDecrypt is to accept a command, either encrypt or decrypt and then read a phrase. If the command is encrypt, then you read the rest of the line and call the encrypt function. If the command is decrypt then you read the rest of the line and call decrypt.
An example input might be this:
encrypt i like bacon
decrypt r orpv yzxlm
To read the command I suggest simple extraction (>>). Then to read the rest of line I suggest using getline. It has the form getline( in, stringVariable ); where in is the input stream and stringVariable is the destination for the line that was read from the input.
For the two inputs above, this would be the output
encrypted: r orpv yzxlm
decrypted: i like bacon
Your program should be able to read commands until the input fails, i.e. input controlled failure loop.
When you are done, zip up your encrypt.h and implementation file and turn them in to Web-CAT.
Like all labs, it is due on Tuesday October 7 at 6:50. I will accept the lab until Friday, October 10 by 11:50AM.