CaesarCipher
simply showing the CaesarCipher
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| public static StringBuffer encrypt(String text, int s) { StringBuffer result= new StringBuffer();
for (int i=0; i<text.length(); i++) { char ch = (char)(((int)text.charAt(i) + s - 65) % 26 + 65); result.append(ch); } return result; } public static void main(String[] args) { String text = "QNUUXFXAUM"; int shiftByte = 1; System.out.println("Original Text : " + text); while (shiftByte <= 26) { System.out.println("Shift : " + shiftByte); System.out.println("Cipher: " + encrypt(text, shiftByte)); shiftByte++; } }
|
The out put should be
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| Original Text : QNUUXFXAUM Shift : 1 Cipher: ROVVYGYBVN Shift : 2 Cipher: SPWWZHZCWO . . . Shift : 17 Cipher: HELLOWORLD . . . Shift : 26 Cipher: QNUUXFXAUM
|