Skip to content

Commit 423e955

Browse files
committedSep 17, 2012
Add base58 tests
Test vectors floating around on the Internet are often for the Flickr base 58 encoding; this encoding differs from the Bitcoin one, so they can not be used.
1 parent b34efff commit 423e955

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
 

‎base58.py

+21
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,27 @@
22
_base58_codestring_len = len (_base58_codestring)
33

44
def encode (x):
5+
'''
6+
Encode bytes into base58-encoded bytes.
7+
8+
>>> import binascii
9+
>>> encode (b'\x30\x39')
10+
b'4fr'
11+
>>> encode (int (12345).to_bytes (2, 'big'))
12+
b'4fr'
13+
>>> encode (int (3471391110).to_bytes (4, 'big'))
14+
b'6Hknds'
15+
>>> encode (binascii.unhexlify (b'00'))
16+
b'1'
17+
>>> encode (binascii.unhexlify (b'0000'))
18+
b'11'
19+
>>> encode (binascii.unhexlify (b'01'))
20+
b'2'
21+
>>> encode (binascii.unhexlify (b'0198b9a10f'))
22+
b'BSxJKp'
23+
>>> encode (int (3429289555).to_bytes (4, 'big'))
24+
b'6E31Jz'
25+
'''
526
q = int.from_bytes (x, 'big')
627
result = bytearray ()
728
while q > 0:

0 commit comments

Comments
 (0)
Please sign in to comment.