Author

Topic: convert list of bitcoin address to hash 160 ??? Python (Read 413 times)

legendary
Activity: 3472
Merit: 10611
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.
legendary
Activity: 1624
Merit: 2481
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.
member
Activity: 126
Merit: 38

I want to create a database. for a project. need to convert address list...
legendary
Activity: 1624
Merit: 2481
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:

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).
member
Activity: 126
Merit: 38
input.txt

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


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



How to convert in python??
Jump to: