Tuukka Toivonen wrote:

> Download GZIP and deflate compression specifications. They explain CRC
> (32-bit if my memory serves) and sample implementation. It was very easy to
> understand, even I did.

I don't find it so easy ... :
Spending 5 minutes reading the crc code, all i understood
is that gzip first compute a table containing the first
256 values of the polynom

x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1

( I don't even undestand how those values are computed
    ( in sample/makecrc.c))

This table (crc_32_tab) is then used in util.c/updcrc :

ulg updcrc(s, n)
    uch *s;                 /* pointer to bytes to pump through */
    unsigned n;             /* number of bytes in s[] */
{
    register ulg c;         /* temporary variable */

    static ulg crc = (ulg)0xffffffffL; /* shift register contents */

    if (s == NULL) {
          c = 0xffffffffL;
    } else {
        c = crc;
        if (n) do {
            c = crc_32_tab[((int)c ^ (*s++)) & 0xff] ^ (c >> 8);
        } while (--n);
    }
    crc = c;
    return c ^ 0xffffffffL;       /* (instead of ~c for 64-bit machines) */
}


I think I'll use the weighted checksum sugested by glynn Clemens
which is a lot simpler to me.

david

Reply via email to