Base58Check encoding: Difference between revisions

Content added Content deleted
(Added 11l)
Line 900: Line 900:
=={{header|Python}}==
=={{header|Python}}==
===Procedural===
===Procedural===
===Works with Python 3.9
{{trans|C#}}
{{trans|C#}}
<lang python>ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
<lang python>ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
Line 908: Line 909:
r = num % 58
r = num % 58
sb = sb + ALPHABET[r]
sb = sb + ALPHABET[r]
num = num / 58;
num = num // 58;
return sb[::-1]
return sb[::-1]


s = 25420294593250030202636073700053352635053786165627414518
s = 25420294593250030202636073700053352635053786165627414518
b = convertToBase58(s)
b = convertToBase58(s)
print "%-56d -> %s" % (s, b)
print("%-56d -> %s" % (s, b))


hash_arr = [0x61, 0x626262, 0x636363, 0x73696d706c792061206c6f6e6720737472696e67, 0x516b6fcd0f, 0xbf4f89001e670274dd, 0x572e4794, 0xecac89cad93923c02321, 0x10c8511e]
hash_arr = [0x61, 0x626262, 0x636363, 0x73696d706c792061206c6f6e6720737472696e67, 0x516b6fcd0f, 0xbf4f89001e670274dd, 0x572e4794, 0xecac89cad93923c02321, 0x10c8511e]
for num in hash_arr:
for num in hash_arr:
b = convertToBase58(num)
b = convertToBase58(num)
print "0x%-54x -> %s" % (num, b)</lang>
print("0x%-54x -> %s" % (num, b))</lang>
{{out}}
{{out}}
<pre>25420294593250030202636073700053352635053786165627414518 -> 6UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM
<pre>25420294593250030202636073700053352635053786165627414518 -> 6UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM