參考文檔加密
FNV哈希分爲3個版本:fnv-0
(已廢棄),FNV-1
,FNV-1a
code
hash = 0 for each byte_of_data to be hashed hash = hash * FNV_prime hash = hash ^ octet_of_data return hash
hash = FNV_offset_basis for each byte_of_data to be hashed hash = hash * FNV_prime hash = hash ^ byte_of_data return hash
hash = FNV_offset_basis for each byte_of_data to be hashed hash = hash ^ byte_of_data hash = hash * FNV_prime return hash
這個參數的值是固定的,根據不一樣的位數選擇不一樣的值做爲hash的首次填充值ip
位數 | 十進制值 |
---|---|
32 | 2166136261 |
64 | 14695981039346656037 |
128 | 144066263297769815596495629667062367629 |
256 | 100029257958052580907070968620625704837092796014241193945225284501741471925557 |
512 | 965930312949666949800943540071631046609041874567263789610837432943446265799458 2932197716438449813051892206539805784495328239340083876191928701583869517785 |
1024 | 1419779506494762106872207064140321832088062279544193396087847491461758272325 2296732303717722150864096521202355549365628174669108571814760471015076148029 7559698040773201576924585630032153049571501574036444603635505054127112859663 61610267868082893823963790439336411086884584107735010676915 |
尚未看懂,不過這不影響咱們實現通用32位,64位的FNV算法文檔
位數 | 十進制值 |
---|---|
32 | 16777619 |
64 | 1099511628211 |
128 | 309485009821345068724781371 |
256 | 374144419156711147060143317175368453031918731002211 |
512 | 35835915874844867368919076489095108449946327955754392558399825615420669938882 575126094039892345713852759 |
1024 | 501645651011311865543459881103527895503076534540479074430301752383111205510814745 150915769222029538271616265187852689524938529229181652437508374669137180409427187 3160484737966720260389217684476157468082573 |
hash後的最總結果get
8位無符號整數hash
要加密的數據,須要轉換成byte_of_data[]
而後循環^
計算it