La idea es desemcriptar message, ya esta la logica pero no puedo poner la i después del index dentro del for
message = "rvtufkmbrdpr fmasmegppreemvemeuaiv tmgb"
messageArray = message.chars
decrypted = ""
alphabet = ["","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
for i in(messageArray)
letter = ""
letter = alphabet[((alphabet.index(i)) 14)%27]
decrypted = decrypted letter
end
puts decrypted
CodePudding user response:
Your alphabet needs to include a space " "
instead of the empty string ""
message = "rvtufkmbrdpr fmasmegppreemvemeuaiv tmgb"
alphabet = " abcdefghijklmnopqrstuvwxyz".chars
message.chars.each_with_object("") do |char,decrypted|
decrypted << alphabet[ (alphabet.index(char) 14)%alphabet.size ]
end
#=> "eighty percent of success is showing up"