目标
实现 32 位 FNV-1a:偏移基 0x811c9dc5、素数 0x01000193,逐字符异或后无符号右移乘法;对每个命令行参数输出十六进制摘要。
要点
官方向量由测试钉死:空串 0x811c9dc5、“a” 0xe40c292c、“foobar” 0xbf9cf968;顺序敏感性由 ab 与 ba 的不同摘要验证。
提示
FNV-1a 是快速非密码学哈希——只用于校验和与哈希表,绝不能当签名。
验证
node –test 三个向量用例;CLI 传 foobar 输出 0xbf9cf968。 复现命令:
node --test fnv.test.mjs
node fnv.mjs foobar
预期输出要点:Running with the argument foobar prints 0xbf9cf968, the official FNV-1a 32-bit digest of that string.
实测证据:Node 22.23.2: node –test -> 3 passed; official vectors for empty string, a, and foobar all matched; CLI printed 0xbf9cf968.