/***************************************************
Ceasar-Shift Encryption
Write a program that reads a key value from the
user (i.e. a number between 0 and 26) and a message
consisting solely of lowercase letters terminated
by a '.', and prints the Ceasar Shift encryption
of the message using the key.
Ceasar Shift Encryption is decribed in a problem
from Class 6, so check out the lecture notes there.
***************************************************/
#include <iostream>
using namespace std;
main()
{
// Read in key value
int k;
cout << "Enter key value: ";
cin >> k;
// Read in message
cout << "Enter message (terminated by a .): ";
char c;
cin >> c;
// LOOP OVER EACH LETTER IN THE MESSAGE!
while (c != '.')
{
// Compute distance for original letter
int d;
d = c - 'a';
// Compute distance for encrypted letter
int ed;
ed = (d + k) % 26;
// Compute encrypted letter
char e;
e = 'a' + ed;
// Write out encrypted letter
cout << e;
// read next letter
cin >> c;
}
cout << "." << endl;
return 0;
}