Bitcoin Forum
April 26, 2024, 09:10:37 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to convert btc address to hash160 and other way around in PHP ?  (Read 748 times)
btctousd81 (OP)
Sr. Member
****
Offline Offline

Activity: 434
Merit: 270


View Profile WWW
November 09, 2017, 06:16:43 AM
 #1

i tried looking for ways to convert btc address to hash160 hex and other way around,
i have found few tools iwritten n c++, which works on command line., but i am trying to implement it in my own php code.

but i couldn't find any php code to convert btc address to hash160 address or the other way around.

this guys has the code

http://bitcoinvalued.com/tools.php

i tried contacting him, but he is no mood to share the code.,

even blockchain does it on the fly , https://blockchain.info/address/14CFVhgRnd94q9Bq6uMigptDfwtKnMPVZs

Address   14CFVhgRnd94q9Bq6uMigptDfwtKnMPVZs
Hash 160   23090d78bc991026455285f511c5563e6765f03d



any other guys have php code ?


Thanks for your time.


1714122637
Hero Member
*
Offline Offline

Posts: 1714122637

View Profile Personal Message (Offline)

Ignore
1714122637
Reply with quote  #2

1714122637
Report to moderator
1714122637
Hero Member
*
Offline Offline

Posts: 1714122637

View Profile Personal Message (Offline)

Ignore
1714122637
Reply with quote  #2

1714122637
Report to moderator
1714122637
Hero Member
*
Offline Offline

Posts: 1714122637

View Profile Personal Message (Offline)

Ignore
1714122637
Reply with quote  #2

1714122637
Report to moderator
The block chain is the main innovation of Bitcoin. It is the first distributed timestamping system.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714122637
Hero Member
*
Offline Offline

Posts: 1714122637

View Profile Personal Message (Offline)

Ignore
1714122637
Reply with quote  #2

1714122637
Report to moderator
1714122637
Hero Member
*
Offline Offline

Posts: 1714122637

View Profile Personal Message (Offline)

Ignore
1714122637
Reply with quote  #2

1714122637
Report to moderator
aleksej996
Sr. Member
****
Offline Offline

Activity: 490
Merit: 389


Do not trust the government


View Profile
November 09, 2017, 08:23:40 PM
 #2

As I understand you just need to Base58 decode it and strip off first byte (network byte) and last 4 (checksum bytes). That should give you your 160 bit number you are looking for. I found this PHP library for Base58 encoding/decoding for you https://github.com/stephen-hill/base58php
btctousd81 (OP)
Sr. Member
****
Offline Offline

Activity: 434
Merit: 270


View Profile WWW
November 09, 2017, 08:30:48 PM
 #3

As I understand you just need to Base58 decode it and strip off first byte (network byte) and last 4 (checksum bytes). That should give you your 160 bit number you are looking for. I found this PHP library for Base58 encoding/decoding for you https://github.com/stephen-hill/base58php

thanks looking in to it, and what about hash160 to btc address.,

where does the last 4 bytes we stripped off comes from ? while doinng hash 160 to btc address, i mean if we reverse the process.

aleksej996
Sr. Member
****
Offline Offline

Activity: 490
Merit: 389


Do not trust the government


View Profile
November 09, 2017, 08:37:03 PM
 #4

As I understand you just need to Base58 decode it and strip off first byte (network byte) and last 4 (checksum bytes). That should give you your 160 bit number you are looking for. I found this PHP library for Base58 encoding/decoding for you https://github.com/stephen-hill/base58php

thanks looking in to it, and what about hash160 to btc address.,

where does the last 4 bytes we stripped off comes from ? while doinng hash 160 to btc address, i mean if we reverse the process.

Theose are the first 4 bytes of a double sha256 hash of the hash160 with the added first network byte. So the first network byte (mainnet is zero) and 160 bit number is 168 bits. You hash that with sha256 and the result hash again with sha256, then just take the first 4 bytes.

You can find more information here https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses
btctousd81 (OP)
Sr. Member
****
Offline Offline

Activity: 434
Merit: 270


View Profile WWW
November 09, 2017, 09:38:22 PM
Last edit: November 09, 2017, 09:51:25 PM by btctousd81
 #5

As I understand you just need to Base58 decode it and strip off first byte (network byte) and last 4 (checksum bytes). That should give you your 160 bit number you are looking for. I found this PHP library for Base58 encoding/decoding for you https://github.com/stephen-hill/base58php

thanks looking in to it, and what about hash160 to btc address.,

where does the last 4 bytes we stripped off comes from ? while doinng hash 160 to btc address, i mean if we reverse the process.

Theose are the first 4 bytes of a double sha256 hash of the hash160 with the added first network byte. So the first network byte (mainnet is zero) and 160 bit number is 168 bits. You hash that with sha256 and the result hash again with sha256, then just take the first 4 bytes.

You can find more information here https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses

okie., so far i have managed to do

bitcoin address to hash160
for p2pkh
for p2sh

hash160 to btc address
for p2pkh only

how to make it work with p2sh ?

thanks

why p2sh 's hash160 gives p2pkh address upon conversion through hash160 to bitcoin address and not the p2sh addresss  ?

i mean

https://blockchain.info/address/39ZPyRrVR4jYoRG1f3MeMm9jES9SPZyMCB

has hash160 as 565015b43956dd69623061d66039ff854c0690ba

but if i go for

https://blockchain.info/address/565015b43956dd69623061d66039ff854c0690ba

i get Address   18sP3tN3sARAiFZaXwh3w8no5uriuM8Yyz

so if i again g o to

https://blockchain.info/address/18sP3tN3sARAiFZaXwh3w8no5uriuM8Yyz

i fuckin get Hash 160   565015b43956dd69623061d66039ff854c0690ba

so in short

https://blockchain.info/address/39ZPyRrVR4jYoRG1f3MeMm9jES9SPZyMCB

and

https://blockchain.info/address/18sP3tN3sARAiFZaXwh3w8no5uriuM8Yyz

both have same hash160 , how is that possible ?

something is not right., or its the way it is ?

my code is also giving same outputs as blockchain.info . so HuhHuhHuhHuh?

thanks

HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4316

<insert witty quote here>


View Profile
November 09, 2017, 11:13:07 PM
 #6

hash160 to btc address
for p2pkh only

how to make it work with p2sh ?
why p2sh 's hash160 gives p2pkh address upon conversion through hash160 to bitcoin address and not the p2sh addresss  ?
Because, as Danny already told you, you don't hash a public key to get to get a P2SH address... it is a "Pay to SCRIPT hash"... you need to hash a "redeem script", not a public key. Read my answer in your other thread: https://bitcointalk.org/index.php?topic=2380374.msg24318230#msg24318230

PS. don't create multiple threads for the same question, it'll fragment/split the answers and make things more confusing. Suggest you pick one thread and lock the other.

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
btctousd81 (OP)
Sr. Member
****
Offline Offline

Activity: 434
Merit: 270


View Profile WWW
November 10, 2017, 02:37:02 AM
 #7

hash160 to btc address
for p2pkh only

how to make it work with p2sh ?
why p2sh 's hash160 gives p2pkh address upon conversion through hash160 to bitcoin address and not the p2sh addresss  ?
Because, as Danny already told you, you don't hash a public key to get to get a P2SH address... it is a "Pay to SCRIPT hash"... you need to hash a "redeem script", not a public key. Read my answer in your other thread: https://bitcointalk.org/index.php?topic=2380374.msg24318230#msg24318230

PS. don't create multiple threads for the same question, it'll fragment/split the answers and make things more confusing. Suggest you pick one thread and lock the other.

okie., thanks , looking in to it.,

this is completely different thread than my other thread, here i am working on php code to get hash160 from btc address.

while on other thread i am asking for how to create p2sh address and tx.

thanks

Sneginka111
Member
**
Offline Offline

Activity: 308
Merit: 10


View Profile
November 11, 2017, 06:11:08 AM
 #8

As I understand you just need to Base58 decode it and strip off first byte (network byte) and last 4 (checksum bytes). That should give you your 160 bit number you are looking for. I found this PHP library for Base58 encoding/decoding for you https://github.com/stephen-hill/base58php
Yes, I found it there too
aleksej996
Sr. Member
****
Offline Offline

Activity: 490
Merit: 389


Do not trust the government


View Profile
November 11, 2017, 06:43:22 PM
 #9

As I understand you just need to Base58 decode it and strip off first byte (network byte) and last 4 (checksum bytes). That should give you your 160 bit number you are looking for. I found this PHP library for Base58 encoding/decoding for you https://github.com/stephen-hill/base58php

thanks looking in to it, and what about hash160 to btc address.,

where does the last 4 bytes we stripped off comes from ? while doinng hash 160 to btc address, i mean if we reverse the process.

Theose are the first 4 bytes of a double sha256 hash of the hash160 with the added first network byte. So the first network byte (mainnet is zero) and 160 bit number is 168 bits. You hash that with sha256 and the result hash again with sha256, then just take the first 4 bytes.

You can find more information here https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses

okie., so far i have managed to do

bitcoin address to hash160
for p2pkh
for p2sh

hash160 to btc address
for p2pkh only

how to make it work with p2sh ?

thanks

why p2sh 's hash160 gives p2pkh address upon conversion through hash160 to bitcoin address and not the p2sh addresss  ?

i mean

https://blockchain.info/address/39ZPyRrVR4jYoRG1f3MeMm9jES9SPZyMCB

has hash160 as 565015b43956dd69623061d66039ff854c0690ba

but if i go for

https://blockchain.info/address/565015b43956dd69623061d66039ff854c0690ba

i get Address   18sP3tN3sARAiFZaXwh3w8no5uriuM8Yyz

so if i again g o to

https://blockchain.info/address/18sP3tN3sARAiFZaXwh3w8no5uriuM8Yyz

i fuckin get Hash 160   565015b43956dd69623061d66039ff854c0690ba

so in short

https://blockchain.info/address/39ZPyRrVR4jYoRG1f3MeMm9jES9SPZyMCB

and

https://blockchain.info/address/18sP3tN3sARAiFZaXwh3w8no5uriuM8Yyz

both have same hash160 , how is that possible ?

something is not right., or its the way it is ?

my code is also giving same outputs as blockchain.info . so HuhHuhHuhHuh?

thanks

This is because they are encoded differently. It seems that the only difference is that the version byte is 5 in P2SH instead of 0.
https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki

hash160 to btc address
for p2pkh only

how to make it work with p2sh ?
why p2sh 's hash160 gives p2pkh address upon conversion through hash160 to bitcoin address and not the p2sh addresss  ?
Because, as Danny already told you, you don't hash a public key to get to get a P2SH address... it is a "Pay to SCRIPT hash"... you need to hash a "redeem script", not a public key. Read my answer in your other thread: https://bitcointalk.org/index.php?topic=2380374.msg24318230#msg24318230

PS. don't create multiple threads for the same question, it'll fragment/split the answers and make things more confusing. Suggest you pick one thread and lock the other.

OP is just asking of getting hash 160 of a bitcoin address and vice versa, whether or not he understands what an address even is or what that hash 160 is of is a whole other story.
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!