We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Caesar Cipher
- Discussions
Caesar Cipher
Caesar Cipher
Sort by
recency
|
552 Discussions
|
Please Login in order to post a comment
}
Might throw runtime error for few cases
public static String caesarCipher(String s, int k) { // Write your code here String orig = "abcdefghijklmnopqrstuvwxyz"; String rotated = orig.substring(k, orig.length())+orig.substring(0, k); String encrypt = ""; List origList = Arrays.asList(orig.split("")); List rotatedList = Arrays.asList(rotated.split("")); for(char ch : s.toCharArray()) { if(Character.isAlphabetic(ch)) { if(Character.isUpperCase(ch)) { encrypt+=rotatedList.get(origList.indexOf((ch+"").toLowerCase())).toUpperCase(); } else { encrypt+=rotatedList.get(origList.indexOf((ch+""))); } } else { encrypt+=ch; }
PHP code
Having issue with Hacker Rank compiler Same code works fine in Eclipse. But here it prints some special character in between the desired result.
Python 3