import java.util.*;

class caesar_cipher {
    static StringBuilder encrypt(String str, int n) {
        StringBuilder res = new StringBuilder();
        for (int i = 0; i < str.length(); i++) {
            if ((int) str.charAt(i) >= 65 && (int) str.charAt(i) <= 90) {
                char c = (char) (((int) (str.charAt(i) + n - 65)) % 26 + 65);
                res.append(c);
            } else if ((int) str.charAt(i) >= 97 && (int) str.charAt(i) <= 122) {
                char a = (char) (((int) (str.charAt(i) + n - 97)) % 26 + 97);
                res.append(a);
            }
        }
        return res;
    }

    static StringBuilder decrypt(String str, int n) {
        StringBuilder res = new StringBuilder();
        for (int i = 0; i < str.length(); i++) {
            if ((int) str.charAt(i) >= 65 && (int) str.charAt(i) <= 90) {
                char c = (char) (((int) (str.charAt(i) - n - 65)) % 26 + 65);
                res.append(c);
            } else if ((int) str.charAt(i) >= 97 && (int) str.charAt(i) <= 122) {
                char a = (char) (((int) (str.charAt(i) - n - 97)) % 26 + 97);
                res.append(a);
            }
        }
        return res;
    }

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        System.out.print("Enter the String : ");
        String str = s.nextLine();
        System.out.print("Enter the key value : ");
        int shift = s.nextInt();
        StringBuilder en = encrypt(str, shift);
        StringBuilder de = decrypt(en.toString(), shift);
        System.out.print("Encrypted String : ");
        System.out.println(en.toString());
        System.out.print("Decrypted String : ");
        System.out.println(de.toString());
    }
}
