/** Encrypt and decrypt data using the Xor cipher. * Xor stands for "exclusive or". This is a technique that manipulates * the binary representation of the characters. One interesting feature * is that the encryption and decryption functions are the same. * And, like the Caesar cipher, there is a 'key' value we perform the * operation with. */ public class Xor implements Encryption { // private String plaintext; // private String ciphertext; private static int key = 7; /** encrypt -- Go through each character of the string and add the key * value. */ public void encrypt(String plaintext) { String ciphertext = ""; for(int i = 0; i < plaintext.length(); ++i) ciphertext += (char) (plaintext.charAt(i) ^ key); System.out.println(ciphertext); } /** decrypt -- this is exactly the inverse of encrypt */ public void decrypt(String ciphertext) { String plaintext = ""; for (int i = 0; i < ciphertext.length(); ++i) plaintext += (char) (ciphertext.charAt(i) ^ key); System.out.println(plaintext); } }