HI !
How did you calculate the checksum (crc) of a tdb file?
Thanx!
vincent_filion@yahoo.com
checksum
Moderator: Owen
checksum
HI !
I know theres a checksum for each table in the tdb file but how did you calcul it..
Yes I want the formula.. please :)
Vince.
vincent_filion@yahoo.com
I know theres a checksum for each table in the tdb file but how did you calcul it..
Yes I want the formula.. please :)
Vince.
vincent_filion@yahoo.com
Here is Pascal version. I just directly converted it from assembler so there is probably a way to make it more compact, I didn't bother.
When calling HashBuffer, Buffer is pointer to the section of TDB file you want to hash and InitHash is $FFFFFFFF.
Code: Select all
var HashTable: array[0..255] of LongWord;
function HashBuffer(Buffer: PChar; BufSize: LongWord; InitHash: LongWord): LongWord;
procedure CreateHashTable;
var
ax, si, cx: Longword;
i: byte;
begin
cx := 0;
for i := Low(HashTable) to High(HashTable) do
begin
ax := cx;
ax := ax shl $18;
for si := 0 to 7 do
begin
if (integer(ax) >= 0) then
begin
ax := ax shl 1;
end
else
begin
ax := ax + ax;
ax := ax xor $4C11DB7;
end;
end;
HashTable[i] := ax;
Inc(cx);
end;
end;
var
ax, si: LongWord;
di: byte;
i: LongWord;
begin
if (integer(HashTable[1]) >= 0) then
begin
CreateHashTable;
ax := InitHash;
end
else
ax := InitHash;
for i := 0 to BufSize - 1 do
begin
di := Byte(Buffer[i]);
si := ax;
si := si shr $18;
si := si xor di;
si := HashTable[si];
ax := ax shl 8;
ax := ax xor si;
end;
Result := ax;
end;