Effecient hashing function for identifying files

Started by
4 comments, last by emileej 19 years, 8 months ago
I need a hashing function to identify certain dll files and I was wondering if anyone in here knows an effecient one which they can recommend. Note: Speed is not of great importance - as long as it will get the job done.
Emil Johansen- SMMOG AI designerhttp://smmog.com
Advertisement
try this:

string = dllFileName;int hash = 0;for(int i = 0; i.string.length(); i++){  hash = ((37*hash) + string.charAt(i))%arraySize;}return hash;
Give a man a fish and you feed him for a day; teach him to use the Net and he won't bother you for weeks.
There are 3 major hashing algorithms in common use - CRC32, MD5, and SHA. I listed them in order of 'goodness': an MD5 hash is much less likely to be the same for 2 random files than a CRC32 hash, just as an SHA is more likely to be different than an MD5 hash.

You should be able to find tons of information (including source for whichever language you're using) on each of the algorithms because they are very popular. Googling with each name should get you there.

The function OrthoDiablo would be a horrible hash function because the 'hash * 37' gets rid of the top bits of the hash each time. This means the hash is only really a hash of the last few bytes of data so the first bytes could be anything without the hash changing.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
OrthoDiablo << Woudln't be very secure to base your security on a filename now would it? :)

Extrarius << Thanks. I'll have a look at the SHA algorithm for C++ then :)
Emil Johansen- SMMOG AI designerhttp://smmog.com
Well you asked for a hashing function, not for a checksum.
Give a man a fish and you feed him for a day; teach him to use the Net and he won't bother you for weeks.
I said it was for identifying files. If the filenames were reliable then why would I need a hashing function at all?
Emil Johansen- SMMOG AI designerhttp://smmog.com

This topic is closed to new replies.

Advertisement