interplane.Get Omega
Read in your language

omega-zip

omega-zip: ZIP archive reader in seeded Omega (store and deflate, CRC-32, fail-closed refusals)

Brought by drakestapleton

branch main Branches Tags History

omega-zip / src / crc32.om

47 lines · 1162 bytes Raw Blame History
1note ======== src/crc32.om: CRC-32 (ISO 3309 / ITU-T V.42, the zip and gzip CRC) ========
2note Reflected polynomial 0xEDB88320 (3988292384), register preset to all ones, result inverted,
3note as specified in the zip application note section 4.4.7 and RFC 1952 section 8.
4note crcinit builds the 256-entry table the usual way: entry n is n shifted right 8 times,
5note XORing the polynomial whenever the bit shifted out is 1.
6
7fn crcinit to void
8for n uint 256
9c = n
10for k uint 8
11if eq and c 1 1
12c = xor 3988292384 shr c 1
13else
14c = shr c 1
15end
16end
17put crctab n c
18end
19end
20
21note crcrun: CRC-32 of all of stdin, printed as 8 lowercase hex digits and a newline.
22note At most 2^40 input bytes, counted in bytes (a pipe may return short reads); more is refused
23note with code 22. Every pass reads at least one byte, so 2^40 + 2 passes reach the bound or the end.
24fn crcrun to int
25put crcv 0 4294967295
26n = ulong 0
27while true bound 1099511627778
28r = read 0 win 0 WSIZE
29if lt r 0
30fail 3 tread
31ret 3
32end
33if eq r 0
34c = xor get crcv 0 4294967295
35sayhex ulong c 8
36say tnl
37ret 0
38end
39crcwin ulong r
40n = add n ulong r
41if gt n 1099511627776
42fail 22 tbig
43ret 22
44end
45end
46ret 22
47end