def decode(char, index) list = ("A".."Z").to_a list[(list.index(char) - index) % 26] end # # pp decode("K", 3) # # pp decode("A", 3) # pp decode("A", 24) S = gets.chomp puts S.chars.map.with_index(1) { |c, i| decode(c, i) }.join