Bitcoin Forum
November 17, 2024, 09:51:38 PM *
News: Check out the artwork 1Dq created to commemorate this forum's 15th anniversary
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Base58?  (Read 882 times)
tkbx (OP)
Sr. Member
****
Offline Offline

Activity: 350
Merit: 251



View Profile
March 21, 2014, 07:24:31 AM
 #1

Where can I find a Python function to convert bytes to base58 for addresses and wallet import format private keys?



The wiki only has what appears to be some kind of pseudocode.
flatfly
Legendary
*
Offline Offline

Activity: 1092
Merit: 1016

760930


View Profile
March 21, 2014, 08:29:09 AM
 #2

I have some really tight code for this on my home PC. Will try to remember to post it this when I get a chance this weekend - that is, if nobody beats me to it. Smiley  There are literally dozens of implementations around.
If you can't wait, you can try digging through the Electrum and Armory repos.
deepceleron
Legendary
*
Offline Offline

Activity: 1512
Merit: 1036



View Profile WWW
March 21, 2014, 09:17:20 AM
 #3

http://we.lovebitco.in/paperwal.py

Has two functions o_b58():with bitcoin address checksum and b58encode():non checksum. You can use it as an import library. Since it makes a bitcoin address, everything library-wise that you need to make a paper wallet is obviously included.

https://bitcointalk.org/index.php?topic=361092.0
tkbx (OP)
Sr. Member
****
Offline Offline

Activity: 350
Merit: 251



View Profile
March 21, 2014, 09:24:45 AM
 #4

http://we.lovebitco.in/paperwal.py

Has two functions o_b58():with bitcoin address checksum and b58encode():non checksum. You can use it as an import library. Since it makes a bitcoin address, everything library-wise that you need to make a paper wallet is obviously included.

https://bitcointalk.org/index.php?topic=361092.0
Perfect, thanks

Just in case anyone finds this question by googling and wants the solution:

Code:
def b58encode(v):
""" gavin bitcointool - encode v, which is a string of bytes, to base58.
"""
_b58chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
_b58base = len(_b58chars)

#(c style int->base256)
long_value = 0L
for (i, c) in enumerate(v[::-1]):
long_value += (256**i) * ord(c)
result = ''
while long_value >= _b58base:
div, mod = divmod(long_value, _b58base)
result = _b58chars[mod] + result
long_value = div
result = _b58chars[long_value] + result
zeropad = 0
for c in v:
if c == '\x00':
zeropad += 1
else:
break
return '1'*zeropad + result
jadescorpio
Newbie
*
Offline Offline

Activity: 28
Merit: 0


View Profile
March 22, 2014, 12:11:58 PM
 #5

Why do you need to convert bytes to base58 for addresses and wallet import format private keys? How can it be useful?
KawalGrover
Newbie
*
Offline Offline

Activity: 38
Merit: 0


View Profile
March 23, 2014, 02:48:08 PM
 #6

Why do you need to convert bytes to base58 for addresses and wallet import format private keys? How can it be useful?


From the bitcoin wiki:

// Why base-58 instead of standard base-64 encoding?
// - Don't want 0OIl characters that look the same in some fonts and
//      could be used to create visually identical looking account numbers.
// - A string with non-alphanumeric characters is not as easily accepted as an account number.
// - E-mail usually won't line-break if there's no punctuation to break at.
// - Doubleclicking selects the whole number as one word if it's all alphanumeric.

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!