Skip to content

Instantly share code, notes, and snippets.

@benui-dev
Created September 20, 2010 00:22
Show Gist options
  • Save benui-dev/587258 to your computer and use it in GitHub Desktop.
Save benui-dev/587258 to your computer and use it in GitHub Desktop.
require 'pp'
input = <<eos
Hello there
eos
# Randomise order of a-z
rand_characters = ('a'..'z').sort_by { rand }
encoding = Hash.new
rand_characters.each_with_index do |letter, index|
encoding[letter] = index + 1 # Let's make it 1..26
end
output = Array.new
# Arrays of arrays
input.downcase.split(/\s/).each do |word|
# Swap from letters to numbers
word_arr = word.split('').collect do |letter|
encoding[letter]
end
output.push( word_arr )
end
pp output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment