crc.l (960B)
1 # 25may11abu 2 # (c) Software Lab. Alexander Burger 3 4 (if (== 64 64) (load "@lib/native.l") (from "/**/")) 5 6 (gcc "util" NIL 7 (crc (Len Lst) "crc" 'I Len (cons NIL (cons Len) Lst)) ) 8 9 int crc(int len, char *p) { 10 int res, c, i; 11 12 for (res = 0; --len >=0;) { 13 c = *p++; 14 for (i = 0; i < 8; ++i) { 15 if ((c ^ res) & 1) 16 res ^= 0x14002; /* Polynom x**16 + x**15 + x**2 + 1 */ 17 c >>= 1, res >>= 1; 18 } 19 } 20 return res; 21 } 22 23 /**/ 24 25 26 (ifn (== 64 64) (load "@lib/gcc.l") (from "/**/")) 27 28 (gcc "crc" NIL 'crc) 29 30 any crc(any ex) { 31 any x; 32 int len, res, c, i; 33 34 len = evCnt(ex, x = cdr(ex)); 35 x = cdr(x), x = EVAL(car(x)); 36 for (res = 0; --len >=0; x = cdr(x)) { 37 c = (int)xCnt(ex,car(x)); 38 for (i = 0; i < 8; ++i) { 39 if ((c ^ res) & 1) 40 res ^= 0x14002; /* Polynom x**16 + x**15 + x**2 + 1 */ 41 c >>= 1, res >>= 1; 42 } 43 } 44 return boxCnt(res); 45 } 46 47 /**/ 48 49 # vi:et:ts=3:sw=3