Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: Jupiter_01 on October 19, 2018, 06:42:47 AM



Title: convert list of bitcoin address to hash 160 ??? Python
Post by: Jupiter_01 on October 19, 2018, 06:42:47 AM
input.txt

adres
1KxUVU9DKfdaTLMnXBLS5BZRf56cFnRosk
1KxUVU9DKfdaTLMnXBLS5BZRf56cFnRosk
1KxUVU9DKfdaTLMnXBLS5BZRf56cFnRosk
1KxUVU9DKfdaTLMnXBLS5BZRf56cFnRosk
1KxUVU9DKfdaTLMnXBLS5BZRf56cFnRosk
1KxUVU9DKfdaTLMnXBLS5BZRf56cFnRosk
....
....
....


output.txt
hash 160
cff01716e3b722613b3d017b9ed5da84d24e4fcf
cff01716e3b722613b3d017b9ed5da84d24e4fcf
cff01716e3b722613b3d017b9ed5da84d24e4fcf
cff01716e3b722613b3d017b9ed5da84d24e4fcf
cff01716e3b722613b3d017b9ed5da84d24e4fcf
cff01716e3b722613b3d017b9ed5da84d24e4fcf
....
....
....



How to convert in python??


Title: Re: convert list of bitcoin address to hash 160 ??? Python
Post by: bob123 on October 19, 2018, 06:50:59 AM
Why do you want to hash the address ? The address is a hash itself.

But alright.. whatever..  First, you need to define what hash function you want to use. I can only see "hash 160".
There is no "hash 160".

I guess you are referring to the RIPEMD-160.. ?


You can use hashlib (https://docs.python.org/3/library/hashlib.html):

Code:
>>> h = hashlib.new('ripemd160')
>>> h.update(b"YourString or address or whatever")
>>> h.hexdigest()

Output will be the RIPEMD-160 hash of the input.


But the chances are high you are trying to accomplish something which doesn't help you at all.
Instead of asking how to do that particular step, start from the beginning and explain what you are trying to accomplish (and please explain detailed why you need to hash the hash of a public key, it doesn't make sense for me).


Title: Re: convert list of bitcoin address to hash 160 ??? Python
Post by: Jupiter_01 on October 19, 2018, 07:03:19 AM

I want to create a database. for a project. need to convert address list...


Title: Re: convert list of bitcoin address to hash 160 ??? Python
Post by: bob123 on October 19, 2018, 07:08:03 AM
I want to create a database. for a project. need to convert address list...

You aren't converting addresses this way. You are simply hashing them.
And since addresses already are RIPEMD-160 hashes, they won't get shorter (or whatever you are expecting to happen).


My previous post explained how to do this based on an example. Implementing it for a list of addresses shouldn't be a problem at all anymore.


Title: Re: convert list of bitcoin address to hash 160 ??? Python
Post by: pooya87 on October 19, 2018, 06:25:49 PM
But alright.. whatever..  First, you need to define what hash function you want to use. I can only see "hash 160".
There is no "hash 160".

hash160 is referred to the result of RIPEMD160 of SHA256 which is the first step used to convert public key to an address:
Code:
base58check({version byte}RIPEMD160(SHA256(pubkey)))

Base58check encoding is encoding so it is reversible function. so to get HASH160 simply decode the address (base58 string) then remove the first byte since it is the address version byte then remove the last 4 bytes if the function hasn't already done it since it is the checksum. the remaining 20 bytes will be HASH160.