Say you have the string \"Hi\". How do you get a value of 8, 9 (\"H\" is the 8th letter of the alphabet, and \"i\"
\"Hi\"
8
9
\"H\"
\"i\"
Preserving case and assuming you want to wrap around at "Z":
upper = [*?A..?Z] lower = [*?a..?z] LOOKUP = (upper.zip(upper.rotate) + lower.zip(lower.rotate)).to_h s.each_char.map { |c| LOOKUP[c] }.join #=> "Ij"