Skip to content

Instantly share code, notes, and snippets.

/Lock to Key (nmDC)
Created Jan 27, 2011

Embed
What would you like to do?
(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
You can’t perform that action at this time.