123456 % 58 = 32 // first (least significant) digit 123456 / 58 = 2128 2128 % 58 = 40 // second digit 2128 / 58 = 36 36 % 58 = 36 // third digit 36 / 58 = 0 // we're done |
Multi-word divide |
|
|
! " CG? 3RFQ)FTR-'0 0 1 123456 9000000000000000001 |
static const char* const ASCII_CHARS = "!\"#$ % &'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
|
|
Const static unsigned char b58_char[ 58 ] = ‘1234’; // shortened here for brevity.
ASCII_CHARS
contains all "printable" ASCII characters. For Base-58, only the first 58 chars are used, so, yeah, you could shorten that array to a length of just 58 chars. You can also easily replace/swap the characters to be used as needed.sizeof()
operator, but it is not counted when you use the strlen()
function. Anyway, you don't need to care about this, because the suggested Base-58 encode/decode functions simply won't touch any characters in ASCII_CHARS
beyond array index 57
😊
|
|
|
|
|
|
Had to use array size of 59 rather than 58 because I was unable to get Qt Creator to create the string using the format ‘123’; The use of “123” forces a null character on the end. |
|
|
I don't understand "Start by taking the remainder to find the next digit." But from the example that follows, I think it confirms the concept I described, with the change for the ending divide as noted in your reply. |
|
|
static const char* const ASCII_CHARS = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
Encode: 0 (0x0000000000000000) --> 1 Encode: 1 (0x0000000000000001) --> 2 Encode: 123456 (0x000000000001E240) --> dhZ Encode: 9000000000000000001 (0x7CE66C50E2840001) --> MtgsBgvtF9J Encode: 18446744073709551615 (0xFFFFFFFFFFFFFFFF) --> jpXCZedGfVQ Decode: 1 --> 0 (0x0000000000000000) Decode: 2 --> 1 (0x0000000000000001) Decode: dhZ --> 123456 (0x000000000001E240) Decode: MtgsBgvtF9J --> 9000000000000000001 (0x7CE66C50E2840001) Decode: jpXCZedGfVQ --> 18446744073709551615 (0xFFFFFFFFFFFFFFFF) |
|
|
|
|