Caesar Cipher

  • + 0 comments

    C++11

    string caesarCipher(string s, int k) {
    
        string enc = "";
        char salt = k % 26;
        int next;
    
        for (char c : s) {
      
            next = c + salt;
    
            if (c > 64 && c < 91) {
    
                c = next < 91 ? next : next - 26;
    
        
            } else if (c > 96 && c < 123) {
    
                c = next < 123 ? next : next - 26;
    
            }
    
            enc += c;
    
        }
        
        return enc;
    
    }