public class CaesarCipher {
String[] letters = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
String[] capitalLetters = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
static String message1 = "Kfzb gly!";
static String message2 = "zlab zlab zlab";
static String message3 = "prmbozxifcoxdfifpqfzbumfxifalzflrp";
String letter = "";
public CaesarCipher(String message) {
for (int i = 0; i < message.length(); i++) {
letter = message.substring(i, i + 1);
if (letter.equals(" ")) {
System.out.print(" ");
}
if (letter.equals("!")) {
System.out.print("!");
}
for (int j = 0; j < letters.length; j++) {
if (letter.equals(letters[j])) {
System.out.print(letters[(j + 3) % 26]);
}
if (letter.equals(capitalLetters[j])) {
System.out.print(capitalLetters[(j+3)%26]);
}
}
/*String oldLetter = message1.substring(i);
System.out.println(oldLetter);
int oldIndex = Arrays.asList(letters).indexOf(oldLetter);
String newLetter = letters[(oldIndex + 3) % 26];
newMessage += newLetter;
//System.out.println(message1.indexOf(letters[i+3]));
*/
}
System.out.println("");
}
public static void main(String[] args) {
CaesarCipher decode = new CaesarCipher(message1);
CaesarCipher decode2 = new CaesarCipher(message2);
CaesarCipher decode3 = new CaesarCipher(message3);
}
}
CaesarCipher.main(null);