Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-zip/blob/main/src/crc32.om # omega-zip omega-zip: ZIP archive reader in seeded Omega (store and deflate, CRC-32, fail-closed refusals) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-zip / src / crc32.om` 47 lines ยท 1162 bytes Raw Blame History 1 note ======== src/crc32.om: CRC-32 (ISO 3309 / ITU-T V.42, the zip and gzip CRC) ======== 2 note Reflected polynomial 0xEDB88320 (`3988292384`), register preset to all ones, result inverted, 3 note as specified in the zip application note section 4.4.7 and RFC 1952 section 8. 4 note crcinit builds the 256-entry table the usual way: entry n is n shifted right 8 times, 5 note XORing the polynomial whenever the bit shifted out is 1. 6 7 fn crcinit to void 8 for n uint 256 9 c = n 10 for k uint 8 11 if eq and c 1 1 12 c = xor `3988292384` shr c 1 13 else 14 c = shr c 1 15 end 16 end 17 put crctab n c 18 end 19 end 20 21 note crcrun: CRC-32 of all of stdin, printed as 8 lowercase hex digits and a newline. 22 note At most 2^40 input bytes, counted in bytes (a pipe may return short reads); more is refused 23 note with code 22. Every pass reads at least one byte, so 2^40 + 2 passes reach the bound or the end. 24 fn crcrun to int 25 put crcv 0 `4294967295` 26 n = ulong 0 27 while true bound `1099511627778` 28 r = read 0 win 0 WSIZE 29 if lt r 0 30 fail 3 tread 31 ret 3 32 end 33 if eq r 0 34 c = xor get crcv 0 `4294967295` 35 sayhex ulong c 8 36 say tnl 37 ret 0 38 end 39 crcwin ulong r 40 n = add n ulong r 41 if gt n `1099511627776` 42 fail 22 tbig 43 ret 22 44 end 45 end 46 ret 22 47 end