RosettaCodeData/Task/Substitution-cipher/Ruby/substitution-cipher.rb

10 lines
344 B
Ruby
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
Key = "VsciBjedgrzyHalvXZKtUPumGfIwJxqOCFRApnDhQWobLkESYMTN"
def encrypt(str) = str.tr(Alphabet, Key)
def decrypt(str) = str.tr(Key, Alphabet)
str = 'All is lost, he thought. Everything is ruined. Its ten past three.'
p encrypted = encrypt(str)
p decrypt(encrypted)