base62

package
v1.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: BSD-3-Clause Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Package base62

Abstract

base62 encodes and decodes uint64 values using a caller-supplied alphabet of 62 unique bytes. The alphabet defines the digit order and is kept by the Base62 value for subsequent operations.

API and behavior

New(alphabet) panics unless the alphabet is exactly 62 bytes long and every byte is unique. Callers MUST validate externally supplied alphabets before constructing a codec. Encode(0) returns the empty string. Decode returns zero for empty input, invalid characters, or arithmetic overflow; its return value does not distinguish those cases from a valid encoding of zero.

package main

import (
	"fmt"

	"go.osspkg.com/algorithms/encoding/base62"
)

func main() {
	codec := base62.New("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
	text := codec.Encode(123456)
	value := codec.Decode(text)
	fmt.Println(text, value)
}

Base62 is a representation, not encryption or authentication. Callers SHOULD not use an encoded value to hide or protect sensitive data.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base62

type Base62 struct {
	// contains filtered or unexported fields
}

func New

func New(alphabet string) *Base62

func (*Base62) Decode

func (v *Base62) Decode(data string) uint64

func (*Base62) Encode

func (v *Base62) Encode(id uint64) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL