Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: oOoOo on August 19, 2011, 04:04:22 PM



Title: hash160 -> base58. Quick Question @devs!
Post by: oOoOo on August 19, 2011, 04:04:22 PM
Just a quick question:

How do I go from here:
65f2a3921afacd998e6c98a5aaa94325ed07ee14

to here:
1AJ3vE2NNYW2Jzv3fLwyjKF1LYbZ65Ez64
?

Things I have at my disposal to accomplish this task:

-pen,
-paper,
-calculator.

What do I need to do?
.


Title: Re: hash160 -> base58. Quick Question @devs!
Post by: jackjack on August 19, 2011, 04:39:21 PM
Add "00" before, and add the first 4 bytes of sha256(sha256("00" + hash160)) after your hash160     (the + is the concatenate operation, not sum)
So you have [ "0065f2a3921afacd998e6c98a5aaa94325ed07ee14" + first4bytesof(sha256(sha256("0065f2a3921afacd998e6c98a5aaa94325ed07ee14"))) ]
The address is just the base58 representation of the hexadecimal number above

Base58 characters: '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'



-pen,
-paper,
-calculator.
Quote
sha256(sha256("0465f2a3921afacd998e6c98a5aaa94325ed07ee14"))
Lol



If you really want to do it with a calculator only, there's a sha256 pseudocode here: http://en.wikipedia.org/wiki/SHA-2


Title: Re: hash160 -> base58. Quick Question @devs!
Post by: oOoOo on August 19, 2011, 04:47:18 PM
The address is just the base58 representation of the hexadecimal number above


Oh I think you misunderstood. Or I didn't express myself correctly.
The red part is what I'm interested in. That's why I mentioned pen+paper. I need the b58 routine.
But thanks anyways!
.


Title: Re: hash160 -> base58. Quick Question @devs!
Post by: jackjack on August 19, 2011, 04:57:21 PM
I depends of what you want to do

If you only have the hash160 of your pubkey, I answered correctly
If you just want to convert an hex number to a base58 number, here's the process:

hex = "1d3f3a"
dec = 1*16^5 + 13*16^4 + 3*16^3 + 15*16^2 + 3*16^1 + 10*16^0
      = 1916730

The rest is just some divisions (start with the power "number of digit in the hex representation"):
dec / 58^6 = 0. ...
dec / 58^5 = 0. ...
dec / 58^4 = 0. ...
dec / 58^3 = 9.8237......
so the first character is 9, and you substract 9*58^3 to dec -> dec = 160722
dec / 58^2 = 47.777.....
so the next character is 47, and you substract 47*58^2 to dec -> dec = 2664
dec / 58^1 = 45.931.....
so the next character is 45, and you substract 45*58^1 to dec -> dec = 54
the final character is 54

Your base58 number is [9-47-45-54], ie 9mov



Your calculator may not really appreciate the value of a 64-digit hexadecimal number though


Title: Re: hash160 -> base58. Quick Question @devs!
Post by: oOoOo on August 19, 2011, 05:02:03 PM
That's it perfect, thanks!


Title: Re: hash160 -> base58. Quick Question @devs!
Post by: etotheipi on August 19, 2011, 05:45:11 PM
For reference, see this diagram I created:

http://dl.dropbox.com/u/1139081/BitcoinImg/PubKeyToAddr.png

I have a few other diagrams posted here (https://bitcointalk.org/index.php?topic=29416.0) that you might find useful if you start looking at other calculations.