* fixed crc sample

git-svn-id: trunk@12574 -
This commit is contained in:
ivost 2009-01-20 01:54:21 +00:00
parent 4ab7922296
commit f0dc1a133f
2 changed files with 15 additions and 11 deletions

View File

@ -11,10 +11,10 @@ const
testseq1: string = 'MNIIQGNLVGTGLKIGIVVGRFNDFITSKLLSGAEDALLRHGVDTNDIDVAWVPGAFEIPFAAKKMAETKKYDAIITLGTVIRGATTSYDYVCNEAAKGIAQAANTTGVPVIFGIVTTENIEQAIERAGTKAGNKGVDCAVSAIEMANLNRSFE';
testseq2: string = 'MNIIQGNLVGTGLKIGIVVGRFNDFITSKLLSGAEDALLRHGVDTNDIDVAWVPGAFEIPFAAKKMAETKKYDAIITLGDVIRGATTHYDYVCNEAAKGIAQAANTTGVPVIFGIVTTENIEQAIERAGTKAGNKGVDCAVSAIEMANLNRSFE';
test1_crc64: qword = 1;
test2_crc64: qword = 1;
test1_crc32: longword = 1;
test2_crc32: longword = 1;
test1_crc64: qword = 14444300186948028230;
test2_crc64: qword = 3310614217963326015;
test1_crc32: longword = 3319070459;
test2_crc32: longword = 1148765760;
procedure perform_crc32(const name, testcase: string; result: longword);
@ -24,11 +24,11 @@ begin
crc := crc32(0,nil,0);
crc := crc32(crc,@testcase[1],length(testcase));
write(name,': ');
write(name,'(size=',length(testcase),'): ');
if crc=result then
writeln('passed')
else
writeln('failed');
writeln('failed (got=',crc,',expected=',result,')');
end;
procedure perform_crc64(const name, testcase: string; result: qword);
@ -38,11 +38,11 @@ begin
crc := crc64(0,nil,0);
crc := crc64(crc,@testcase[1],length(testcase));
write(name,': ');
write(name,'(size=',length(testcase),'): ');
if crc=result then
writeln('passed')
else
writeln('failed');
writeln('failed (got=',crc,',expected=',result,')');
end;

View File

@ -67,6 +67,11 @@ implementation
* CRC32
******************************************************************************)
const
CRC32_XINIT = $FFFFFFFF;
CRC32_XOROT = $FFFFFFFF;
{$IFDEF DYNAMIC_CRC_TABLE}
{local}
@ -213,14 +218,13 @@ end;
function crc32 (crc : cardinal; buf : Pbyte; len : cardinal): cardinal;
begin
if buf = nil then
exit(0);
exit(0{CRC32_XINIT});
{$IFDEF DYNAMIC_CRC_TABLE}
if crc32_table_empty then
make_crc32_table;
{$ENDIF}
crc := crc xor cardinal($ffffffff);
while (len >= 8) do
begin
crc := crc32_table[(crc xor buf^) and $ff] xor (crc shr 8);
@ -249,7 +253,7 @@ begin
dec(len);
until (len = 0);
result := crc xor cardinal($ffffffff);
result := crc; //xor CRC32_XOROT;
end;