by danbruc · 2y ago · 0 comments
The five characters SHALL each be converted into a value 0 to 84, and accumulated by multiplication by 85, from most to least significant.
There is of course the example and the reference implementation and everyone knows how this kind of encoding works, so you can certainly figure out how you are supposed to implement it.
Example: 0 to 4294967295 = 4 bytes
4294967296 to 4311744511 = 3 bytes (subtract 4294967296 first)
4311744512 to 4311810047 = 2 bytes (subtract 4311744512 first)
4311810048 to 4311810303 = 1 byte (subtract 4311810048 first)
Then you're still left with 125242821 remaining numbers, over 26 bits.
Another is to encode 4k+i bytes as 5k+1+i base-85 characters, for 0<i<4. That way the encoding length immediately determines the input length. And there's again plenty of space since 85^{i+1} > 256^i for i < 4.
This leaves encoding lengths of 5k+1 unused. These could be used to support arbitrary bit lengths, i.e. for encoding an input of 4(k-1) bytes + i bits, with 0<i<32. Set the final byte to i, and let the preceding 5 base-85 characters encode the i bits with 0 padding.
Anyway, it all seems a bit https://xkcd.com/927/
I myself typically binary compress then base64 encode.
Because there is no padding rule given, it's impossible to use the standard to encode most binary strings.
For example, how would you encode/decode these?
0x0000000000000000
0x00000000000000
0x000000000000
0x0000000000
0x00000000
0x000000> Fortunately, the charging one has been solved now that we've all standardized on mini-USB. Or is it micro-USB? Shit.
is hilariously even more true.
The article explains how Base64 is “problematic because it has more than a dozen variants”. So instead of picking one, let’s invent a new standard.