Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: GlassWerx on January 09, 2016, 11:11:10 PM



Title: How to convert Hex keys to WIF as a math problem?
Post by: GlassWerx on January 09, 2016, 11:11:10 PM
I have noticed that behind the scenes of bitcoin code there is a lot of math. Which made me wonder, Is there a way to convert a hex private key to WIF using a mathematical algorithm? If so, could someone please post the formula as i cannot find it anywhere if it exists. I am by far no math wiz or anything i just find math interesting sometimes, and this is one of them.


Title: Re: How to convert Hex keys to WIF as a math problem?
Post by: shorena on January 09, 2016, 11:21:43 PM
I have noticed that behind the scenes of bitcoin code there is a lot of math. Which made me wonder, Is there a way to convert a hex private key to WIF using a mathematical algorithm? If so, could someone please post the formula as i cannot find it anywhere if it exists. I am by far no math wiz or anything i just find math interesting sometimes, and this is one of them.

In math terms its pretty borring -> https://en.bitcoin.it/wiki/Wallet_import_format


Title: Re: How to convert Hex keys to WIF as a math problem?
Post by: DannyHamilton on January 10, 2016, 12:19:37 AM
- snip -
hex private key to WIF using a mathematical
- snip -

There are two mathematical algorithms you'll need.

First you'll need to calculate SHA256. This is generally binary "math" consisting of the logic functions (and, or, xor, not) and shifting or rotating positions.  You can find a description of the algorithm here:
https://en.wikipedia.org/wiki/SHA-2#Pseudocode

Then you'll need to convert from base 16 (hex) to base 58.



Title: Re: How to convert Hex keys to WIF as a math problem?
Post by: fbueller on January 10, 2016, 02:42:35 AM
I have an implementation that illustrates the maths - it's mostly a generic base conversion trick. https://github.com/Bit-Wasp/bitcoin-php/blob/master/src/Base58.php look at the encode() and decode() functions.


Title: Re: How to convert Hex keys to WIF as a math problem?
Post by: GlassWerx on January 10, 2016, 03:31:15 PM
Thanks for all the links guys. Some very good reading. Bitcoin really is beautiful when you look behind the scenes.