base62 icon indicating copy to clipboard operation
base62 copied to clipboard

Is it base62 or (non-standard) base64 encoding?

Open gavv opened this issue 8 years ago • 5 comments

In base62.go:

const encodeStd = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-0123456789."

there are 64 symbols.

UPD: I also noted there is a fork.

gavv avatar Apr 26 '16 12:04 gavv

Yeah, this confused me, so I forked it to be sure. No idea why those are in there. I'll submit it as a PR.

tuxxy avatar Jun 20 '16 20:06 tuxxy

For anyone else stumbling across this: You won't find a working base62 impl in here.

Try https://github.com/eknkc/basex instead, which has perfect support for base62 and other encodings.

riptl avatar Jun 27 '20 16:06 riptl

Here is another high performance implementation https://github.com/jxskiss/base62

jxskiss avatar Mar 17 '21 05:03 jxskiss

@jxskiss Your library is encoding things backwards - meaning that it reverses the byte order of the input when producing the output.

So [0, 0, 0, 0, 255, 255, 255, 255] becomes:

// Using the base64-like alphabet ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789

ffffffDAAAAA
// Using the GMP-like alphabet 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

VVVVVV300000

And I'm not clear that simply reversing the string would be the correct implementation.

coolaj86 avatar Dec 22 '21 06:12 coolaj86

@coolaj86 Simply reversing the string wouldn't be a correct implementation -_- The reversing order you see is just an implementation detail, the correctness is tested by large amount of random bytes data.

You may get more details here https://github.com/jxskiss/base62/issues/2#issuecomment-999554395

jxskiss avatar Dec 22 '21 12:12 jxskiss