Mercurial > paraspace
changeset 68:b7432d6f7e93
adler32
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 29 Jun 2011 19:56:24 +0800 |
parents | 9504ad530dbf |
children | d07fd67e2b08 |
files | paraspace/tools.py |
diffstat | 1 files changed, 12 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/paraspace/tools.py Wed Jun 29 19:56:24 2011 +0800 @@ -0,0 +1,12 @@ +base = 65521 + +def adler32(adler, buf, offset, sz): + sum1 = adler & 0xffff + sum2 = (adler >> 16) & 0xffff + for off in range(offset, offset + sz): + sum1 = (sum1 + ord(buf[off])) % base + sum2 = (sum2 + sum1) % base + pass + r = (sum2 << 16) | sum1 + return r +