Convert private key to integer

0

I have a random private key (compressed or uncompressed) 5HpHagT65TZzG1QDbnQCzdudnpknN7nA1SLEt4ZcxsH2SV92yqt or KwDiBf89QgGbjEmUcXPRwPuKPFnFECvJkvovGNiyjaujMCrQXy98. How do I convert this private key back to an integer?

The Gripmaster

Posted 2019-08-25T03:56:24.960

Reputation: 115

Answers

3

Assuming the key is the posted compressed WIF KwDiBf89QgGbjEmUcXPRwPuKPFnFECvJkvovGNiyjaujMCrQXy98:

  1. Decode the key you have using the encoder used (in this case base-58)
    80-00000000000000000006f5d7d806edef2e1110b0b243f9a90c2aaaaaaaaaaaaa-01-098dbf37
  2. Remove the extra bytes (version byte, compressed byte if present, checksum)
    00000000000000000006f5d7d806edef2e1110b0b243f9a90c2aaaaaaaaaaaaa
  3. Take the remaining bytes (in this case it must be 32 bytes) and convert it to an integer assuming it is positive and in big-endian (most significant value is stored first).
    666666666666666666666666666666666666666666666666666666

Coding Enthusiast

Posted 2019-08-25T03:56:24.960

Reputation: 488

1@The Gripmaster you should also add that entering "private key" in a website is not a good idea.Coding Enthusiast 2019-09-04T03:36:58.410