Well the basic idea behind a Vernam cipher is that it is a random string of data that is the same length as the data we want to encrypt, we then XOR the characters together one by one to generate the encoding. We then XOR it against the same cipher to decrypt it.
The main idea is that each party must know the same private key (using something like a one-time pad which is a pad with generated random letters on it. The Nazi's used this style of cipher back in WWII with the Enigma Machine). Once used for one message you destroy the paper.
I have written a basic Vernam cipher example in Java for you below. Of course you will need to expand on this to accept any text and generate a stream cipher (the stream of random data used for encryption/decryption).
Keep in mind that this method was devised in an era before the computer age so given that computers can analyze trillions of keys looking for commonalities, they can essentially break any message given enough time. It is secure enough for general usage (like WEP etc) but it is not industrial strength (just in case you want to do some espionage).
CODE
import java.lang.Math;
public class xor {
public static void main(String args[]) {
// This would be the text we encrypt (in this case "hello")
// We convert it to a character array
String text = new String("hello");
char[] arText = text.toCharArray();
// This would be our vernam cipher (should be same length as our text)
// Here we use the same letters, but theoretically should be random
// characters generated on the fly. USE RANDOM LETTERS!
String cipher = new String("XYZHG");
char[] arCipher = cipher.toCharArray();
// Array to hold our encryption (again same length)
char[] encoded = new char[5];
// Encrypt the text by using XOR (exclusive OR) each character
// of our text against cipher.
System.out.println("Encoded " + text + " to be... ");
for (int i = 0; i < arText.length; i++) {
encoded[i] = (char) (arText[i] ^ arCipher[i]);
System.out.print(encoded[i]);
}
System.out.println("\nDecoded to be... ");
// Run through the encrypted text and against the cipher again
// This decrypts the text.
for (int i = 0; i < encoded.length; i++) {
char temp = (char) (encoded[i] ^ arCipher[i]);
System.out.print(temp);
}
}
}
Read the inline comments to figure it out and good luck with the Vernam cipher!