Mega Code Archive

 
Categories / Delphi / Examples
 

Hash anyone

This article demonstrates a simple hashing algorythm. function HashElf(const Buf; BufSize: Integer): Integer; var Bytes: TByteArray absolute Buf; I, X: Integer; begin Result := 0; for I := 0 to BufSize - 1 do begin Result := (Result shl 4) + Bytes[I]; X := Result and $F0000000; if (X <> 0) then Result := Result xor (X shr 24); Result := Result and (not X); end; end;