Mal ein Versuch:
Delphi-Quellcode:
function Skr_CRC32(const Data: string): string;
var
i, lCRC32, iBit: DWORD;
Crc32Table: array[0..255] of DWORD;
begin
for i := Low(Crc32Table) to High(Crc32Table) do
begin
lCRC32 := i;
for iBit := 0 to 7 do
begin
if lCRC32 and $01 <> 0 then
lCRC32 := ((lCRC32 and $FFFFFFFE div 2) and $7FFFFFFF) xor $EDB88320
else
lCRC32 := (lCRC32 and $FFFFFFFE div 2) and $7FFFFFFF;
end;
Crc32Table[i] := lCRC32;
end;
lCRC32 := $FFFFFFFF;
for i := 1 to Length(Data) do
lCRC32 := ((lCRC32 and $FFFFFF00 div $100) and $00FFFFFF) xor
Crc32Table[(lCRC32 and $FF) xor Ord(Data[i])];
Result := Format('%.8x', [lCRC32 xor $FFFFFFFF]);
end;
Ohne Vergleichswerte fällt das Testen allerdings schwer.
Danke für die Mühe,
Ich habe es fast ähnlich gelöst.
Delphi-Quellcode:
Function Skr_CRC32(Data :String) : String;
function Hex(data: longint; width: word): string;
(* pads with leading zeroes to reach specified width; use width=0 for tight fit *)
const
HexChars: array[0..$F] of char = '0123456789ABCDEF';
var
txt: string;
begin
txt := '';
repeat
insert(HexChars[data and $F],txt,1);
data := data shr 4;
until data=0;
while length(txt) < width do
insert('0',txt,1);
Hex:= txt;
end;
var
i, lCRC32, iBit : dword;
Crc32Table : array[0..255] of dword;
txt : string;
begin
For i := 0 To 255 do //$B40BBE37
begin
lCRC32 := i;
For iBit := 0 To 7 do
begin
If (lCRC32 And $1) <> 0 Then
lCRC32 := (((lCRC32 And $FFFFFFFE) div $2) And $7FFFFFFF) Xor $EDB88320
Else
lCRC32 := ((lCRC32 And $FFFFFFFE) div $2) And $7FFFFFFF;
end;
Crc32Table[i] := lCRC32;
end;
lCRC32 := $FFFFFFFF;
For i := 1 To length(Data) do
begin
lCRC32 := ((lCRC32 And $FFFFFF00 div $100) And $FFFFFF) Xor
Crc32Table[(lCRC32 and $FF) xor Ord(Data[i])];
end;
result := Hex(lCRC32 Xor $FFFFFFFF,8);
end;
Ich habe nur ein Problem.
Das Script gibt in Excel(VBA) beim User(testuser) immer testuser->60DA836E aus und das Delphiprog testuser->B9851374