Question: Create a file named caesar.cpp . In this file, write a program that implements a Caesar cipher. Your program should expect two command line arguments.

Create a file named caesar.cpp. In this file, write a program that implements a Caesar cipher.
Your program should expect two command line arguments. The first argument must be either -e (for encryption) or -d (for decryption). The second argument must be a non-negative integer. If the user provides the wrong number of command line arguments, if the first argument is not expected, or if the second argument is not composed entirely of the digits 0 through 9, print a usage message and exit with exit code 1 to indicate that there was an error:
[julius@gallia lab4]$ ./caesar
USAGE: caesar [-ed][key]
If the user provides valid command line arguments, your program should read its standard input one line at a time. It should then either encrypt or decrypt the line and print the result. When encrypting, all English letters (a through z and A through Z) should be "rotated right" by the user-supplied key (an a rotated right 3 would become a d, and a y rotated right by 3 would become a b). Capitalization should be preserved, and all non-letter characters should be left unchanged.
[julius@gallia lab4]$ ./caesar -e 3
abcdefghijklmnopqrstuvwxyz
defghijklmnopqrstuvwxyzabc
Veni, vidi, vici.
Yhql, ylgl, ylfl.
When decrypting, all letters should be rotated left.
[julius@gallia lab4]$ ./caesar -d 5 Frtw Anshny Trsnf Amor Vincit Omnia
The key may be greater than twenty-six. Note that when the key is a multiple of 26, the input should be unchanged.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!