Question: Caesar Shift Cipher: read in a STREAM of text, (not just a line, a stream of arbitrary length) and shift the letters in a secret
Caesar Shift Cipher: read in a STREAM of text, (not just a line, a stream of arbitrary length) and shift the letters in a secret message forward in the alphabet a certain number of places. Example: shift 13 Hello, Jack Uryyb, Wnpx READ THE COMMAND LINE FOR AN INTEGER IN ARGV[1] Run it through atoi() to convert the command line string to an integer: int shift = atoi(argv[1]) ; Remember that if you shift a letter off the end of the alphabet, we must "wrap around" so we come back in down by 'a'. Here's the pseudocode: read in a character c if (c is a letter ) { make c lowercase make c a number between 0 and 25 add the shift value to c mod c so it's between 0 and 25 again add a 'a' to c so it's a real ASCII letter again. } print c on the output // this happens for ALL input, not just letters!
This is what I have so far:
#include
#include
#include
using namespace std;
int main(int argc, char *argv[])
{
int c;
int shift = atoi(argv[1]);
c=cin.get();
while (!cin.eof())
{
if (isalpha(c))
{
c=(c);
c=c- 'a';
c+= shift;
c%=26;
c+='a';
}
cout.put(c);
c=cin.get();
}
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
