compute crc of file in python

A little more compact and optimized code def crc(fileName): prev = 0 for eachLine in open(fileName,”rb”): prev = zlib.crc32(eachLine, prev) return “%X”%(prev & 0xFFFFFFFF) PS2: Old PS is deprecated – therefore deleted -, because of the suggestion in the comment. Thank you. I don’t get, how I missed this, but it was really good.

How to use boost::crc?

Dan Story and ergosys provided good answers (apparently I was looking in the wrong place, that’s why the headaches) but while I’m at it I wanted to provide a copy&paste solution for the function in my question for future googlers: #include <boost/crc.hpp> uint32_t GetCrc32(const string& my_string) { boost::crc_32_type result; result.process_bytes(my_string.data(), my_string.length()); return result.checksum(); }

Data Length vs CRC Length

It’s not a research topic. It’s really well understood: http://en.wikipedia.org/wiki/Cyclic_redundancy_check The math is pretty simple. An 8-bit CRC boils all messages down to one of 256 values. If your message is more than a few bytes long, the possibility of multiple messages having the same hash value goes up higher and higher. A 16-bit CRC, … Read more

Function to Calculate a CRC16 Checksum

There are several details you need to ‘match up’ with for a particular CRC implementation – even using the same polynomial there can be different results because of minor differences in how data bits are handled, using a particular initial value for the CRC (sometimes it’s zero, sometimes 0xffff), and/or inverting the bits of the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)