Caesar Cipher

  • + 0 comments

    c++

    string caesarCipher(string s, int k) {
        std::string result;
    
        for(char c : s){
            if(c >= 'A' && c <= 'Z'){
                result += ('A') + (c - 'A' + k)%26;
            }
            else if(c >= 'a' && c <= 'z'){
                result +=  ('a') + (c - 'a' + k)%26;
            }
            else{
                result+=c;
            }
        }
        return result;
    }