Last active
March 9, 2016 02:44
-
-
Save ZucchiniZe/37c508babbfb9a32bf60 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def base 65521) | |
(defn adler32 [data] | |
(let [a (atom 1) | |
b (atom 0) | |
i (atom 0) | |
l (count data) | |
m (bit-and @l -4)] | |
(while (< @i @m) | |
(let [n (min (+ @i 4096) @m)] | |
(while (< @i @n) | |
(swap! b + (+ | |
(swap! a + (int (.charAt data @i))) | |
(swap! a + (int (.charAt data (+ @i 1)))) | |
(swap! a + (int (.charAt data (+ @i 2)))) | |
(swap! a + (int (.charAt data (+ @i 3)))))) | |
(swap! a mod base) | |
(swap! b mod base) | |
(swap! i + 4)))) | |
(while (< @i @l) | |
(swap! b + (swap! a + (int (.charAt data @i)))) | |
(swap! i inc)) | |
(swap! a mod base) | |
(swap! b mod base) | |
(bit-or @a (bit-shift-left @b 16)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment