According to https://en.bitcoin.it/wiki/Wallet_import_format, the bitcoin private wif format key is create by below step. And it says that the compressed wif key always start with 'K' or 'L', this mean 80+private-key+01/ mod 58' last result is always 18 or 19. I know the big number mod 58 will result in 0-57, why the last remainder of wif key mod 58 always is 18 or 19 Would someone give me Mathematical Proof of this?

 #1 take a private key

 #2 add version
 version='80' #mainnet

 #3 perform double hash-256 of priv in step#2

 #4 get first 4 bytes for checksum

 #5 add checksum to priv in step#2

 #6 final bash58encode
 wif= b58encode(wifhash.decode('hex'))

 # compressed --> K or L
 print wif

 #compressed: L4TB9Z3dXeKW4tyF7EVqbczrEA5hjSdjG1QvBd1CeYTQHm2YincA


Base58 check encoding is really just a base conversion. It follows the standard base conversion algorithm in mathematics.

Right before we perform the base conversion, we will have a sequence of 38 bytes. It's 0x80 + 32 byte private key + 1 byte compression indicator + 4 bytes checksum. For the encoding itself, these 38 bytes are interpreted as a very large number, and then a base 58 version of that number is computed.

Let's look at our number in hexadecimal (base 16). The constraints we have mean that the number will be at least 0x0x8000000000000000000000000000000000000000000000000000000000000000000000000000 and at most 0x80ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff. Now in base 58, these two numbers are KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73NTmk4WB and L5oLkpV3aqBjhki6LmvChTCq73v9gyymzzMpBbhDLjDpKhfJuTe6.

Since every possible value that can be encoded falls between those two base 58 numbers, all possible values that can be encoded must begin with a K or L.

| improve this answer | |

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.