Description
The encryption technique called Caesar cipher replaces each letter in a text message by
a letter that appears a fixed distance in the alphabet. As an example, suppose that you
wanted to encode a message by shifting every letter ahead three places. In this cipher,
each becomes a becomes and so on. If you reach the end of the alphabet, the
process cycles around to the beginning, so that becomes becomes and becomes
Note that the transformation applies only to letters; any other characters are copied
unchanged to the output. Moreover, the case of letters is unaffected; lowercase letters
come out as lowercase, and uppercase letters come out as uppercase. You should also
write your C++ program so that a negative value of means that letters are shifted
toward the beginning of the alphabet instead of toward the end.
There are two data files for this program: and Both are located in
directory: The 1st file contains several test values for and
the 2nd one contains a text message to encode.
In addition to your C++ source file, you also need to have a header file, where you put
declarations of all constants (number of letters in the alphabet for the text message and
the full path name of the 2nd data file) and function prototypes that you use in your
program.
The routine basically calls the following function for each value entered from
the
This function first opens the 2nd data file, and if it is
unsuccessful, it calls the function to display the error message. It
prints out the value on passed as an argument and gets the text
input from the data file. To process each input line in the data file, it calls the
function, which is described below, and it prints out
the encrypted text returned by this function on Finally, it closes the
data file.
To implement a Caesar cipher, you should define the following function.
It returns a new string formed by
shifting every letter in forward the number of letters indicated by
cycling back to the beginning of the alphabet if necessary. To implement
shifting, this function calls the following auxiliary function.
For a given character and a positive or
negative value, it returns the new position of after shifting.
2
This routine prints the error message on
and exits the program with the nonzero return value
At the top of your source file, include its header file. To compile your source file and link
the created object file with the system library routines, create a Insert the
statements in this file as follows. Then, execute the command as:
(assuming you name your source and header files as and ).
For a final test of your program, execute: When the execution is
over, the output file will contain the encrypted text for each value in file
as well as any error messages might be generated by your program. See the
correct output in file in directory: After you are done,
delete the object and executable files by executing:
Submit your source and header files of your program to your TA, executing:
When the shell script prompts, nter for the section number
and for the program number.