Categorygithub.com/adroge/entropy
modulepackage
1.0.2
Repository: https://github.com/adroge/entropy.git
Documentation: pkg.go.dev

# README

Entropy

Description

This package will calculate the entropy from a given string. The alphabet used to calculate the entropy can be specified.

Usage

package main

import (
	"fmt"

	"github.com/adroge/entropy"
)

func main() {
	password := "monkey"
	result, err := entropy.Calculate(password)
	if err != nil {
		fmt.Println("error: ", err)
		return
	}
	fmt.Printf("Strength of \"%s\" is %s, with entropy: %f\n", password, result, result.Bits)
}
$ go run main.go
Strength of "monkey" is very weak, with entropy: 28.202638

It's possible to change the alphabets and entropy strength bounds by utilizing the Alphabet(...) and Bounds(...) functions. If you wanted to include a subset of the Latin-1 Supplement characters, you could do it with Alphabet(...).

Unit tests are a good source of usage.

References

These aren't the only places, or even the original places, where the formula used can be found, but for my own reference I used the following:

# Packages

Package mock_entropy is a generated GoMock package.

# Functions

Alphabets replaces the currently defined alphabets.
Bounds changes the upper ranges for evaluating the strength of the calculated entropy.
Calculate analyzes the entropy of a string.
Descriptions changes the string descriptions of the String() evaluation of the entropy value.
EntropyBounds returns an array of bound values used internally.
SetMock allows replacing the call variable with the mock code found in the mock_entropy directory.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

DescriptionTags can be used to change the string representation of an entropy value.
EntropyResult contains the bits, and the evaluation that maps to exported constants.

# Interfaces

Function defines an interface that is used for testing with the generated mock_entropy code.