Skip to content

Commit

Permalink
Ignore planet, use our own crc32.
Browse files Browse the repository at this point in the history
  • Loading branch information
dchest committed Nov 25, 2010
1 parent f5ca81f commit f4858d7
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion crc32.rkt
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#lang racket

(require (planet untyped/unlib/crc))
; -- Taken from unlib/crc, under LGPL
; http://planet.racket-lang.org/display.ss?package=unlib.plt&owner=untyped

(define (crc32 data)
(bitwise-xor
(for/fold ([accum #xFFFFFFFF])
([byte (in-bytes data)])
(for/fold ([accum (bitwise-xor accum byte)])
([num (in-range 0 8)])
(bitwise-xor (quotient accum 2)
(* #xEDB88320 (bitwise-and accum 1)))))
#xFFFFFFFF))

(define (string->crc32 s)
(crc32 (string->bytes/utf-8 s)))
Expand All @@ -12,6 +23,7 @@
(number->hex-string (string->crc32 s)))

(provide/contract
[crc32 (-> bytes? natural-number/c)]
[string->crc32 (-> string? natural-number/c)]
[number->hex-string (-> number? any/c)]
[string->crc32/hex (-> string? any/c)])

0 comments on commit f4858d7

Please sign in to comment.