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!

Asked By: Anton Koval'

||

Answers:

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

Answered By: Katriel

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.

Answered By: martineau
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.