Skip to content

Instantly share code, notes, and snippets.

Created January 27, 2011 19:14
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 anonymous/799022 to your computer and use it in GitHub Desktop.
Save anonymous/799022 to your computer and use it in GitHub Desktop.
(defn nibble-swap [num]
(bit-or (bit-shift-right num 4)
(bit-and (bit-shift-left num 4) 240)))
(defn xor-string [s]
(reduce bit-xor (map int (list* s))))
(defn l2 [lock]
(let [lock-len (count lock)
a (map #(bit-xor (int (get lock %)) (int (get lock (dec %) 0))) (range lock-len))
b (reduce bit-xor (map int (vector (first lock) (last lock) (nth lock (- lock-len 2)) 5)))
c (conj a b)
d (map nibble-swap c)
key (apply str (map char d))]
key))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment