[fpc-pascal] old school crc32

wkitty42 at windstream.net wkitty42 at windstream.net
Sun Jul 24 21:30:47 CEST 2016


On 07/24/2016 05:03 AM, Mark Morgan Lloyd wrote:
> Have you tried running your test case through a different implementation? I
> use http://www.wolfgang-ehrhardt.de/crchash_en.html

i'm trying to use only what is available in FPC... i will take a look at others, 
though...

[time passes]

ok, i looked at the one you recommended... the biggest plus is that it had a 
self-test with a known crc32 for a given string... with that, i was able to 
figure out what was going on...

the main thing is that i need the "inverted" crc32... in other words, i needed 
the bytes all reversed so that i could visually match what i was seeing with 
what i needed... i didn't realize that swap was only swapping the hi and lo 
words of the longints... i had to specifically break that down and do it like 
this...

   mystrsumi := swap(lo(mystrsum)) shl 16 + swap(hi(mystrsum));

that gave me the bytes in the same order i was seeing them in the binary file 
and that told me that i had the proper result...

it also told me

1. i need to initialize the crc32 variable with longint($ffffffff).
2. feed each character to the routine instead of letting the routine walk the 
string on its own.
3. do NOT xor the last value with longint($ffffffff).


i've found that i cannot use the crc32 function from the crc unit that comes 
with FPC... if it is possible, i'm missing the very subtle difference... i 
suspect that the automatic pre- and post-processing parts (items 1 and 3) are 
getting in the way but it may also be how the routines walk the string if you 
feed it all to them at once... even the crc32Update routine of wolfgang's 
refuses to spit out the desired result if the whole string is given to it at 
once instead of character by character...

thanks to everyone who offered input!

-- 
  NOTE: No off-list assistance is given without prior approval.
        *Please keep mailing list traffic on the list* unless
        private contact is specifically requested and granted.



More information about the fpc-pascal mailing list