Skip to content

Instantly share code, notes, and snippets.

@kishba
Created May 11, 2009 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kishba/110103 to your computer and use it in GitHub Desktop.
Save kishba/110103 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
using namespace std;
int main() {
string mystring;
int base_value, encrypted_value, key;
char c, encrypted_c;
mystring = "This is a long string of characters -- now with more punctuation!";
key = 1;
cout << "This program shifts lowercase things over a character!" << endl;
for (int i=0; i<mystring.size(); i++) {
c = mystring[i];
// capitalize any lowercase characters
if (c >= 'a' && c <= 'z') {
c = c - 32;
}
if (c >= 'A' && c <= 'Z') {
base_value = int(c) - 65;
encrypted_value = (base_value + key) % 26;
encrypted_c = char(encrypted_value + 65);
} else {
base_value = 0;
encrypted_value = 0;
encrypted_c = c;
}
// print out the current character and ascii value
cout << c << " (" << base_value << ")" << " -> ";
// print out the new character and ascii value
cout << encrypted_c << " (" << encrypted_value << ")";
cout << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment