CRC32 on files

Pete Shinners pete at shinners.org
Fri Jan 4 11:52:28 EST 2002


Adonis Vargas wrote:

> how do i run a CRC32 checksum on a file with python? or do i have the
> concept all wrong.
> pardon my ignorance, first time i even touch upon this subject.
> 
> thanks in advance.


hmm, you can use the SHA module to get a "SHA" checksum for a file. it 
is a bit more intensive but also probably more 'unique' then crc.

import sha
def get_sha_checksum(filename):
     filedata = open(filename).read()
     return sha.new(filedata).hexdigest()

this will return a 40byte string of hex data. it also appears you can 
get a straight up CRC32 checksum as well...

import binascii
def get_crc_checksum(filename):
     filedata = open(filename).read()
     return binascii.crc32(filedata)


that should do you pretty good. goodluck








More information about the Python-list mailing list