Created
January 27, 2011 19:14
-
-
Save anonymous/799022 to your computer and use it in GitHub Desktop.
http://www.teamfair.info/wiki/index.php?title=Lock_to_key <-- What I'm trying to do
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
(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