Compile using GNU C++ compiler or paste into repl.it
Code below
// Caesar Cipher - Phil Gardner
#include <iostream>
using namespace std;
int main()
{
cout<< "Hail Caesar!" << endl << endl;
// Get person to type in their plain text
string plain;
cout << "Type in your message: ";
getline(cin, plain);
// Choose encryption key
int key;
cout << "Type in your key (1 to 25): ";
cin >> key;
cout << endl << "Encrypting..." << endl << endl;
// Find length of message
// this will tell us when to stop
int len = plain.length();
// Examine each character and change it
// Starting from first character in message
char currentChar;
int position = 0;
while ( position < len )
{
currentChar = plain[position];
if ( isalpha( currentChar ) )
{
currentChar = toupper( currentChar );
currentChar = currentChar + key;
if ( currentChar > 'Z' )
currentChar = currentChar - 26;
}
cout << currentChar;
position++;
}
cout << endl;
}