SipHash v1.1.0 SipHash.Util

Utility module for minor masking and binary conversions.

Summary

Functions

Applies a 64 bit mask to the passed in number to force it to use only 64 bits. Any bits extending further than the 64th bit are zeroed and dropped

Converts a binary input to an unsigned number using little endian

Chunks a binary input into groups of N, where N is passed in. If a group does not have enough chars to be chunked again, it will be added to the list as is

Functions

apply_mask64(input)

Specs

apply_mask64(number) :: number

Applies a 64 bit mask to the passed in number to force it to use only 64 bits. Any bits extending further than the 64th bit are zeroed and dropped.

Examples

iex> SipHash.Util.apply_mask64(9223372036854775808)
9223372036854775808

iex> SipHash.Util.apply_mask64(92233720368547758077)
18446744073709551613

iex> SipHash.Util.apply_mask64("test_string")
** (FunctionClauseError) no function clause matching in SipHash.Util.apply_mask64/1
bytes_to_long(input)

Specs

bytes_to_long(binary) :: number

Converts a binary input to an unsigned number using little endian.

Examples

iex> SipHash.Util.bytes_to_long(<<169,138,199>>)
13077161

iex> SipHash.Util.bytes_to_long("test_string")
125040764888893876906190196

iex> SipHash.Util.bytes_to_long(5)
** (FunctionClauseError) no function clause matching in SipHash.Util.bytes_to_long/1
chunk_string(str, n)

Specs

chunk_string(binary, number) :: list

Chunks a binary input into groups of N, where N is passed in. If a group does not have enough chars to be chunked again, it will be added to the list as is.

Examples

iex> SipHash.Util.chunk_string("12345678", 4)
["1234","5678"]