I need a tool to generate a 6-digit "hash" from a file. Naturally, identical files should always create the same hash. What is a good way to do this?
- This is required on a vanilla debian system.
- I understand that with just 6-digits hash collisions can occur, but the hope is that it will be unlikely. In case of collision MD5 hashes can be used.
- Input files will most likely be PDFs, if that makes any difference.
crc32
(part oflibarchive-zip-perl
package), then convert the last six of the 8 hex digits to four characters by recoding in base64 ([a-zA-Z0-9/+]
), thereby preserving the same level of uniqueness as the crc32. The recoding part can be done with{ echo -n 0:; crc32 FileName|cut -c 3-8; }|xxd -r|base64
. If you're interested, I'll document it fully in an answer. – AFH May 24 '17 at 23:24