Page 1 of 1

checksum

Posted: Mon Nov 10, 2003 9:20 am
by guest
HI !

How did you calculate the checksum (crc) of a tdb file?

Thanx!

vincent_filion@yahoo.com

Posted: Mon Nov 10, 2003 11:13 am
by Artem
What do you mean? How I got "the formula" or you want "the formula" itself?

checksum

Posted: Mon Nov 10, 2003 12:10 pm
by guest
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

Posted: Tue Nov 11, 2003 4:13 pm
by Artem
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.

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;
When calling HashBuffer, Buffer is pointer to the section of TDB file you want to hash and InitHash is $FFFFFFFF.

Posted: Tue Nov 11, 2003 7:19 pm
by blinky
:shock:

"Mrs Hoover, I swallowed my crayon again. I don't feel so good"...