开发者

python: generate 24bit hash

开发者 https://www.devze.com 2023-02-11 21:18 出处:网络
I want to generate a 24-bit-length hash from strings. After some googling, I found this:开发者_高级运维 http://code.activestate.com/recipes/164274-fixed-size-cache/ , but it seems to be too complex.

I want to generate a 24-bit-length hash from strings. After some googling, I found this:开发者_高级运维 http://code.activestate.com/recipes/164274-fixed-size-cache/ , but it seems to be too complex.

Are there other, simpler, ways to generate a 24-bit hash?

Thanks!


Does it need to by cryptographically secure? I think you could probably just truncate one of the hashes from hashlib.


You could compute a 24-bit CRC check value and use it as a hash value. The Wikipedia article on cyclic redundancy check describes how to do this for n-bit CRCs and even has several generator polynomials for 24-bits in its Polynomial representations of cyclic redundancy checks section.

0

精彩评论

暂无评论...
验证码 换一张
取 消