mIRC Home    About    Download    Register    News    Help

Print Thread
#98370 23/09/04 03:26 AM
Joined: Dec 2003
Posts: 48
N
Ameglian cow
OP Offline
Ameglian cow
N
Joined: Dec 2003
Posts: 48
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.

#98371 23/09/04 09:51 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
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;
}


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#98372 24/09/04 07:39 PM
Joined: Dec 2003
Posts: 48
N
Ameglian cow
OP Offline
Ameglian cow
N
Joined: Dec 2003
Posts: 48
awesome, thanks qwerty.


Link Copied to Clipboard