Compute the same crc as zlib

Hi! I am trying to get the output of a crc32 to match the result from zlib and cannot figure out the correct inputs to do so. The answer to this SO has an example usage of zlib in Python that I’m trying to replicate in Go.

I have this currently:

table := crc32.MakeTable(0xb71dc104)
result := crc32.Update(0xFFFFFFFF, table, []byte(“123456789”))
result ^= 0xFFFFFFFF

The polynomial that zlib uses is 0x04C11DB7 but the go docs suggest that it expects reversed order. I might have done that wrong? I’ve tried little endian and big endian and all combinations of exclusive ors that I can think of. I’ve also tried crc64 and then casting back down. It’s gotta be something simple but I just haven’t been able to replicate it! Any ideas??

Thank you!

Hi @thenorthnate, how are you?
crc32.IEEE is your table :smiley:
here is an example:

package main

import (
	"fmt"
	"hash/crc32"
)

func main() {
	data := []byte("123456789")
	table := crc32.MakeTable(crc32.IEEE)

	got := crc32.Checksum(data, table)
	fmt.Printf("got: %08x\n", got)

	fmt.Println("-- OR --")

	result := crc32.Update(0, table, data)
	fmt.Printf("result: %08x\n", result)
}

got: cbf43926
– OR –
result: cbf43926

Hi @GonzaSaya! I figured it was something simple haha. I probably should’ve tried the one that says “most common polynomial” from the start. Thanks for the help!! Works like a charm.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.