Created
April 25, 2009 21:15
-
-
Save jou/101753 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
# Version 2, December 2004 | |
# | |
# Copyright (C) 2004 Sam Hocevar | |
# 14 rue de Plaisance, 75014 Paris, France | |
# Everyone is permitted to copy and distribute verbatim or modified | |
# copies of this license document, and changing it is allowed as long | |
# as the name is changed. | |
# | |
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
# | |
# 0. You just DO WHAT THE FUCK YOU WANT TO. | |
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
### @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