Skip to content

Instantly share code, notes, and snippets.

@geemus
Created February 24, 2009 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geemus/69725 to your computer and use it in GitHub Desktop.
Save geemus/69725 to your computer and use it in GitHub Desktop.
module Base
module_function
BASE_CHARACTERS = '0123456789BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz'
def encode(int)
str = ''
while int > 0
character = int % BASE_CHARACTERS.length
int = int / BASE_CHARACTERS.length
str = BASE_CHARACTERS[character..character] + str
end
str
end
def decode(str)
int = 0
str.reverse.split('').each_with_index do |char, i|
int += BASE_CHARACTERS.index(char) * (BASE_CHARACTERS.length ** i)
end
int
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment