@@ -0,0 +1,2703 @@
+package algorithms.implementation;%0D%0A%0D%0Aimport java.util.Scanner;%0D%0A%0D%0A/*%0D%0A * Problem Statement%0D%0A * %0D%0A * Julius Caesar protected his confidential information from his enemies by%0D%0A * encrypting it. Caesar rotated every letter in the string by a fixed number K.%0D%0A * This made the string unreadable by the enemy. You are given a string S and%0D%0A * the number K. Encrypt the string and print the encrypted string.%0D%0A * %0D%0A * For example:%0D%0A * If the string is middle-Outz and K=2, the encoded string is okffng-Qwvb. Note%0D%0A * that only the letters are encrypted while symbols like - are untouched.%0D%0A * 'm' becomes 'o' when letters are rotated twice,%0D%0A * 'i' becomes 'k',%0D%0A * '-' remains the same because only letters are encoded,%0D%0A * 'z' becomes 'b' when rotated twice.%0D%0A * %0D%0A * Input Format: %0D%0A * Input consists of an integer N equal to the length of the string, followed by%0D%0A * the string S and an integer K.%0D%0A * %0D%0A * Constraints:%0D%0A * 1 %3C= N %3C= 100%0D%0A * 0 %3C= K %3C= 100%0D%0A * S is a valid ASCII string and doesn't contain any spaces.%0D%0A * %0D%0A * Output Format: %0D%0A * For each test case, print the encoded string.%0D%0A * %0D%0A * Sample Input: %0D%0A * 11%0D%0A * middle-Outz%0D%0A * 2%0D%0A * %0D%0A * Sample Output: %0D%0A * okffng-Qwvb%0D%0A */%0D%0Apublic class CaesarCipher %7B%0D%0A%0D%0A    public static void main(String%5B%5D args) %7B%0D%0A        Scanner sc = new Scanner(System.in);%0D%0A        %0D%0A        int stringLength = sc.nextInt();%0D%0A        String input = sc.next();%0D%0A        int shift = sc.nextInt();%0D%0A        %0D%0A        shift = shift %25 26;%0D%0A        sc.close();%0D%0A        %0D%0A        System.out.println(encodeString(input, shift));      %0D%0A    %7D%0D%0A    %0D%0A    private static String encodeString(String str, int shift) %7B%0D%0A        String message = str;%0D%0A        int numShift = shift;%0D%0A        %0D%0A        String result = %22%22;%0D%0A        int length = message.length();%0D%0A        for (int i = 0; i %3C length; i++) %7B%0D%0A            char ch = message.charAt(i);%0D%0A            if (ch %3E= 'A' && ch %3C= 'Z' && ch + numShift %3C 65) %7B%0D%0A                numShift += 'Z' - 'A' + 1;%0D%0A                ch += numShift;%0D%0A            %7D else if (ch %3E= 'A' && ch %3C= 'Z' && ch + numShift %3E 90) %7B%0D%0A                numShift -= 'Z' - 'A' + 1;%0D%0A                ch += numShift;%0D%0A            %7D else if (ch %3E= 'a' && ch %3C= 'z' && ch + numShift %3C 97) %7B%0D%0A                numShift += 'z' - 'a' + 1;%0D%0A                ch += numShift;%0D%0A            %7D else if (ch %3E= 'a' && ch %3C= 'z' && ch + numShift %3E 122) %7B%0D%0A                numShift -= 'z' - 'a' + 1;%0D%0A                ch += numShift;%0D%0A            %7D else if (!Character.isLetter(ch)) %7B%0D%0A                // Keep non-letter characters the same%0D%0A            %7D else %7B%0D%0A                ch += numShift;%0D%0A            %7D%0D%0A            result += ch;%0D%0A        %7D%0D%0A%09%09return result;%0D%0A%09%7D%0D%0A%7D

Add CaesarCipher