crock32

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: Apache-2.0 Imports: 3 Imported by: 15

README

Implementation of Douglas Crockford's Base32 encoding.

Example usage:

i, _ := crock32.Decode("a1j3")
s := crock32.Encode(i)
fmt.Println(s)

Crock32 is useful for "expressing numbers in a form that can be conveniently and accurately transmitted between humans and computer systems".

See http://www.crockford.com/wrmg/base32.html for details.

Note: crock32 differs from Crockford in its use of lower-case letters when encoding (decode works for both cases). To change, use: crock32.SetDigits("0123456789ABCDEFGHJKMNPQRSTVWXYZ")

Install with go get github.com/richardlehane/crock32

Documentation

Overview

Package crock32 implements Douglas Crockford's Base32 encoding.

Crock32 is useful for "expressing numbers in a form that can be conveniently and accurately transmitted between humans and computer systems." See http://www.crockford.com/wrmg/base32.html for details. Note: crock32 differs from Crockford in its use of lower-case letters when encoding (decode works for both cases). To change, use: crock32.SetDigits("0123456789ABCDEFGHJKMNPQRSTVWXYZ")

Example:

i, _ := crock32.Decode("a1j3")
s := crock32.Encode(i)
fmt.Println(s)

Copyright 2018 Richard Lehane. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2018 Richard Lehane. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(s string) (uint64, error)

Decode converts a string matching Douglas Crockford's character set (case insensitive) into an unsigned 64-bit integer.

func DecodeWithCheck

func DecodeWithCheck(s string) (uint64, error)

Decode converts a string matching Douglas Crockford's character set (case insensitive) into an unsigned 64-bit integer. Expects a check symbol as the last character and returns an error if check fails.

func Encode

func Encode(n uint64) string

Encode converts a uint64 into a Crockford base32 encoded string

func EncodeWithCheck

func EncodeWithCheck(n uint64) string

Encode converts a uint64 into a Crockford base32 encoded string with a trailing check symbol

func PUID

func PUID() string

PUID is a pseudo unique ID, crock32 encoded

func SetDigits

func SetDigits(s string) error

SetDigits allows you to change the encoding alphabet (not the decoding alphabet).

func SetUpper

func SetUpper()

SetUpper changes the encoding alphabet to upper case (Crockford's preference)

Types

type Sortable

type Sortable []string

Sortable makes a slice of crock32 strings sortable numerically

func (Sortable) Len

func (s Sortable) Len() int

func (Sortable) Less

func (s Sortable) Less(i, j int) bool

func (Sortable) Swap

func (s Sortable) Swap(i, j int)

Jump to

Keyboard shortcuts

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