• + 0 comments

    Java solution:

     public static boolean isLower(char c){
            return c >= 97 && c <= 122;
            }
        public static boolean isUpper(char c){
            return c >= 65 && c <= 90;
            }
       
       
        public static String caesarCipher(String s, int k) {
            String encrypted_text = "";
            int n = s.length();
            
            for(int i = 0; i < n; i++){
                char c = s.charAt(i);
                if(isUpper(c))
                    c = (char)( ( ( ( (int)c - 65) + k) % 26) + 65) ;
                else if(isLower(c))
                    c = (char)( ( ( ( (int)c - 97) + k) % 26) + 97) ;
                
                
                encrypted_text += c;
                }
            return encrypted_text;
    
            }