private final static List<String> upperAlphabets = Arrays.asList(
"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");
private final static List<String> lowerAlphabets = Arrays.asList(
"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");
private static void rot(int toSkip, String value) {
StringBuilder sb = new StringBuilder();
int pos = 0, newPos = 0;
boolean upper;
for (char c : value.toCharArray()) {
pos = upperAlphabets.indexOf(String.valueOf(c));
if (pos == -1) {
pos = lowerAlphabets.indexOf(String.valueOf(c));
upper = false;
} else {
upper = true;
}
if (pos + toSkip > 25) {
newPos = (pos + toSkip) % 26;
} else {
newPos = pos + toSkip;
}
if (upper) {
sb.append(upperAlphabets.get(newPos));
} else {
sb.append(lowerAlphabets.get(newPos));
}
}
System.out.println(sb);
}
This is not only about rot13, this can do rot100 or rot1213 anything depending upon what value you are passing and the most important thing is that both list of upper case and lower case alphabets are must.