Author

Topic: Python brainwallet generation - hash160 problem (Read 1719 times)

member
Activity: 67
Merit: 130
Oh my. You should use hash160.update(hashlib.sha256(PUBLIC_KEY).digest()), and you can't calculate public key without using Elliptic Curve DSA.

Code:
import hashlib

passphrase = ""
print hashlib.sha256(passphrase).hexdigest() #<-- e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

# tons of ecdsa related stuff, e.g.
# k = ECDSA_KEY()
# k.generate('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.decode('hex'))
# echo k.get_pubkey().encode('hex') # <- 04a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd5b8dec5235a0fa8722476c7709c02559e3aa73aa03918ba2d492eea75abea235

pub='04a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd5b8dec5235a0fa8722476c7709c02559e3aa73aa03918ba2d492eea75abea235'.decode('hex')
hash160 = hashlib.new('ripemd160')
hash160.update(hashlib.sha256(pub).digest())
print hash160.hexdigest() #<-- b5bd079c4d57cc7fc28ecf8213a6b791625b8183
legendary
Activity: 2618
Merit: 1007
Code (Python 2.7):
Code:
import hashlib

passphrase = ""

hash160 = hashlib.new('ripemd160')
hash160.update(hashlib.sha256(passphrase).digest())
print hash160.hexdigest() #<-- b472a266d0bd89c13706a4132ccfb16f7c3b9fcb

print hashlib.sha256(passphrase).hexdigest() #<-- e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

I want to perform steps 2+3 from https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses

The hexdigest of the sha256 hash is the correct one for an empty input.
According to https://bitcointools.appspot.com/?s=&r=1 hash160 however should be b5bd079c4d57cc7fc28ecf8213a6b791625b8183, not the one I came up with.

https://github.com/weex/addrgen/blob/master/addrgen.py from line 71 on does exactly the same thing I do here (just outputting the digest, not hexdigest) and does call the result from this "hash160" later in the code. Where/what is my error?!
Jump to: