Link to home
Start Free TrialLog in
Avatar of pbonney
pbonney

asked on

How to get a checksum for a disk file?

I want to be able to quickly compare two disk files to see
if they are identical.  I have the ability to remember
information about the files, so it would be handy to keep
checksums for older files, and then just checksum new files
as they come in and compare the results.

Short of writing the checksumming code myself, is there a
way of generating checksums on Windows files?  (Appearances
to the contrary notwithstanding, this is not actually a
yes/no question; please do not respond unless you can
actually point me at something useful. :-)

I'm using Borland C++ on Win32.

Extra credit (but no extra points :-):  It'd be nice to be
able to generate the checksums on buffers in memory as well.
Avatar of faster
faster

For normal checksum is easy, for example, if you have a buffer which is n Bytes long:

unsigned char checksum = 0;

for (int i=0; i<n; i++)
   checksum += buf[i];

That's it.

If you want better digital digest, you can use MD5.  There is also another option: CRC, which is better than checksum, but MD5 is the best of these three.



Avatar of pbonney

ASKER

Nothing personal -- this is my first time using this service
(and I realize you're volunteering your help) -- but this is
hardly the "expert" answer I was hoping for.

Your solution provides a non-unique checksum for in-memory
buffers.  My question was focused on a useful solution for disk
files, and (while I didn't constrain the answer to any particular
checksum algorithm) the question's designation as 'hard' I'd
think rules out an algorithm that doesn't deliver a pretty
unique fingerprint.

Moreover, I can certainly implement CRC or MD5 (or, more likely
since security isn't an issue, MD4) myself.  However, My query
was an attempt to see if I could save myself the effort by
finding something either in the windows APIs or off-the-shelf.

I apologize if, in my efforts to be succinct in my phrasing of
the question, I was unclear in my intent.  I'm looking for a
pointer to a windows API call, or a cost-effective freeware/
shareware/commercial package (source and/or binary).

Thanks for responding!
It is OK, I don't know what purpose you want for a "checksum", you know all the options I mentioned are useful in respective situations.

I am using md5, since our application must be secure and I am using a product of a company called "algorithmic research".  I am  very sure that win32 does not have such an API, but I don't know whether there is a freeware.  Most probably someone has written the code in some book.
You might want to have a look at:

http://www.cs.umd.edu/~harry/jotp/

it has md4 and md5 implemented in java.
ASKER CERTIFIED SOLUTION
Avatar of dmetzler
dmetzler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial