📄 dymcrc32.pas
字号:
unit DymCrc32;
interface
uses
Windows,SysUtils,Classes;
var
Table:Array[0..255] of DWORD;
function GetCRC32File(FileName:string):String;
function GetCrc32Str(s: string; Seed: LongInt):string;
implementation
procedure MakeTable();
var
i,j,Crc:integer;
begin
for i:=0 to 255 do
begin
Crc:=i;
for j:=0 to 7 do
begin
if (Crc and 1)<>0 then
Crc:=(Crc shr 1) xor $EDB88320
else
Crc:=Crc shr 1;
end;
Table[i]:=Crc;
end;
end;
procedure GetCRC32(FileName:string;var CRC32:DWORD);
var
F:file;
BytesRead:DWORD;
Buffer:array[1..65521] of Byte;
i:Word;
begin
MakeTable();
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 GetCRC32File(FileName:String):String;
var
CRC32:DWORD;
begin
GetCRC32(FileName,CRC32);
Result:=UpperCase(IntToHex(CRC32,8));
end;
function GetCrc32Str(s: string; Seed: LongInt):string;
var
Count: Integer;
CrcVal: LongInt;
begin
MakeTable();
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;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -