|
Nick Craig-Wood |
at Aug 13, 2013 at 8:02 am
|
⇧ |
| |
On 13/08/13 02:42, Josh Bleecher Snyder wrote:According to
http://en.wikipedia.org/wiki/Cyclic_redundancy_check, if
you append a crc32 to a message and then recalculate the crc32 on that
longer message, you should get zero.
Note the "usually but not always" in that paragraph!
I don't seem to be able to reproduce that with hash/crc32 in the stdlib,
with any polynomial. Here's an example:
http://play.golang.org/p/scQSxgF6IAWhat am I doing wrong? Or am I just confused about how this is supposed
to work? (Is this a crc32 question instead of a golang question?)
It's a CRC32 question really, but here is the answer...
The CRC32 CRC is inverted so that all zero messages don't produce zero
polynomials.
And CRC32 CRCs are appended to messages in bigendian format for some
reason I've never been able to understand, whereas the polynomial used
is little endian.
So if you append the inverted CRC little end first then you'll get a
zero (FFFFFFFF actually) CRC.
http://play.golang.org/p/gNG37hKG2mHope that helps!
--
Nick Craig-Wood <
nick@craig-wood.com> --
http://www.craig-wood.com/nick--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out.