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.
40 lines
896 B
40 lines
896 B
(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- swap [arr i j]
|
|
(def a (in arr j))
|
|
(def b (in arr i))
|
|
(put arr i a)
|
|
(put arr j b)
|
|
)
|
|
|
|
(defn consistent-shuffle [alphabet salt]
|
|
(if (= "" salt) alphabet
|
|
(let [alph-bytes (apply array (string/bytes alphabet))
|
|
salt-bytes (string/bytes salt)
|
|
max-index (- (length alph-bytes) 1)]
|
|
(var p 0)
|
|
|
|
(loop [i :down [max-index 0]]
|
|
(let [v (mod (- max-index i) (length salt-bytes))
|
|
n (get salt-bytes v)
|
|
j (mod (+ n v (set p (+ p n))) i)]
|
|
(swap alph-bytes i j)))
|
|
|
|
(apply string/from-bytes alph-bytes))))
|
|
|
|
|
|
(defn encode [opts num]
|
|
"j0gW")
|