alpha

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrTooShort       = fmt.Errorf("alphabet must be at least %d characters", alphaMinChars)
	ErrDuplicateChars = errors.New("alphabet contains duplicated characters")
)

Functions

This section is empty.

Types

type Alphabet

type Alphabet struct {
	// contains filtered or unexported fields
}
Example
alpha := NewAlphabet("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789").Rotate(500)
// alpha = alpha.Slice(1, 10)

for i := range alpha.Len() {
	fmt.Printf("%02d = %s\n", i, string(alpha.At(i)))
}

fmt.Println("found 'd' at:", alpha.IndexByte('d'))
Output:

TODO

func NewAlphabet

func NewAlphabet(charset ...string) Alphabet

newAlphabet creates a new Alphabet without any initial rotation.

func (Alphabet) At

func (r Alphabet) At(i int64) byte

At returns the byte at the given index in the sliced rotated alphabet.

func (Alphabet) IndexByte

func (r Alphabet) IndexByte(b byte) int64

IndexByte returns the index of the given byte in the rotated and sliced alphabet, or -1 if not found.

func (Alphabet) Len

func (r Alphabet) Len() int64

Len returns the length of the sliced rotated alphabet.

func (Alphabet) Rotate

func (r Alphabet) Rotate(offset int64) Alphabet

Rotate rotates the alphabet by the given offset.

func (Alphabet) Shuffle

func (r Alphabet) Shuffle(seed int64) Alphabet

func (Alphabet) Slice

func (r Alphabet) Slice(low, high int64) Alphabet

Slice simulates slicing on the rotated alphabet.

func (Alphabet) Validate

func (r Alphabet) Validate() (err error)

Jump to

Keyboard shortcuts

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