You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
889 B

4 years ago
(def DEFAULT_ALPHABET "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")
(def DEFAULT_SEPS "cfhistuCFHISTU")
(def DEFAULT_SALT "")
(def DEFAULT_MIN_LENGTH 0)
(def MIN_ALPHABET_LENGTH 16)
(def SEP_DIV (/ 7 2))
(def GUARD_DIV 12)
(defn consistent-shuffle [alphabet salt]
(if (= "" salt) alphabet
(let [alph-bytes (apply array (string/bytes alphabet))
salt-bytes (string/bytes salt)]
(var p 0)
(loop [i :down [(- (length alph-bytes) 1) 0]]
(let [v (mod (- (length alph-bytes) i 1) (length salt-bytes))
4 years ago
n (get salt-bytes v)]
(set p (+ p n))
(def j (mod (+ n v p) i))
(def a (get alph-bytes j))
(def b (get alph-bytes i))
(put alph-bytes i a)
(put alph-bytes j b)
))
(apply string/from-bytes alph-bytes))))
(defn encode [opts num]
"j0gW")