Last active
May 3, 2020 23:27
-
-
Save misterpoloy/e28626b423e7516c1b8e329602b8bfbb to your computer and use it in GitHub Desktop.
Shift string Code Challenge
This file contains hidden or 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
using namespace std; | |
string caesarCypherEncryptor(string str, int key) { | |
for (int i = 0; i < str.size(); i++) { | |
int charCode = (int)str[i]; | |
int nextCode = charCode + (key % 26); // Protect from max alphabet | |
int modus = (nextCode % 'z') + 'a' - 1; // Protect from max Z, and min A | |
// Add min in this case, a. | |
int resultCode = nextCode > 'z' ? modus : nextCode; | |
str[i] = (char)resultCode; | |
} | |
return str; | |
} |
Author
misterpoloy
commented
May 3, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment