Home / code

Elf Hash

Writer: Christophe Wolfs
Published: 27 March 2008

This a script that hashes a string using a Elf Hash.

Note : If you are using this script in combination with another program (c++, delphi) you might have a problem. This script works fine for passwords up to +-6 characters. After that it goes wrong.
The reason is that PHP doesn't store it as bit value. If you still want to use it, change 'F0000000 in the php script and in the other program to a large int (1000000000).

<?php
function elfhash($str)
{
  $hex='$F0000000';
  $hash="";
  $tmp=0;

  for($i=0;$i<< 4)+       ord($str[$i]);
        $x=$tmp & $hex;
        if($x<>0) $tmp=$tmp ^ ($x >> 24);
        $tmp=$tmp & (~$x);
        $hash=$tmp;
  }
  return $hash;
}
?>

 

TOP