crc32

Is CRC32 additive?

柔情痞子 提交于 2019-11-30 02:26:21
问题 On several places I've read that crc32 is additive and so: CRC(A xor B) = CRC(A) xor CRC(B). The above statement was disproven by the following code I wrote: import zlib def crc32(data): return zlib.crc32(data) & 0xffffffff print crc32(chr(ord("A") ^ ord("B"))) print crc32("A") ^ crc32("B") Program output: 1259060791 2567524794 Could someone provide a proper code proving this theory or point me where I've failed? 回答1: CRC is additive in the mathematical sense since the CRC hash is just a

Java compatible cksum function

♀尐吖头ヾ 提交于 2019-11-29 19:57:33
问题 Is there any library/code in Java to calculate the 32-bit CRC of a stream of bytes in a way thats consistent with the cksum command in unix ? 回答1: Jacksum: http://www.jonelo.de/java/jacksum/index.html cksum algorithm: POSIX 1003.2 CRC algorithm length: 32 bits type: crc since: Jacksum 1.0.0 comment: - under BeOS it is /bin/cksum - under FreeBSD it is /usr/bin/cksum - under HP-UX it is /usr/bin/cksum and /usr/bin/sum -p - under IBM AIX it is /usr/bin/cksum - under Linux it is /usr/bin/cksum It

How to create Uncompressed Zip archive in Java

痴心易碎 提交于 2019-11-29 06:04:35
问题 I am using the Zip utility package of Java and wanted to know how to create a zip file with no compression at all. Setting the level to 0 doesn't help. Is this right? Also, when I used the STORED method, it throws following exception: java.util.zip.ZipException: STORED entry missing size, compressed size, or crc-32 I can set the size but now following exception is thrown: java.util.zip.ZipException: invalid entry crc-32 I am just following all the examples available by searching on the web

Data Length vs CRC Length

青春壹個敷衍的年華 提交于 2019-11-28 22:32:15
I've seen 8-bit, 16-bit, and 32-bit CRCs. At what point do I need to jump to a wider CRC? My gut reaction is that it is based on the data length: 1-100 bytes: 8-bit CRC 101 - 1000 bytes: 16-bit CRC 1001 - ??? bytes: 32-bit CRC EDIT: Looking at the Wikipedia page about CRC and Lott's answer, here' what we have: <64 bytes: 8-bit CRC <16K bytes: 16-bit CRC <512M bytes: 32-bit CRC It's not a research topic. It's really well understood: http://en.wikipedia.org/wiki/Cyclic_redundancy_check The math is pretty simple. An 8-bit CRC boils all messages down to one of 256 values. If your message is more

Can CRC32 be used as a hash function?

笑着哭i 提交于 2019-11-28 17:01:08
Can CRC32 be used as a hash function? Any drawbacks to this approach? Any tradedeoffs? CRC32 works very well as a hash algorithm. The whole point of a CRC is to hash a stream of bytes with as few collisions as possible. That said, there are a few points to consider: CRC's are not secure. For secure hashing you need a much more computationally expensive algorithm. For a simple bucket hasher, security is usually a non-issue. Different CRC flavors exist with different properties. Make sure you use the right algorithm, e.g. with hash polynomial 0x11EDC6F41 (CRC32C) which is the optimal general

Python CRC-32 woes

久未见 提交于 2019-11-28 11:32:57
I'm writing a Python program to extract data from the middle of a 6 GB bz2 file. A bzip2 file is made up of independently decryptable blocks of data, so I only need to find a block (they are delimited by magic bits), then create a temporary one-block bzip2 file from it in memory, and finally pass that to the bz2.decompress function. Easy, no? The bzip2 format has a crc32 checksum for the file at the end. No problem, binascii.crc32 to the rescue. But wait. The data to be checksummed does not necessarily end on a byte boundary, and the crc32 function operates on a whole number of bytes. My plan:

zipfile.BadZipFile: Bad CRC-32 when extracting a password protected .zip & .zip goes corrupt on extract

我们两清 提交于 2019-11-28 10:34:49
问题 I am trying to extract a password protected .zip which has a .txt document (Say Congrats.txt for this case). Now Congrats.txt has text in it thus its not 0kb in size. Its placed in a .zip (For the sake of the thread lets name this .zip zipv1.zip ) with the password dominique for the sake of this thread. That password is stored among other words and names within another .txt (Which we'll name it as file.txt for the sake of this question). Now if I run the code below by doing python Program.py

JavaScript CRC32

安稳与你 提交于 2019-11-27 17:15:33
I'm looking for a modern JavaScript implementation of CRC32. This implementation , which may have originated from here , and is now here, there and everywhere , is unacceptable because it's slow (500ms/MB), and depends on over 2KB of space delimited table, accessed using substr. Yuck! There appears to be a few variations of CRC32, so I need to match this output: mysql> SELECT CRC32('abcde'); > 2240272485 Function doesn't actually need to accept a string however, since I'm working with byte arrays. Update I added a helper function to create the CRCTable instead of having this enormous literal

How is a CRC32 checksum calculated?

青春壹個敷衍的年華 提交于 2019-11-27 16:55:21
Maybe I'm just not seeing it, but CRC32 seems either needlessly complicated, or insufficiently explained anywhere I could find on the web. I understand that it is the remainder from a non-carry-based arithmetic division of the message value, divided by the (generator) polynomial, but the actual implementation of it escapes me. I've read A Painless Guide To CRC Error Detection Algorithms , and I must say it was not painless. It goes over the theory rather well, but the author never gets to a simple "this is it." He does say what the parameters are for the standard CRC32 algorithm, but he

Data Length vs CRC Length

删除回忆录丶 提交于 2019-11-27 14:33:26
问题 I've seen 8-bit, 16-bit, and 32-bit CRCs. At what point do I need to jump to a wider CRC? My gut reaction is that it is based on the data length: 1-100 bytes: 8-bit CRC 101 - 1000 bytes: 16-bit CRC 1001 - ??? bytes: 32-bit CRC EDIT: Looking at the Wikipedia page about CRC and Lott's answer, here' what we have: <64 bytes: 8-bit CRC <16K bytes: 16-bit CRC <512M bytes: 32-bit CRC 回答1: It's not a research topic. It's really well understood: http://en.wikipedia.org/wiki/Cyclic_redundancy_check The