Cryptographic hash functions are widely used for verifying data integrity, but hexadecimal (or worse, binary) representations are hard for humans to remember. In contrast, humans have evolved to parse other human faces instantly and to store thousands of them in memory.
This makes faces the ideal representation for cryptographic hashes, at least for quickly checking if some data has changed, even after a long time has passed.
You need a Linux environment with Python >=3.7 and PyTorch >=1.8 installed. Then install via:
pip install git+https://github.com/alebeck/facehash
facehash
should have been added to your PATH
, just call it like
facehash file
# or
echo -n "hello world!" | facehash
# you can also specify an output file (instead of displaying)
echo -n "hello world!" | facehash -o out.png
The first run can take a bit longer as the StyleGAN2 model has to be downloaded and relevant PyTorch extensions are built.
We calculate an extended (512 byte) SHA hash by appending eight nonce values to the input and concatenating the respective SHA-512 hashes. Each byte is expected to be uniformly distributed within its value range, due to the chaotic nature of the hash. We use a Box-Muller transform to deterministically map the uniformly distributed bytes to a 512-dimensional Gaussian latent vector, which is expected by the Generator function of NVIDIA's StyleGAN2-ADA model.