interplane.Get Omega
Read in your language

omega-pdf

Omega PDF: read and write PDF files in Omega

Brought by drakestapleton

branch main Branches Tags History

omega-pdf / vendor / omega-zip / src / crc32.om

46 lines · 1035 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 (33554432 reads of 32 KiB); more is refused with code 22.
23fn crcrun to int
24put crcv 0 4294967295
25n = ulong 0
26while true bound 33554433
27r = read 0 win 0 WSIZE
28if lt r 0
29fail 3 tread
30ret 3
31end
32if eq r 0
33c = xor get crcv 0 4294967295
34sayhex ulong c 8
35say tnl
36ret 0
37end
38crcwin ulong r
39n = add n 1
40if ge n 33554432
41fail 22 tbig
42ret 22
43end
44end
45ret 22
46end