Skip to content

Instantly share code, notes, and snippets.

@ZucchiniZe
Last active March 9, 2016 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZucchiniZe/37c508babbfb9a32bf60 to your computer and use it in GitHub Desktop.
Save ZucchiniZe/37c508babbfb9a32bf60 to your computer and use it in GitHub Desktop.
(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