Shorter checksum than MD5

Joachim Bauch jojo at struktur.de
Thu Sep 9 10:54:28 CEST 2004


-----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

- --
Joachim Bauch
struktur AG, jojo at struktur.de
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFBQBpEvb5cTc087cURAqBCAJ9CiSYI57djBUHRDweG7U0efIfR2wCfXIu5
e81vPBECKZh+wRVSn2jjFYo=
=uObd
-----END PGP SIGNATURE-----



More information about the Python-list mailing list