Created
May 11, 2009 18:50
-
-
Save kishba/110103 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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