crock32

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2021 License: Apache-2.0 Imports: 1 Imported by: 0

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 img 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 Encode

func Encode(n uint64) string

Encode converts a uint64 into a Crockford base32 encoded string

func SetDigits

func SetDigits(s string) error

SetDigits allows you to change the encoding alphabet (not the decoding alphabet). The main purpose of this function is to allow upper-case encoding with crock32.SetDigits("0123456789ABCDEFGHJKMNPQRSTVWXYZ")

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