c++ - Can this checksum algorithm be improved? -


We have a very old, unsupported program that copies the files in SMB shares. There is a checksum algorithm for determining whether the file content has changed before copying. Algorithms are easily fooled - we have just found an example where two files change from one '1' to a '2', the same checksum returns here, there is an algorithm:

  Unsigned long GetFileCheckSum (CString PathFilename) {FILE * File; Unsigned long checksum = 0; Unsigned long data = 0; Unsigned long calculation = 0; = () (If the (feeds (and data, 1, size (unsigned long), file) = FALSE = {checkme ^ = data +++ calculation; data = (= file = FOPN (path = FOPN (pathfilename, "RB") = 0;} Fclose (file);} returns checksum;}  

I'm not a programmer (I am a cesammin), but I know that XOR-based checksum is going to be very crude Are the probabilities of this algorithm returning the same checksum for two files of the same size with different materials? I'm not expecting an accurate answer, "remote" or "enough prospect" is ok.)

How can it be improved without any major performance hits?

Finally, what is going on with fread () ? I was scanned the documentation quick but I did not understand what data is in return for each of the files Byte is set to? Edit : OK, so this file should be in the unsigned long What happens in each section? If the content of the file is abcd , then the value of the first data What is it? Is it (in Perl):

  (ord ('a') <24) & amp; (Ord ('b') <<16) & amp; (Ord ('c') & lt; <8) & amp; Commonly used to verify the integrity of transfer files (usually 'D')  

The source code is easily available in C ++. It is widely considered to be a fast and accurate algorithm.

See also


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -