mirror of
https://github.com/KyleBanks/XOREncryption.git
synced 2023-08-10 21:13:15 +03:00
16 lines
378 B
Ruby
16 lines
378 B
Ruby
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}"
|