在计算运行校验和时需要澄清。在
假设我有这样的数据。在data = 'helloworld'
假设块大小为5,我需要计算运行校验和。在
^{pr2}$
根据Python文档(Python版本2.7.2)zlib.adler32(data[, value])"Computes a Adler-32 checksum of data. (An Adler-32 checksum is almost
as reliable as a CRC32 but can be computed much more quickly.) If
value is present, it is used as the starting value of the checksum;
otherwise, a fixed default value is used. This allows computing a
running checksum over the concatenation of several inputs."
但当我提供这样的东西时>>> zlib.adler32('ellow', zlib.adler32('hello'))
383190072
结果完全不同。在
我尝试创建一个自定义函数来生成rsync算法中定义的滚动校验和。在def weakchecksum(data):
a = 1
b = 0
for char in data:
a += (ord(char)) % MOD_VALUE
b += a % MOD_VALUE
return (b << 16) | a
def rolling(checksum, removed, added, block_size):
a = checksum
b = (a >> 16) & 0xffff
a &= 0xffff
a = (a - ord(removed) + ord(added)) % MOD_VALUE
b = (b - (block_size * ord(removed)) + a) % MOD_VALUE
return (b << 16) | a
下面是我从运行这些函数得到的值Weak for hello: 103547413
Rolling for ellow: 105382436
Weak for ellow: 105316900
如您所见,我的滚动校验和实现与python的实现在价值上有很大的不同。在
我在计算滚动校验和时哪里出错了?
我是否正确地使用了python adler32函数的rolling属性?在