Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Challenge week 1
- # 3/23/15
- # Meshiest / _cake
- # Test data:
- # psghactuxjnmrbyzefklwvoidq
- # uammy oyfmh!
- puts "Enter cipher: "
- cipher = gets.chomp
- unless /((?!=\G)([a-z])){26}/i =~ cipher
- puts "Invalid cipher, requires 26 unique letters"
- exit
- end
- map = Hash[*((cipher.chars.zip ('a'..'z').to_a).flatten)] # Map alphabet to each cipher character
- puts "Enter ciphertext: "
- text = gets.chomp
- text = text.downcase
- .chars
- .map{ |c|
- map[c] || c # get the alternate character, otherwise, the same character
- } * ''
- puts "Deciphered text: "
- puts text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement