7
I'm trying create raw private keys using the steps:
- Take a version of PK (0x80) and concatenate (as prefix)with my pseudo-random 32bytes-array.
- Take a calculated checksum (4bytes) and push it to the end of the array.
Encode the result to Base58Check using the algorithm:
code_string = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; x = converted_arrayofbytes_to_big_integer; output_string = ""; while(x > 0) { (x, remainder) = divide(x, 58); //x becomes the integer part of dividing here output_string.append(code_string[remainder]) } return output_string.Reverse();
Ok, I have done it, but I can't understand when x devided into 58 (through the loop) why the last remainder is 4 always (decimal: when the remainder is 4, it use as index of code_string: the last value of output_string is 5 (Base58) therefore)? I assume this's beacause of version's prefix but who can explain it from the standpoint of mathematics?
1Thank for the answer. Now I understand it. If, for example, take the range of decimal numbers 300-399 and represent any number as a exponents of 10: (smallest) 300 = 310^2 + 010^1 + 010^0 or (biggest) 399 = 310^2 + 910^1 + 910^0. In the range, obvious, any number has 3 as the last remainder, i.e. (other words) it consists of three hundreds. Similarly it is right for Base58 encoding (it has more symbols, than decimal, as you mentioned). – Mergasov – 2016-05-27T20:54:57.160
Yes, exactly, it's just a range :) – morsecoder – 2016-05-27T21:33:41.410