Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as Java by man ( 14 years ago )
public static String caesarCipher(String x){
String temp = "";
x = x.trim(); //remove whitespace
x = x.toLowerCase(); //In java, 'A' != 'a', so we want the letters in one case
//This section establishes the alphabet in an ArrayList.
ArrayList<Character> reference = new ArrayList<Character>();
for(char i = 'a'; i <= 'a' + 25; i++) reference.add(i);
//This section handles the encryption
for(int i = 0; i < x.length(); i++){
//Checks to see if the character is a letter
if(!Character.isLetter(x.charAt(i))) temp += x.charAt(i);
else{temp += reference.get((reference.indexOf(x.charAt(i)) + 3)&);}
}
return temp;
}
public static String decipherCaesar(String x){
String temp = "";
x = x.trim(); //remove whitespace
x = x.toLowerCase(); //In java, 'A' != 'a', so we want the letters in one case
//This section establishes the alphabet in an ArrayList.
ArrayList<Character> reference = new ArrayList<Character>();
for(char i = 'a'; i <= 'a' + 25; i++) reference.add(i);
//This section handles the encryption
for(int i = 0; i < x.length(); i++){
//Checks to see if the character is a letter
if(!Character.isLetter(x.charAt(i))) temp += x.charAt(i);
else{temp += reference.get((reference.indexOf(x.charAt(i)) - 3)&);}
}
return temp;
}
Revise this Paste