1

I'm trying to learn every bit of the process of converting a private key to WIF (Wallet Import Format).
I've been following the steps on this page and have made it all the way to the last step (Step 7 - "Convert the result from a byte string into a base58 string using Base58Check encoding") and that's where I'm stuck.
I need to use this process:

   code_string = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
   x = convert_bytes_to_big_integer(hash_result)

   output_string = ""

   while(x > 0) 
       {
           (x, remainder) = divide(x, 58)
           output_string.append(code_string[remainder])
       }

   repeat(number_of_leading_zero_bytes_in_hash)
       {
       output_string.append(code_string[0]);
       }

   output_string.reverse();

That process is from the Bitcoin wiki.
I'm pretty sure I've managed to decipher all of it except for this part:

x = convert_bytes_to_big_integer(hash_result)

It looks like its telling me to convert the bytes of a hash result into a "big integer", but I'm not sure what hash result it's referring to (I think maybe this one?: 800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D507A5B8D) and I don't know how to convert its bytes to a "big integer" (keep in mind that I'm trying to learn and therefore need to do all of the math myself instead of simply having an existing programming command or web tool do it for me).

And to a lesser extent this part:

repeat(number_of_leading_zero_bytes_in_hash)

I'm not sure what "hash" it's referring to.

I've spent many hours trying to figure all this out and have done a lot of searching and tried many possible interpretations so please don't think I'm just looking for someone to do the work for me.
Thank you.

1

I think maybe this one?: 800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D507A5B8D

Yep!

and I don't know how to convert its bytes to a "big integer" (keep in mind that I'm trying to learn and therefore need to do all of the math myself instead of simply having an existing programming command or web tool do it for me).

First, you need to convert it to an integer. Let me give you a simple example that you can use to test your program:

hex = fb4d9a
dec = 16469402

How do you get an integer from hex? It's like reading a base ten number, only it's base 16.

hex = fb4d9a
           ^ one's column
          ^ 16's column
         ^ 256's column (16*16)
        ^ etc.

Once you figure this out, upgrade your program to handle 'big integers.' Some programming languages have a limit on how big of numbers they can handle. In C, you can't put five billion into an int type variable. Some languages, like Python, can handle big integers without any help.

The number you get for the hash you referenced should be 63680997318088143281752740767766707563546963464218564507450892460763521488675430192536461.

I'm not sure what "hash" it's referring to.

It's the same one you just referenced. In this case, there are zero leading zeroes, which means that the output address should not start with a one.

  • What a great answer. Thanks so much! Got it all figured out now, and even have my own handy dandy Bitcoin wallet generator! – Eric Glass Sep 29 '17 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.