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.
精彩评论