Categorygithub.com/boreq/friendlyhash
repositorypackage
0.0.0-20190522010448-1ca64b3ca69e
Repository: https://github.com/boreq/friendlyhash.git
Documentation: pkg.go.dev

# README

Friendly hash GoDoc Build Status codecov

Friendly hash is a Go library which implements human-readable and reversible representation of known-length byte slices. It can be used to represent hashes in a human-readable way.

The core idea

This library aims to make hashes friendlier to humans. As an example the following hash:

9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08

Can be instead represented in the following way to make it more visually recognizable:

swiss.laboratory.mostly.parks.inches.therapy.homes.preferred.victory.applicant.making.leading.documentation.ownership.every.models.expense.targets.picture.series.return.signature

Or even displayed using emoji:

🏘 πŸ“  πŸ₯“ 😢 😑 🀢 πŸ“‹ πŸšΆβ€β™€οΈ ⌨ πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦ 🍷 πŸ˜† πŸ‘ πŸ€ 🍣 🌈 🚍 🍏 🐬 πŸ’Ί 🚝 🏯 πŸ‘ πŸ§€ 🍸 πŸš‡ πŸ™ 😝 πŸ—

Length of the output

The table below presents the number of dictionary elements which have to be used to represent a hash of a specific size using the dictionary containing the given number of elements.

Example: 11 elements are needed to encode a hash if it is 128 bits (16 bytes) long and a dictionary of 5000 elements is used.

Dictionary size128 bits256 bits512 bits
5000112142
10000102039
15000101937
2000091836
3000091835
4000091734
5000091733
6000091733
7000081632
8000081632
9000081632
10000081631

Word list

This package doesn't provide a dictionary of words used for encoding. I can recommend using one of the following lists available on Github:

If you prefer to use emoji the following library has a list of those:

Code example

dictionary := []string{"word1", "word2", "word3", "word4", "word5", "word6"}
hashSize := 2

// Create
h, err := New(dictionary, hashSize)
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"