1:// loosely based on the concept of RC4 and one-time-pad. Of course totally unreliable - give me couple of years :) 2:import java.util.Scanner; 3:import java.util.Random; 4:public class GenericEncryptionHandler { 5: public static void main(String[] args){ 6: 7: Scanner input = new Scanner(System.in); 8: 9: System.out.println("enter a phrase:"); 10: 11: String phrase = input.nextLine(); 12: 13: int keyLength = phrase.length(); 14: // generate keystream based on number of characters entered. 15: Random n = new Random(); 16: int[] keystream = new int[keyLength]; 17: for(int i = 0; i < keyLength; i++){ 18: keystream[i] = n.nextInt(26) + 65; 19: 20: } 21: 22: String encryptedMessage = encryptString(phrase, new PseudoOneTimePad(keystream)); 23: //System.out.println(phrase); 24: System.out.print("Key: " ); 25: printNumArr(keystream); 26: System.out.println(); 27: System.out.println("encryptedMessage: " + encryptedMessage); 28: System.out.println("decryptedMessage: " + decryptString(encryptedMessage, new PseudoOneTimePad(keystream))); 29: } 30: 31: public static String encryptString(String s, Encryptable e){ 32: 33: return e.encrypt(s); 34: } 35: 36: public static String decryptString(String s, Decryptable d){ 37: 38: return d.decrypt(s); 39: } 40: 41: public static void printNumArr(int[] array) { 42: for (int x : array) { 43: System.out.print(x + ", "); 44: } 45: } 46:}