开发者

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

开发者 https://www.devze.com 2023-03-04 13:11 出处:网络
Can any one give an example of 2 strings, consisting of alphabetical characters only, that will produce the same hash value with ELFHash?

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 pr开发者_StackOverflowovides 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);
}


You can find collisions using a brute force method (e.g. compute all possible strings with length lower than 5).

Some example of collisions (that I got in that way):

hash = 23114:
-------------
UMz
SpJ

hash = 4543841:
---------------
AAAAQ
AAABA

hash = 5301994:
---------------
KYQYZ
KYQZJ
KYRIZ
KYRJJ
KZAYZ
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号