很久以前我使用 crc32 从字符串中计算校验和,但我不记得当时具体是怎么做的了。
echo -n "LongString" | crc32 # no output
我发现了一种使用 Python 计算它们的解决方案[1],但是难道没有一种直接从字符串计算它们的方法吗?
# signed
python -c 'import binascii; print binascii.crc32("LongString")'
python -c 'import zlib; print zlib.crc32("LongString")'
# unsigned
python -c 'import binascii; print binascii.crc32("LongString") % (1<<32)'
python -c 'import zlib; print zlib.crc32("LongString") % (1<<32)'
... | od -t x4 -N 4 -A n
。 - Pedro Gimeno-t x4
输出十六进制,使用-t d4
输出十进制。 - robertgzip -1 -c
可以使压缩更快,因为你无论如何都会丢弃它。 - Mark Adler"gzip -1 -c"
替换为"gzip -1 -f -c"
。 - undefined