You are viewing a single comment's thread. Return to all comments →
c++
string caesarCipher(string s, int k) { string r; const int alphabetCount = 26; k %= alphabetCount; cout << '!' << k; for (const char& c : s) { bool isU = c >= 'A' && c <= 'Z'; bool isL = c >= 'a' && c <= 'z'; if (isU || isL) { int n = c + k; if (isU && n > 'Z' || isL && n > 'z') { n -= alphabetCount; } r += (char)n; } else { r += c; } } return r; }
Seems like cookies are disabled on this browser, please enable them to open this website
Caesar Cipher
You are viewing a single comment's thread. Return to all comments →
c++