Skip to content

Instantly share code, notes, and snippets.

@mshroyer
Created March 8, 2014 20:30
Show Gist options
  • Save mshroyer/9438407 to your computer and use it in GitHub Desktop.
Save mshroyer/9438407 to your computer and use it in GitHub Desktop.
(destructuring-bind (offset in-path out-path) (cdr sb-ext:*posix-argv*)
(with-open-file (in in-path :element-type '(unsigned-byte 8))
(with-open-file (out out-path :direction :output :if-exists :supersede)
(do ((c (make-array 32)) (n 0) (a (parse-integer offset :radix 16) (+ a n)))
((zerop (setq n (read-sequence c in))))
(format out ":~2,'0X~4,'0X00" n a)
(format out "~2,'0X~%" (mod (- (apply #'+ a (ash a -8) n (map 'list (lambda (b) (format out "~2,'0X" b) b) (subseq c 0 n)))) 256)))
(format out ":00000001FF~%"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment