python: generate 24bit hash
Question:
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!
Answers:
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.
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.