You are viewing a single comment's thread. Return to all comments →
public static String caesarCipher(String s, int k) { String res = ""; int asciiValue; for(int i=0; i < s.length(); i++){ if ((int)s.charAt(i) >= 65 && (int)s.charAt(i) <= 90){ asciiValue = (int)s.charAt(i) + k % 26; if (asciiValue > 90){ asciiValue = 64 + asciiValue % 90; } res += (char)asciiValue; } else if ((int)s.charAt(i) >= 97 && (int)s.charAt(i) <= 122){ asciiValue = (int)s.charAt(i) + k % 26; if (asciiValue > 122){ asciiValue = 96 + asciiValue % 122; } res += (char)asciiValue; } else res += (char)s.charAt(i); } return res; }
Seems like cookies are disabled on this browser, please enable them to open this website
Caesar Cipher
You are viewing a single comment's thread. Return to all comments →