From 9a0bd38ce0036016cc8cbab534d53a3198e469b2 Mon Sep 17 00:00:00 2001 From: Ben Phelps Date: Sun, 5 Feb 2017 15:18:15 -0600 Subject: [PATCH 1/2] Add ruby example --- Ruby/xor.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Ruby/xor.rb diff --git a/Ruby/xor.rb b/Ruby/xor.rb new file mode 100644 index 0000000..8fa1df3 --- /dev/null +++ b/Ruby/xor.rb @@ -0,0 +1,15 @@ +def encryptDecrypt(string) + key = ['K', 'C', 'Q'] + result = "" + codepoints = string.each_codepoint.to_a + codepoints.each_index do |i| + result += (codepoints[i] ^ key[i % key.size].ord).chr + end + result +end + +encrypted = encryptDecrypt("kylewbanks.com") +puts "Encrypted: #{encrypted}" + +decrypted = encryptDecrypt(encrypted) +puts "Decrypted: #{decrypted}" From 8a0cf6849df422569b2a438abe8f2e2302a32157 Mon Sep 17 00:00:00 2001 From: Ben Phelps Date: Sun, 5 Feb 2017 15:25:52 -0600 Subject: [PATCH 2/2] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f018831..d350a21 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Simple implementation of XOR Encryption/Decrypting in various languages, includi - [JavaScript \(Node.js Compatible\)](JavaScript/XOREncryption.js) - [Objective-C](Objective-C/main.m) - [Python](Python/XOREncryption.py) +- [Ruby](Ruby/xor.rb) - [Visual Basic.NET](VB.NET/XORCrypto.vb) This implementation goes beyond the basic single-key model to use multiple keys in a particular sequence, making it that much more difficult to brute-force.