Skip to content

Instantly share code, notes, and snippets.

@ile
Last active December 19, 2015 11:09
Show Gist options
  • Save ile/5946044 to your computer and use it in GitHub Desktop.
Save ile/5946044 to your computer and use it in GitHub Desktop.
DICTIONARY = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split("")
encode = (i) ->
return DICTIONARY[0] if i is 0
result = ""
base = DICTIONARY.length
while i > 0
result += DICTIONARY[(i % base)]
i = Math.floor(i / base)
result.split("").reverse().join ""
decode = (input) ->
i = 0
base = DICTIONARY.length
input.split("").forEach (c) ->
i = i * base + DICTIONARY.indexOf(c)
i
@ile
Copy link
Author

ile commented Jul 8, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment