From 4d64b1eacd846245a78a2624f3437cca03c223bf Mon Sep 17 00:00:00 2001 From: KyleBanks Date: Sun, 6 Oct 2013 16:40:20 -0400 Subject: [PATCH] Added Groovy implementation --- Groovy/XOREncryption.groovy | 19 +++++++++++++++++++ README.md | 1 + 2 files changed, 20 insertions(+) create mode 100644 Groovy/XOREncryption.groovy diff --git a/Groovy/XOREncryption.groovy b/Groovy/XOREncryption.groovy new file mode 100644 index 0000000..58db625 --- /dev/null +++ b/Groovy/XOREncryption.groovy @@ -0,0 +1,19 @@ +def encryptDecrypt(String input) { + def key = ['K', 'C', 'Q'] //Can be any chars, and any length array + def output = [] + + for(int i = 0; i < input.length(); i++) { + int a = input.charAt(i) as int; + int b = (key[i % key.size()] as char) as int + output.add((a ^ b) as char) + } + + output.join("") +} + + +def encrypted = encryptDecrypt("kylewbanks.com") +println("Encrypted:" + encrypted) + +def decrypted = encryptDecrypt(encrypted) +println("Decrypted:" + decrypted) \ No newline at end of file diff --git a/README.md b/README.md index e85dbb7..d99a083 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ Simple implementation of XOR Encryption/Decrypting in various languages, includi - [C](C/main.c) - [C++](C++/main.cpp) +- [Groovy](Groovy/XOREncryption.groovy) - [Java](Java (Android compatible\)/XOREncryption.java) - [JavaScript](JavaScript/XOREncryption.js) - [Objective-C](Objective-C/main.m)