Skip to content

Instantly share code, notes, and snippets.

@scottymac
Forked from jou/base58.rb
Created June 18, 2009 18:52
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 scottymac/132118 to your computer and use it in GitHub Desktop.
Save scottymac/132118 to your computer and use it in GitHub Desktop.
# http://www.flickr.com/groups/api/discuss/72157616713786392/
# manufacturing flic.kr style photo URLs
module Base58
def self.encode(n)
alphabet = %w(
1 2 3 4 5 6 7 8 9
a b c d e f g h i
j k m n o p q r s
t u v w x y z A B
C D E F G H J K L
M N P Q R S T U V
W X Y Z
)
return alphabet[0] if n == 0
result = ''
base = alphabet.length
while n > 0
remainder = n % base
n = n / base
result = alphabet[remainder] + result
end
result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment