base45

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package base45 implements base45 encoding, fork from https://github.com/xkmsoft/base45

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(in string) (string, error)

Decode

Decoding example 1: The string "QED8WEX0" represents, when looked up
in Table 1, the values [26 14 13 8 32 14 33 0].  We arrange the
numbers in chunks of three, except for the last one which can be two,
and get [[26 14 13] [8 32 14] [33 0]].  In base 45 we get [26981
29798 33] where the bytes are [[105 101] [116 102] [33]].  If we look
at the ASCII values we get the string "ietf!".

func Encode

func Encode(in string) string

Encode

  1. The Base45 Encoding A 45-character subset of US-ASCII is used; the 45 characters usable in a QR code in Alphanumeric mode. Base45 encodes 2 bytes in 3 characters, compared to Base64, which encodes 3 bytes in 4 characters.

    For encoding two bytes [a, b] MUST be interpreted as a number n in base 256, i.e. as an unsigned integer over 16 bits so that the number n = (a*256) + b.

    This number n is converted to base 45 [c, d, e] so that n = c + (d*45) + (e*45*45). Note the order of c, d and e which are chosen so that the left-most [c] is the least significant.

    The values c, d and e are then looked up in Table 1 to produce a three character string. The process is reversed when decoding.

    For encoding a single byte [a], it MUST be interpreted as a base 256 number, i.e. as an unsigned integer over 8 bits. That integer MUST be converted to base 45 [c d] so that a = c + (45*d). The values c and d are then looked up in Table 1 to produce a two character string.

    A byte string [a b c d ... x y z] with arbitrary content and arbitrary length MUST be encoded as follows: From left to right pairs of bytes are encoded as described above. If the number of bytes is even, then the encoded form is a string with a length which is evenly divisible by 3. If the number of bytes is odd, then the last (rightmost) byte is encoded on two characters as described above.

    For decoding a Base45 encoded string the inverse operations are performed.

Types

type IllegalBase45ByteError

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

func (IllegalBase45ByteError) Error

func (e IllegalBase45ByteError) Error() string

type InvalidCharacterError

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

func (InvalidCharacterError) Error

func (e InvalidCharacterError) Error() string

type InvalidLengthError

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

func (InvalidLengthError) Error

func (e InvalidLengthError) Error() string

Jump to

Keyboard shortcuts

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