1 import Base 2 import bend-osdev-word64@0.1.0.0/word64.bend as W 3 import bend-osdev-bytes@0.1.0.0/bytes.bend as B 4 import ./crc.bend as C 5 import ./table.bend as T 6 7 def nine() -> B.Octets: 8 B.Octets.of_string("123456789") 9 10 # n pseudo-random bytes (a linear congruential generator), built tail-recursively 11 def bulk.go(n: Nat, +s: U32, acc: List<&2, U32>) -> List<&2, U32>: 12 match n: 13 case 0n: 14 acc 15 case 1n+p: 16 +s2 = U32.add(U32.mul(s, 1103515245), 12345) 17 bulk.go(p, s2, Con{U32.and(U32.shrn(s2, 16n), 255), acc}) 18 19 def bulk(n: Nat) -> B.Octets: 20 B.Octets.of_list(bulk.go(n, 7, Nil{})) 21 22 def main() -> IO(Unit): 23 +big = bulk(102400n) 24 do IO: 25 IO.print(B.hex(B.be32(C.crc32c(nine())))) 26 IO.print(B.hex(B.be32(C.crc32(nine())))) 27 IO.print(B.hex(B.be16(C.crc16(nine())))) 28 IO.print(B.hex(B.be16(C.crc_t10dif(nine())))) 29 IO.print(W.W64.show_hex(C.crc64_ecma(nine()))) 30 IO.print(W.W64.show_hex(C.crc64_xz(nine()))) 31 IO.print(W.W64.show_hex(C.crc64_nvme(nine()))) 32 IO.print(B.hex(B.be32(C.Crc32Spec.finish(C.crc32c.spec(), C.Crc32Spec.update(C.crc32c.spec(), C.Crc32Spec.update(C.crc32c.spec(), C.Crc32Spec.start(C.crc32c.spec()), B.Octets.of_string("1234")), B.Octets.of_string("56789")))))) 33 IO.print(B.hex(B.be32(C.crc32c(big)))) 34 IO.print(B.hex(B.be32(T.Crc32Spec.compute_fast(C.crc32c.spec(), big)))) 35 IO.print(W.W64.show_hex(T.Crc64Spec.compute_fast(C.crc64_xz.spec(), big))) 36 IO.print(U32.show(C.crc4_itu(nine()))) 37 IO.print(U32.show(C.crc7_mmc(nine()))) 38 IO.print(U32.show(C.crc8_smbus(nine()))) 39 IO.print(U32.show(C.crc8_itu(nine()))) 40 IO.print(U32.show(C.crc8_maxim(nine()))) 41 IO.print(U32.show(C.crc8_dvb_s2(nine()))) 42 IO.print(U32.show(C.crc8_autosar(nine()))) 43 IO.print(B.hex(B.be16(C.crc16_kermit(nine())))) 44 IO.print(B.hex(B.be16(C.crc16_ccitt_false(nine())))) 45 IO.print(B.hex(B.be16(C.crc16_xmodem(nine())))) 46 IO.print(U32.show(C.Crc32Spec.finish(C.crc7_mmc.spec(), C.Crc32Spec.update(C.crc7_mmc.spec(), C.Crc32Spec.update(C.crc7_mmc.spec(), C.Crc32Spec.start(C.crc7_mmc.spec()), B.Octets.of_string("1234")), B.Octets.of_string("56789"))))) 47 48 #|e3069283 49 #|cbf43926 50 #|bb3d 51 #|d0db 52 #|6c40df5f0b497347 53 #|995dc9bbdf1939fa 54 #|ae8b14860a799888 55 #|e3069283 56 #|70cabb82 57 #|70cabb82 58 #|5fffa685dfdeb9c0 59 #|7 60 #|117 61 #|244 62 #|161 63 #|161 64 #|188 65 #|223 66 #|2189 67 #|29b1 68 #|31c3 69 #|117