-
-
Save apeiros/afd452f8536c44b67a0e227a8ff0591c 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
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