From the original ...
Code: Select all
(defun update-crc (crc buf)
(declare (type (unsigned-byte 32) crc)
(type (simple-array (unsigned-byte 8)) buf)
(optimize speed))
(setf crc (logxor crc #xffffffff))
(dotimes (n (length buf))
(let ((i (logand #xff (logxor crc (aref buf n)))))
(setf crc (logxor (aref *crc-table* i) (ash crc -8)))))
(logxor crc #xffffffff))
Code: Select all
(define (update-crc crc buf)
(set 'crc (^ crc 0xFFFFFFFF))
(dotimes (n (length buf))
(set 'i (& 0xFF (^ crc (char (nth n buf)))))
(set 'crc (^ (nth i CRC-TABLE) (<< crc 8))) )
(^ crc 0xFFFFFFFF))
Code: Select all
(defun crc (buf)
(update-crc 0 buf))
;;; output should be #xCBF43926
(defun test-crc ()
(let ((a (make-array 9 :element-type '(unsigned-byte 8)
:initial-contents '(#x31 #x32 #x33 #x34 #x35 #x36 #x37 #x38 #x39))))
(crc a)))
Code: Select all
(define (crc buf)
(update-crc 0 buf))
(define (test-crc)
(crc "123456789"))
Code: Select all
(format "%08X" (crc "123456789"))