Bitcoin Forum
December 02, 2022, 08:33:56 AM *
News: Reminder: do not keep your money in online accounts
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Python brainwallet generation - hash160 problem  (Read 1680 times)
Sukrim (OP)
Legendary
*
Offline Offline

Activity: 2618
Merit: 1006


View Profile
March 10, 2013, 12:00:31 AM
 #1

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?!

https://www.coinlend.org <-- automated lending at various exchanges.
https://www.bitfinex.com <-- Trade BTC for other currencies and vice versa.
1669970036
Hero Member
*
Offline Offline

Posts: 1669970036

View Profile Personal Message (Offline)

Ignore
1669970036
Reply with quote  #2

1669970036
Report to moderator
1669970036
Hero Member
*
Offline Offline

Posts: 1669970036

View Profile Personal Message (Offline)

Ignore
1669970036
Reply with quote  #2

1669970036
Report to moderator
1669970036
Hero Member
*
Offline Offline

Posts: 1669970036

View Profile Personal Message (Offline)

Ignore
1669970036
Reply with quote  #2

1669970036
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1669970036
Hero Member
*
Offline Offline

Posts: 1669970036

View Profile Personal Message (Offline)

Ignore
1669970036
Reply with quote  #2

1669970036
Report to moderator
1669970036
Hero Member
*
Offline Offline

Posts: 1669970036

View Profile Personal Message (Offline)

Ignore
1669970036
Reply with quote  #2

1669970036
Report to moderator
Joric
Member
**
Offline Offline

Activity: 67
Merit: 130


View Profile
March 29, 2013, 05:49:51 PM
Merited by xandry (3)
 #2

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

1JoricCBkW8C5m7QUZMwoRz9rBCM6ZSy96
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!