Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base62 Implementations that do and don't agree #1

Open
coolaj86 opened this issue Dec 22, 2021 · 1 comment
Open

Base62 Implementations that do and don't agree #1

coolaj86 opened this issue Dec 22, 2021 · 1 comment

Comments

@coolaj86
Copy link
Author

Reference Base62 Strings

Raw   : Hello, 世界 (13 bytes)
Base64: SGVsbG8sIOS4lueVjA (18 chars)
Base62: 1wJfrzvdbuFbL65vcS (18 chars)

Raw   : Hello World (11 bytes)
Base64: SGVsbG8gV29ybGQ (15 chars)
Base62: 73XpUgyMwkGr29M (15 chars)

Raw   : [0] (1 bytes)
Base64: AA (2 chars)
Base62: 00 (2 chars)

Raw   : [0 0 0 0 0 0 0 0 0 0 0 0] (12 bytes)
Base64: AAAAAAAAAAAAAAAA (16 chars)
Base62: 00000000000000000 (17 chars)

Raw   : [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] (24 bytes)
Base64: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA (32 chars)
Base62: 000000000000000000000000000000000 (33 chars)

Raw   : [0 0 0 0 255 255 255 255] (8 bytes)
Base64: AAAAAP____8 (11 chars)
Base62: 000004gfFC3 (11 chars)

Raw   : [255 255 255 255 0 0 0 0] (8 bytes)
Base64: _____wAAAAA (11 chars)
Base62: LygHZwPV2MC (11 chars)

Test Code Reference

package main

import (
	"encoding/base64"
	"fmt"

	"github.com/keybase/saltpack/encoding/basex"
)

func main() {
	for _, src := range [][]byte{
		[]byte("Hello, 世界"),
		[]byte("Hello World"),
		{0},
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
		{0, 0, 0, 0, 255, 255, 255, 255},
		{255, 255, 255, 255, 0, 0, 0, 0},
	} {
		b62 := basex.Base62StdEncoding.EncodeToString(src)
		b64 := base64.RawURLEncoding.EncodeToString(src)

		if src[0] == 0x0 || src[1] == 255 {
			fmt.Printf("Raw   : %v (%d bytes)\n", src, len(src))
		} else {
			fmt.Printf("Raw   : %v (%d bytes)\n", string(src), len(src))
		}
		fmt.Printf("Base64: %s (%d chars)\n", b64, len(b64))
		fmt.Printf("Base62: %s (%d chars)\n", b62, len(b62))
		fmt.Println("")
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant