OctopusDeploy / Octodiff

| Public | 100% C# implementation of remote delta compression based on the rsync algorithm
Other
24 stars 87 forks source link

Adler32RollingChecksum modulo operation #16

Closed GrzegorzBlok closed 6 years ago

GrzegorzBlok commented 6 years ago

Hi,

In Adler32 algorithm https://en.wikipedia.org/wiki/Adler-32 the prime used in modulo operation equals 65521 (largest prime smaller than 65536).

A = 1 + D1 + D2 + ... + Dn (mod 65521)
B = (1 + D1) + (1 + D1 + D2) + ... + (1 + D1 + D2 + ... + Dn) (mod 65521)
   = n×D1 + (n−1)×D2 + (n−2)×D3 + ... + Dn + n (mod 65521)

In the sources Adler32RollingChecksum.cs you cast to ushort which effectively does a mod 65536. Is there any particular reason for that?

The zlib RFC https://tools.ietf.org/html/rfc1950 that also defines Adler32 states that

That 65521 is prime is important to avoid a possible large class of two-byte errors that leave the check unchanged.

Regards, Grzegorz Blok