Skip to content

Instantly share code, notes, and snippets.

@apeiros
Created April 30, 2016 14:12
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 apeiros/afd452f8536c44b67a0e227a8ff0591c to your computer and use it in GitHub Desktop.
Save apeiros/afd452f8536c44b67a0e227a8ff0591c to your computer and use it in GitHub Desktop.
Base32Chars = "0123456789abcdfghijklmnpqrsvwxyz"
def printHash32(hash_int)
maxSize = 32
len = 50
s = ""
n = len -1
hash = [("%0256b" % hash_int)].pack("B*").unpack("C*")
while n >= 0
b = n * 5;
i = b / 8;
j = b % 8;
c = (hash[i] >> j) | (i >= maxSize - 1 ? 0 : hash[i + 1] << (8 - j))
s << Base32Chars[c & 0x1f]
n -= 1
end
s
end
printHash32 72356286363236526331452798020295219825627762172601973501865183084394422723874
# => "p5gx18yrbnwc6xc0mxvsfaxzgy2y9i78xq7ds0qmdm67q39y4z"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment