Jump to content
  • Advertisement
Sign in to follow this  
emileej

Effecient hashing function for identifying files

This topic is 5057 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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;

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
I said it was for identifying files. If the filenames were reliable then why would I need a hashing function at all?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!