basen

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2019 License: MIT Imports: 3 Imported by: 6

README

basen

GoDoc Build Status codecov Report card

Package basen implements a radix encoding/decoding scheme, defined by a n-character alphabet.

import "github.com/nicksnyder/basen"

base62

Base62 encoding encodes data using the character set 0-9A-Za-z. It is useful for generating strings that are safe to include in URLs, and allows easy copy and paste because a double-click will usually select the whole string.

Encode:

encoded := basen.Base62Encoding.EncodeToString([]byte("Hello"))
fmt.Println(encoded) // 5TP3P3v

Decode:

decoded, _ := basen.Base62Encoding.DecodeString("5TP3P3v")
fmt.Println(string(decoded)) // Hello

base58

Base58 encoding is base62 encoding modified to avoid letters which might look ambiguous when printed (i.e. 0, O, I, l). This reduces the risk of errors when a human is manually copying from some visual source.

Encode:

encoded := basen.Base58Encoding.EncodeToString([]byte("Hello"))
fmt.Println(encoded) // 9Ajdvzr

Decode:

decoded, _ := basen.Base58Encoding.DecodeString("9Ajdvzr")
fmt.Println(string(decoded)) // Hello

Documentation

Overview

Package basen implements a radix encoding/decoding scheme, defined by a n-character alphabet.

Index

Constants

This section is empty.

Variables

View Source
var Base58Encoding = NewEncoding("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")

Base58Encoding is the standard base58 encoding, which is the alternate base64 encoding defined in RFC 4648 modified to avoid both non-alphanumeric characters and letters which might look ambiguous when printed. It is designed for human users who manually enter the data, copying from some visual source, but also allows easy copy and paste because a double-click will usually select the whole string, and it is safe to include in a URL with escaping.

View Source
var Base62Encoding = NewEncoding("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")

Base62Encoding is the standard base62 encoding, which is the standard base64 encoding defined in RFC 4648 modified to avoid non-alphanumeric characters. It is useful for generating strings that are safe to include in URLs, and allows easy copy and paste because a double-click will usually select the whole string.

Functions

This section is empty.

Types

type Encoding

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

An Encoding is a radix encoding/decoding scheme, defined by a n-character alphabet.

func NewEncoding

func NewEncoding(alphabet string) *Encoding

NewEncoding returns a new Encoding defined by the given alphabet.

func (*Encoding) DecodeString

func (e *Encoding) DecodeString(s string) ([]byte, error)

DecodeString returns the bytes represented by the encoded string s.

func (*Encoding) DecodeStringToBigInt

func (e *Encoding) DecodeStringToBigInt(s string) (*big.Int, error)

DecodeStringToBigInt returns the big.Int represented by the encoded string s.

func (*Encoding) DecodeStringToInt64

func (e *Encoding) DecodeStringToInt64(s string) (int64, error)

DecodeStringToInt64 returns the int64 represented by the encoded string s.

func (*Encoding) DecodedLen

func (e *Encoding) DecodedLen(n int) int

DecodedLen returns the maximum length in bytes of the decoded data corresponding to n bytes of encoded data.

func (*Encoding) EncodeBigIntToString

func (e *Encoding) EncodeBigIntToString(src *big.Int) string

EncodeBigIntToString returns the encoding of src.

func (*Encoding) EncodeInt64ToString

func (e *Encoding) EncodeInt64ToString(n int64) string

EncodeInt64ToString returns the encoding of n.

func (*Encoding) EncodeToString

func (e *Encoding) EncodeToString(src []byte) string

EncodeToString returns the encoding of src.

func (*Encoding) EncodedLen

func (e *Encoding) EncodedLen(n int) int

EncodedLen returns the length in bytes of the encoding of an input buffer of length n.

Jump to

Keyboard shortcuts

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