CLHasher is a Linux command line utility to get non-cryptographic hashes of strings or data.
clhasher <options> <algorithm flag> <input>- Clone the repository.
# Clone into directory 'clhasher'
git clone https://github.com/penguin-teal/clhasher.git clhasher
# Enter that directory
cd clhasher
# Go to specific release (v1.1.0 is latest)
git switch --detach v1.1.0- Build the project.
# Make a release build
make release- Install. To install there is a
make installtarget and an optionalDESTDIRvariable.
# Install to /usr/local/bin: (ROOT is required)
sudo make install
# or to other dir:
# make install DESTDIR=/some/other/dir# Go to where you cloned the repository
cd clhasher
# Get the changes
git pull
# Switch to latest (v1.1.0 is latest)
git switch --detach v1.1.0
# Clean just to be safe then build release again
make clean release
# Install like you did before (ROOT is required)
sudo make installTo uninstall just rm the executable file:
# if you used make install: (ROOT is required)
rm /usr/local/bin/clhasher -i
# or if you installed using DESTDIR=*:
# rm /some/other/dir/clhasher -iThis creates a 64-bit hash using the FNV-1A algorithm:
clhasher --fnv1a-64 'My String'Which prints:
9354639888599838980
You can also format the output better:
clhasher -ax --fnv1a-64 'My String'Which prints:
u64 [0]: 0x81D25B6A69B17104
The -a option is for --annotate which produces a little more of a formatted
output, and -x is for --hex which prints the hash as a base-16 hexadecimal
number.
You can also split large integers into smaller ones:
clhasher -ax --fnv0-128 --split-64 'splitting'u64 [0]: 0x2FE83015B8E8ABEC
u64 [8]: 0x12A4876D7700025E
It can also read from STDIN:
gcc --version | grep --color=never 'gcc' | clhasher -x --fnv1a-64DBEF2942FEC1D09F
More examples:
# Hash entire file:
clhasher -x -i ./Makefile --fnv1-32
# 50C5D52
# Hash up to 20 chars from a file:
clhasher -x -i ./Makefile --fnv1a-32 -z 20
# 577B9B35
# Hash the NUL terminator:
clhasher -x0 --fnv1a-64 'TESTSTR'
# BEB7B33DE037BF70
# Use escape codes:
clhasher -xe --fnv1a-64 'line1\n\tline2'
# B2063D2905CD97E1
# Use multiline hashing:
clhasher -axm --fnv1a-64
# > Hello
# #01 u64 [0]: 0x63F0BFACF2C00F6B
# > Sir
# #02 u64 [0]: 0xF76EA5B545A72761
# > Hashed
# #03 u64 [0]: 0x6CEC30CFBB0E4C7C
# > Sir
# #04 u64 [0]: 0xF76EA5B545A72761
# > Lol
# #05 u64 [0]: 0x68344BC6E6C587E0
# > Ctrl + D
# 1 Collisions
#
# Hashes #2 (Sir) and #4 (Sir) both get this hash:
# #01 u64 [0]: 0xF76EA5B545A72761Currently the following algorithms are supported:
- FNV-0: 32, 64, & 128 (
--fnv0-32,--fnv0-64,--fnv0-128) - FNV-1: 32, 64, & 128 (
--fnv1-32,--fnv1-64,--fnv1-128) - FNV-1A: 32, 64, & 128 (
--fnv1a-32,--fnv1a-64,--fnv1a-128)
Here are all the options. You can also run clhasher --help for a similar list.
Usage:
clhasher <options> <algorithm option> <string>Or omit <string> for STDIN:
echo 'hello' | clhasher <options> <algorithm option>Miscellaneous:
-o <FILE>/--out=<FILE>Print into a file. Defaults to-for STDOUT.-i <FILE>/--in=<FILE>Read from a file if no value argument is given. Defaults to-for STDIN.-z <BYTES>/--length=<BYTES>Number of bytes of input to hash. Defaults to0for automatic.-0/--hash-nulWhen length is automatic, includes the\0NULto hash (by default does not hash theNUL).-e/--escapeAllow escape sequences in the inputted string (see Escaping).-m/--multiIndividually hash each line of input (splits input by a line feed). Also automatically reports any collisions.-v/--verboseDescribe what is happening.-?/--helpPrint help list.--usageSee usage message.-V/--versionPrint program version.
--fnv0-32FNV-0 32-bit algorithm.--fnv0-64FNV-0 64-bit algorithm.--fnv0-128FNV-0 128-bit algorithm.--fnv1-32FNV-1 32-bit algorithm.--fnv1-64FNV-1 64-bit algorithm.--fnv1-128FNV-1 128-bit algorithm.--fnv1a-32FNV-1A 32-bit algorithm.--fnv1a-64FNV-1A 64-bit algorithm.--fnv1a-128FNV-1A 128-bit algorithm.
Output Formatting:
-a/--annotatePrint output with nicer formatting.--hi-to-loWhen splitting the output, print the most significant part first (i.e. simulates big-endian on an integer scale).-x/--hexPrint base-16 hexadecimal numbers.--octalPrint base-8 octal numbers.--base-10Print base-10 "normal" numbers (default).
Splitting:
--split-32Split hash output into one/multiple 32-bit numbers (e.g. 64-bit prints two 32-bit numbers).--split-64Split hash output into one/multiple 64-bit numbers (default).
You can enable escaping via -e. Enabling escaping means that the string must
end at a NUL, and therefore having a string containing NULs like
-z <SIZE> allows will not work.
| Escape Code | ASCII | Description |
|---|---|---|
\n |
0A |
New line |
\r |
0D |
Carriage return |
\t |
09 |
Tab |
\\ |
5C |
Backslash |
\0 |
00 |
Nul* |
\XXX |
Octal Code* | |
\oXXX |
Octal Code* | |
\xXX |
Hex Code* |
*If a NUL character exists the string will end there.