hackutils

package module
v0.0.0-...-8f608b0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2019 License: Unlicense Imports: 7 Imported by: 0

README

hackutils

Various hacky utils for Go

Please don't use this code in production. It's meant for writing quick "scripts" in Go, eschewing proper error handling etc.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HammingDistance

func HammingDistance(b1, b2 []byte) int64

HammingDistance computes the hamming distance (number of bits that are different) between b1 and b2.

func HexReaderToBytes

func HexReaderToBytes(r io.Reader) []byte

HexReaderToBytes converts all hexadecimal-encoded data in r to raw bytes. The input has to consist of (possibly whitespace-separated) hexadecimal daat only - for example a file with some hexa data per line (newline separated). The returned byte buffer is the concatenation of all input found in the reader.

func HexToBytes

func HexToBytes(h []byte) []byte

HexToBytes converts hexadecimal encoded bytes to raw bytes, failing the program in case of errors. For example, []byte{"aa18"} is converted to []byte{0xaa, 0x18}.

func KLDivergence

func KLDivergence(p, q []float64) float64

KLDivergence computes the Kullback-Leibler divergence between two probability distributions p and q. p and q are expected to have the same length and contain numbers that sum up to 1.0; The KL divergence is close to 0 if the two distributions are deemed "similar" and gets larger the more different they are. See https://en.wikipedia.org/wiki/Kullback%E2%80%93Leibler_divergence

func XorBytes

func XorBytes(b1, b2 []byte) []byte

XorBytes performs a binary XOR between two byte slices of the same length. If the length is different it fails. Returns a new byte slice with the result.

func XorBytesWithVal

func XorBytesWithVal(bs []byte, b byte) []byte

XorBytesWithVal performs a binary XOR between every byte in bs with b. Returns a new byte slice with the result.

func XorWithRepeatingMask

func XorWithRepeatingMask(bs []byte, mask []byte) []byte

XorWithRepeatingMask performs a binary XOR between bs and mask, with mask repeated enough times to cover the length of bs. For example, with a 10-byte bs and the mask "XYZ", bs will be XOR-ed with "XYZXYZXYZX". Note that just enough of the mask is taken to cover the leftovers.

Types

This section is empty.

Jump to

Keyboard shortcuts

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