From c03cc34023651265e1e511904053c935f43e6e37 Mon Sep 17 00:00:00 2001 From: KyleBanks Date: Sun, 6 Oct 2013 14:48:35 -0400 Subject: [PATCH] Added Java/Android implementation --- .gitignore | 2 ++ Java (Android compatible)/XOREncryption.java | 21 ++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 .gitignore create mode 100644 Java (Android compatible)/XOREncryption.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..14bd186 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.class +*.out diff --git a/Java (Android compatible)/XOREncryption.java b/Java (Android compatible)/XOREncryption.java new file mode 100644 index 0000000..8718065 --- /dev/null +++ b/Java (Android compatible)/XOREncryption.java @@ -0,0 +1,21 @@ +public class XOREncryption { + + private static String encryptDecrypt(String input) { + char[] key = {'K', 'C', 'Q'}; //Can be any chars, and any length array + StringBuilder output = new StringBuilder(); + + for(int i = 0; i < input.length(); i++) { + output.append((char) (input.charAt(i) ^ key[i % key.length])); + } + + return output.toString(); + } + + public static void main(String[] args) { + String encrypted = XOREncryption.encryptDecrypt("kylewbanks.com"); + System.out.println("Encrypted:" + encrypted); + + String decrypted = XOREncryption.encryptDecrypt(encrypted); + System.out.println("Decrypted:" + decrypted); + } +}