Created
November 30, 2016 10:10
Revisions
-
jasonneylon created this gist
Nov 30, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ (require '[clojure.spec :as s]) (require '[clojure.spec.gen :as gen]) ;; PASSPHRASES - generate a random 5 word passphrase ;; naive approach was to generate a random string and contrain to match a five word pattern ;; however this hit 100 generation limit imposed by clojure.spec (defn words [str] (clojure.string/split str #" ")) (def five-words? (comp (partial = 5) count words)) (gen/generate (s/gen (s/and string? five-words?))) ;; Our second attempt was to read the Linux word dictionary into a set ;; and generate a five word list from it (def words (-> (slurp "/usr/share/dict/words") (clojure.string/split #"\n") (->> (filter #(= 4 (count %)))))) (s/def ::word (s/and (set words))) (s/def ::pass-phrase (s/every ::word :count 5)) (gen/generate (s/gen ::pass-phrase)) ;; DNA (s/def ::dna (s/every #{\G \T \C \A} :min-count 1)) (gen/generate (s/gen ::dna)) (s/exercise ::dna)