I'm using ELF Hash to write a specially tweaked version of hash map. Wanting to produce collisions

StackOverflow https://stackoverflow.com/questions/5920276

  •  29-10-2019
  •  | 
  •  

Question

Can any one give an example of 2 strings, consisting of alphabetical characters only, that will produce the same hash value with ELFHash?

I need these to test my codes. But it doesn't seem like easy to produce. And to my surprise there there are a lot of example codes of various hash function on the internet but none of them provides examples of collided strings.

Below is the ELF Hash, in case you need it.

unsigned int ELFHash(const std::string& str)
{
   unsigned int hash = 0;
   unsigned int x    = 0;

   for(std::size_t i = 0; i < str.length(); i++)
   {
      hash = (hash << 4) + str[i];
      if((x = hash & 0xF0000000L) != 0)
      {
         hash ^= (x >> 24);
         hash &= ~x;
      }
   }

   return (hash & 0x7FFFFFFF);
}

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top