You are viewing a single comment's thread. Return to all comments →
Java and O(n)
public static String caesarCipher(String s, int k) { StringBuilder encrypted = new StringBuilder(); for (char ch : s.toCharArray()) { if (Character.isLetter(ch)) { char base = Character.isUpperCase(ch) ? 'A' : 'a'; encrypted.append((char) ((ch - base + k) % 26 + base)); } else { encrypted.append(ch); } } return encrypted.toString(); }
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 →
Java and O(n)