-
-
Save icostan/8cbdd0ebdfc674051a11a94b9419b31f 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
def base58(binary_hash) | |
alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' | |
value = binary_hash.unpack('H*')[0].to_i 16 | |
output = '' | |
while value > 0 | |
remainder = value % 58 | |
value /= 58 | |
output += alphabet[remainder] | |
end | |
output += alphabet[0] * binary_hash.bytes.find_index{|b| b != 0} | |
output.reverse | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment