Documentation ΒΆ
Overview ΒΆ
Package friendlyhash implements human-readable and reversible representation of known-length byte slices.
Index ΒΆ
Examples ΒΆ
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
This section is empty.
Types ΒΆ
type FriendlyHash ΒΆ
type FriendlyHash struct {
// contains filtered or unexported fields
}
FriendlyHash creates a human-friendly representation of byte slices.
func New ΒΆ
func New(dictionary []string, hashLength int) (*FriendlyHash, error)
New creates a struct responsible for encoding and decoding the data using the provided dictionary and hash length. The dictionary should be a list of at least two unique strings, usually words. To decode once encoded data an identical dictionary has to be used. Hash length is required to avoid including the length of the data in the resulting representation or using padding characters.
Example ΒΆ
// Create dictionary := []string{ "word1", "word2", "word3", "word4", "word5", "word6", } h, err := New(dictionary, 2) if err != nil { panic(err) } // Humanize humanized, err := h.Humanize([]byte{'a', 'b'}) if err != nil { panic(err) } fmt.Println(strings.Join(humanized, "-")) // Dehumanize dehumanized, err := h.Dehumanize(humanized) if err != nil { panic(err) } fmt.Printf("%q\n", dehumanized)
Output: word2-word3-word1-word2-word2-word3-word1-word3 "ab"
func (*FriendlyHash) Dehumanize ΒΆ
func (h *FriendlyHash) Dehumanize(words []string) ([]byte, error)
Dehumanize converts the provided list of words previously created using the humanize function back to its byte slice equivalent.
func (*FriendlyHash) Humanize ΒΆ
func (h *FriendlyHash) Humanize(hash []byte) ([]string, error)
Humanize encodes the provided byte slice and returns its representation as a list of words from the dictionary.
func (*FriendlyHash) NumberOfBytes ΒΆ
func (h *FriendlyHash) NumberOfBytes() int
NumberOfBytes returns the hash length returned by the dehumanize function.
func (*FriendlyHash) NumberOfWords ΒΆ
func (h *FriendlyHash) NumberOfWords() int
NumberOfWords returns the number of words returned by the humanize function.