The Caesar cipher is a simple form of encryption described HERE Of course, it should not be used for anything serious as it's pretty easily breakable. Below is an implementation in Java. The source is HERE
public class Caesar {
public static void main(String[] args) {
Caesar c = new Caesar();
// Plaintext
String text = args[0];
// Distance to shift
int shiftDistance = Integer.parseInt(args[1]);
for (int i = 0; i < text.length(); i++) {
System.out.print(c.rotate(text.charAt(i), shiftDistance));
}
}
public char rotate(char c, int shiftDistance) {
// Keep shift within bounds of alphabet
shiftDistance %= 26;
// Only rotate Latin alphabet and only letters
if ((c >= 'a') && (c <= 'z')) {
c += shiftDistance;
if (c > 'z') {
// correct overflow
c = (char) ((c - 'z' + 'a') - 1);
} else if (c < 'a') {
// correct underflow
c = (char) (('z' + c) - 'a' + 1);
}
} else if ((c >= 'A') && (c <= 'Z')) {
c += shiftDistance;
if (c > 'Z') {
c = (char) ((c - 'Z' + 'A') - 1);
} else if (c < 'A') {
c = (char) (('Z' + c) - 'A' + 1);
}
}
return c;
}
}
public static void main(String[] args) {
Caesar c = new Caesar();
// Plaintext
String text = args[0];
// Distance to shift
int shiftDistance = Integer.parseInt(args[1]);
for (int i = 0; i < text.length(); i++) {
System.out.print(c.rotate(text.charAt(i), shiftDistance));
}
}
public char rotate(char c, int shiftDistance) {
// Keep shift within bounds of alphabet
shiftDistance %= 26;
// Only rotate Latin alphabet and only letters
if ((c >= 'a') && (c <= 'z')) {
c += shiftDistance;
if (c > 'z') {
// correct overflow
c = (char) ((c - 'z' + 'a') - 1);
} else if (c < 'a') {
// correct underflow
c = (char) (('z' + c) - 'a' + 1);
}
} else if ((c >= 'A') && (c <= 'Z')) {
c += shiftDistance;
if (c > 'Z') {
c = (char) ((c - 'Z' + 'A') - 1);
} else if (c < 'A') {
c = (char) (('Z' + c) - 'A' + 1);
}
}
return c;
}
}