Friday, October 10, 2025
HomeGolangCompute the identical crc as zlib - Getting Assist

Compute the identical crc as zlib – Getting Assist


Hello! I’m attempting to get the output of a crc32 to match the outcome from zlib and can’t determine the right inputs to take action. The reply to this SO has an instance utilization of zlib in Python that I’m attempting to copy in Go.

I’ve this presently:

desk := crc32.MakeTable(0xb71dc104)
outcome := crc32.Replace(0xFFFFFFFF, desk, []byte(“123456789”))
outcome ^= 0xFFFFFFFF

The polynomial that zlib makes use of is 0x04C11DB7 however the go docs counsel that it expects reversed order. I may need executed that incorrect? I’ve tried little endian and large endian and all combos of unique ors that I can consider. I’ve additionally tried crc64 after which casting again down. It’s gotta be one thing easy however I simply haven’t been capable of replicate it! Any concepts??

Thanks!

Hello @thenorthnate, how are you?
crc32.IEEE is your desk :smiley:
right here is an instance:

package deal fundamental

import (
	"fmt"
	"hash/crc32"
)

func fundamental() {
	information := []byte("123456789")
	desk := crc32.MakeTable(crc32.IEEE)

	bought := crc32.Checksum(information, desk)
	fmt.Printf("bought: %08xn", bought)

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

	outcome := crc32.Replace(0, desk, information)
	fmt.Printf("outcome: %08xn", outcome)
}

bought: cbf43926
– OR –
outcome: cbf43926

Hello @GonzaSaya! I figured it was one thing easy haha. I most likely ought to’ve tried the one that claims “commonest polynomial” from the beginning. Thanks for the assistance!! Works like a attraction.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments