[fpc-pascal] old school crc32

Giuliano Colla giuliano.colla at fastwebnet.it
Sun Jul 24 11:12:50 CEST 2016


Il 24/07/2016 01:18, wkitty42 at windstream.net ha scritto:

> this is driving me battier than i already am :(
>
> i have a binary file that contains a record of data... the first field 
> of the data is a crc32 value of a string of characters... the string 
> of characters is lower cased before being fed to the crc32 function... 
> i need to calculate the same crc32 value as what is stored in the file...
>
> i've already checked the polynomial ($edb88320) is the same in both, 
> the original implementation (converted to TP4 in 1988) and this 
> implementation...
>
> the original routine uses longint and speaks of initializing the 
> variable to $ffffffff before feeding it to the crc32 routine... the 
> existing routine in FPC says "Pre- and post-conditioning (one's 
> complement) is performed within this function so it shouldn't be done 
> by the application." but that doesn't give me the proper answer in 
> this case... i've tried using cardinal types and longint types to no 
> avail...
>
> the following is so so so very close but now i'm bald headed, 
> completely lost in the deep dark woods and can't find my breadcrumbs 
> any more :(
>

What I'd do in your place would be to forget about strings, and use just 
an array of bytes. This way you're sure that you don't have in the way 
the string length value and some automatic encoding conversion, which 
messes up things.

Giuliano




More information about the fpc-pascal mailing list