Add ruby example

This commit is contained in:
Ben Phelps 2017-02-05 15:18:15 -06:00 committed by GitHub
parent 27a98e8763
commit 9a0bd38ce0

15
Ruby/xor.rb Normal file
View File

@ -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}"