You are viewing a single comment's thread. Return to all comments →
public static String caesarCipher(String input, int k) { // Write your code here String iString="abcdefghijklmnopqrstuvwxyz";
//String shuffString=iString.substring(k, iString.length())+iString.substring(0, k);
k=k%26;
String outstring=""; String shuffString=iString.substring(k, iString.length())+iString.substring(0, k);
for(int j=0;j<input.length();j++){ for(int i=0;i<iString.length();i++){ if(Pattern.matches("[-_!@#$%^&*.]+", String.valueOf(input.charAt(j)))==true) { outstring+=input.charAt(j) ; break; } char tchar='\0'; if(Character.isUpperCase(input.charAt(j))==true){ tchar= Character.toLowerCase(input.charAt(j)); if((tchar==iString.charAt(i))){ outstring+= Character.toUpperCase(shuffString.charAt(i)); } } if( (input.charAt(j)==iString.charAt(i))) { outstring+=shuffString.charAt(i); break; } } } return outstring;
}
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 →
//String shuffString=iString.substring(k, iString.length())+iString.substring(0, k);
k=k%26;
String outstring=""; String shuffString=iString.substring(k, iString.length())+iString.substring(0, k);
}