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

Could you provide sample output? #4

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

Could you provide sample output? #4

coolaj86 opened this issue Dec 22, 2021 · 1 comment

Comments

@coolaj86
Copy link

Which base62 implementations is this compatible with?

Reference Strings

For reference, I believe this is what base62 encoding and decoding should look like:

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

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

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

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

Reference Implementation

I generated that using https://github.com/keybase/saltpack/encoding/basex, which seems to be correct and agree with other implementations, such as https://github.com/oconnor663/basex_gmp.

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, 255, 255, 255, 255},
		{255, 255, 255, 255, 0, 0, 0, 0},
	} {
		// Uses the GMP character set "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
		b62 := basex.Base62StdEncoding.EncodeToString(src)
		b64 := base64.RawURLEncoding.EncodeToString(src)

		fmt.Printf("Base64: %s (%d chars)\n", b64, len(b64))
		fmt.Printf("Base62: %s (%d chars)\n", b62, len(b62))
		fmt.Println("")
	}
}
@baztian
Copy link

baztian commented Jul 13, 2022

Hi @coolaj86, this lib seems to produce the same results:

import io.seruco.encoding.base62.Base62;
import java.nio.charset.StandardCharsets;

class Scratch {

  public static void main(String[] args) {
    outputEncoded("Hello, 世界".getBytes(StandardCharsets.UTF_8));
    outputEncoded("Hello World".getBytes(StandardCharsets.UTF_8));
    outputEncoded(toByteArray(0, 0, 0, 0, 255, 255, 255, 255 ));
    outputEncoded(toByteArray(255, 255, 255, 255, 0, 0, 0, 0 ));
  }

  private static void outputEncoded(byte[] unencoded) {
    byte[] bytes = Base62.createInstance().encode(unencoded);
    System.out.println(new String(bytes, StandardCharsets.US_ASCII));
  }
  private static byte[] toByteArray(int... values) {
    byte[] result = new byte[values.length];
    for (int i = 0; i < values.length; i++) {
      result[i] = (byte) values[i];
    }
    return result;
  }
}

Running it produces

1wJfrzvdbuFbL65vcS
73XpUgyMwkGr29M
00004gfFC3
LygHZwPV2MC

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

2 participants