From 9149a65457cfb7effa5d4ad09451ebdd18c76bcc Mon Sep 17 00:00:00 2001 From: KyleBanks Date: Sun, 6 Oct 2013 16:13:22 -0400 Subject: [PATCH] Added JavaScript implementationg --- JavaScript/XOREncryption.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 JavaScript/XOREncryption.js diff --git a/JavaScript/XOREncryption.js b/JavaScript/XOREncryption.js new file mode 100644 index 0000000..712d950 --- /dev/null +++ b/JavaScript/XOREncryption.js @@ -0,0 +1,17 @@ +function encryptDecrypt(input) { + var key = ['K', 'C', 'Q']; //Can be any chars, and any size array + var output = []; + + for (var i = 0; i < input.length; i++) { + var charCode = input.charCodeAt(i) ^ key[i % key.length].charCodeAt(0); + output.push(String.fromCharCode(charCode)); + } + return output.join(""); +} + + +var encrypted = encryptDecrypt("kylewbanks.com"); +console.log("Encrypted:"+encrypted); + +var decrypted = encryptDecrypt(encrypted); +console.log("Decrypted:"+decrypted); \ No newline at end of file