procedure GetCRC32File(FileName:string;var CRC32:DWORD); function GetCrc32Str(s: string; Seed: LongInt):string; procedure GetCrc32Byte(var b:array of byte;size:Integer;var CRC32:DWORD);
implementation
procedure GetCRC32File(FileName:string;var CRC32:DWORD); var F:file; BytesRead:DWORD; Buffer:array[1..65521] of Byte; i:Word; begin FileMode :=0; CRC32 :=$ffffffff; {$I-} AssignFile(F,FileName); Reset(F,1); if IoResult = 0 then begin repeat BlockRead(F,Buffer,Sizeof(Buffer),BytesRead); for i := 1 to BytesRead do CRC32 := (CRC32 shr 8) xor Table[Buffer[i] xor (CRC32 and $000000ff)]; until BytesRead = 0; end; CloseFile(F); {$I+} CRC32 := not CRC32; end;
function GetCrc32Str(s: string; Seed: LongInt):string; var Count: Integer; CrcVal: LongInt; begin CrcVal := Seed; for Count := 1 to Length(s) do CrcVal := Table[Byte(CrcVal xor DWORD(Ord(s[Count])))] xor ((CrcVal shr 8) and $00FFFFFF); Result := IntToHex(not(CrcVal), 8); end;
procedure GetCrc32Byte(var b:array of byte;size:Integer;var CRC32:DWORD); var i:Integer; begin CRC32 :=$ffffffff; for i:=0 to size-1 do CRC32 := (CRC32 shr 8) xor Table[b[i] xor (CRC32 and $000000ff)]; CRC32 := not CRC32; end;