File size: 1,244 Bytes
d517dc9
 
 
 
1
2
3
4
5
{"type": "session", "harness": "opencode", "id": "misc-0002", "name": "CRC and Checksum Algorithms"}
{"type": "message", "message": {"role": "system", "content": "You are an expert programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain CRC and checksum algorithms"}}
{"type": "message", "message": {"role": "assistant", "content": "CRC (Cyclic Redundancy Check): polynomial division over GF(2).\nCRC-32: divides data by generator polynomial x^32+x^26+x^23+...+1, remainder is 32-bit checksum.\nUsed in: Ethernet, ZIP, PNG, gzip.\n\nComputation: process bits, XOR with polynomial when MSB is 1. Table-based: precompute 256-entry table for byte-at-a-time.\n\nVariants: CRC-8 (1-wire), CRC-16 (Modbus, USB), CRC-32 (Ethernet, zlib), CRC-64 (XZ).\n\nChecksum: simpler. Fletcher-16: sum of bytes, sum of running sums. Adler-32: same idea, faster.\nIP header: ones' complement sum of 16-bit words.\n\nMD5/SHA: cryptographic hashes, not just error detection. Much slower but collision-resistant.\n\nFletcher vs CRC: Fletcher is simpler but weaker. CRC detects burst errors up to polynomial degree. Both are for error detection, not correction.\n\nApplications: network packets, file integrity, compression, storage."}}