Bitcoin Forum
November 20, 2017, 11:57:45 PM *
News: Latest stable version of Bitcoin Core: 0.15.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: How to convert btc address to hash160 and other way around in PHP ?  (Read 383 times)
btctousd81
Full Member
***
Offline Offline

Activity: 238


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.


1511222265
Hero Member
*
Offline Offline

Posts: 1511222265

View Profile Personal Message (Offline)

Ignore
1511222265
Reply with quote  #2

1511222265
Report to moderator
Join ICO Now A blockchain platform for effective freelancing
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1511222265
Hero Member
*
Offline Offline

Posts: 1511222265

View Profile Personal Message (Offline)

Ignore
1511222265
Reply with quote  #2

1511222265
Report to moderator
aleksej996
Full Member
***
Offline Offline

Activity: 126


★777Coin.com★ Fun BTC Casino!


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
Full Member
***
Offline Offline

Activity: 238


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
Full Member
***
Offline Offline

Activity: 126


★777Coin.com★ Fun BTC Casino!


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
Full Member
***
Offline Offline

Activity: 238


View Profile WWW
November 09, 2017, 09:38:22 PM
 #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
Sr. Member
****
Offline Offline

Activity: 420

<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.

btctousd81
Full Member
***
Offline Offline

Activity: 238


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
Jr. Member
*
Offline Offline

Activity: 42


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
Full Member
***
Offline Offline

Activity: 126


★777Coin.com★ Fun BTC Casino!


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:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!