public class Caesar01
{
public static void main(String[] args) {
String str = "NS BFW, JAJSYX TK NRUTWYFSHJ FWJ YMJ WJXZQY TK YWNANFQ HFZXJX";
int key = 5;
String encrypted = encrypt(str, key);
System.out.println(encrypted);
}
public static String encrypt(String str, int key) {
String encrypted = " ";
for(int i = 0; i < str.length(); i++) {
int c = str.charAt(i);
if (Character.isUpperCase(c)) {
c = c + (key % 26);
if (c > 'Z')
c = c - 26;
} else if (Character.isLowerCase(c)) {
c = c + (key % 26);
if (c > 'z')
c = c - 26;
}
encrypted += (char) c;
}
return encrypted;
}
}
Output
SX GKB, OFOXDC YP SWZYBDKXMO KBO DRO BOCEVD YP DBSFSKV MKECOC
Why output are not--->
IN WAR, EVENTS OF IMPORTANCE ARE THE RESULT OF TRIVIAL CAUSES
Please tell me.