Skip to content

Instantly share code, notes, and snippets.

@icostan
Created October 11, 2018 18:04
Show Gist options
  • Save icostan/8cbdd0ebdfc674051a11a94b9419b31f to your computer and use it in GitHub Desktop.
Save icostan/8cbdd0ebdfc674051a11a94b9419b31f to your computer and use it in GitHub Desktop.
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