I came up with a string hashing algorithm which I haven't seen before, and I was hoping to get some opinions on whether it has merit as a usable hashing function for things like cryptography.
unsigned long hash(const std::string& str)
unsigned long hashed = 0;
for(it = str.begin(); it != str.end(); it++)
hashed = ((hashed - (*it)) << ((*it) % 7)) + (*it);
Algorithm aside, that certainly would not be good enough for use as a cryptographic hash since the output is limited to 64 bits, at most, on typical platforms. It would be far too vulnerable to a birthday attack.
The algorithm itself looks like one of those used for hash tables.
It looks solid for making a hash table. Though for that purpose it looks like it may have some collisions with higher valued characters.
Is the modulo operation truly necessary? Modulo is still among the slowest integer operations you can execute.
You could get a similar result by & 7 - but it extends the range a little bit from 0..6 to 0..7 - I have no idea if that matters much here.
Originally Posted by CornedBee