mIRC Homepage
Posted By: NrWarren $hash function - 23/09/04 03:26 AM
hey, I was wondering if anyone knew the algorithm for the $hash function? I'm sure its simple, but I havn't been able to find anything.
Posted By: qwerty Re: $hash function - 23/09/04 09:51 AM
Khaled had posted the $hash() formula in the old message board. Unfortunately, those messages were lost with the fire at the university of Twente. The good news is that I'd saved his post before the fire, so here's the function:
Code:
u_long hash(char far *text, int bits)
{
  unsigned int y;
  char far *p;
  u_long x;
  int i;

  x = 0;
  y = 0;

  p = text;
  while (*p) {
    y = (int)((x & (u_long)0xff000000L) >> 24);
    x += (unsigned char)*p;
    x += y;
    x = x << 8;
    p++;
  }

  for (i=0;i<(32-bits);i++) {
    y = (int)(x & 1);
    x = x >> 1;
    x += y;
  }

  x = (x & ((int)pow(2,bits) - 1));

  return x;
}
Posted By: NrWarren Re: $hash function - 24/09/04 07:39 PM
awesome, thanks qwerty.
© mIRC Discussion Forums