Shorter checksum than MD5
Mercuro
this at is.invalid
Thu Sep 9 07:57:07 EDT 2004
Joachim Bauch wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi,
>
> Mercuro wrote:
> | i'm looking for a simple way to checksum my data. The data is 70 bytes
> | long per record, so a 32 byte hex md5sum would increase the size of my
> | mysql db a lot.
> |
> | I'm looking for something that is 5 bytes long, for the moment i'm just
> | taking a part of the hex md5 sum (like this: checksum = md5sum[3:8]). I
> | don't have any duplicates, and I have over 100000 records, but i'm not
> | sure for the future...
> |
> |
> | Can anybody give me something better? Or point me to some website?
>
> You could use binascii.crc32() which generates a 4 byte checksum.
>
> ~From the python docs:
> crc32( data[, crc])
>
> Compute CRC-32, the 32-bit checksum of data, starting with an initial crc.
> This is consistent with the ZIP file checksum. Since the algorithm is
> designed for use as a checksum algorithm, it is not suitable for use as a
> general hash algorithm. Use as follows:
>
> ~ print binascii.crc32("hello world")
> ~ # Or, in two pieces:
> ~ crc = binascii.crc32("hello")
> ~ crc = binascii.crc32(" world", crc)
> ~ print crc
>
> Cheers,
> ~ Joachim
>
thx
More information about the Python-list
mailing list