Browse Source

Added EFF wordlist.

Dicegen script pulls latest version of app
Stephen Starkey 1 year ago
parent
commit
49e88cd31d
4 changed files with 7826 additions and 24 deletions
  1. 10
    1
      README.md
  2. 1
    1
      dicegen
  3. 7776
    0
      resources/eff.wordlist.txt
  4. 39
    22
      src/dicegen/core.clj

+ 10
- 1
README.md View File

@@ -17,13 +17,22 @@ and
17 17
 
18 18
 ## Running the application
19 19
 
20
+Regardless of how you run the application, it takes 1, 2, or 3 arguments. The
21
+first is the number of words that each password contains. If given, the second
22
+is the number of passwords to generate. If given, the third is which password
23
+list to use. You can either use the classic 
24
+[Diceware](https://www.eff.org/deeplinks/2016/07/new-wordlists-random-passphrases)
25
+wordlist using `diceware` or the newer 
26
+[EFF](https://www.eff.org/deeplinks/2016/07/new-wordlists-random-passphrases)
27
+wordlist using `eff`
28
+
20 29
 ### Using `inlein`
21 30
 
22 31
   1. Install [inlein](https://github.com/hyPiRion/inlein/wiki/Getting-Started)
23 32
   2. Run the following: `
24 33
 curl https://git.calmabiding.me/scstarkey/dicegen/raw/branch/master/dicegen 
25 34
 -o ~/bin/dicegen && chmod +x ~/bin/dicegen `
26
-  3. Then simply run `dicegen 5`
35
+  3. Then simply run `dicegen` to get help
27 36
 
28 37
 ### Directly from source control
29 38
 

+ 1
- 1
dicegen View File

@@ -3,7 +3,7 @@
3 3
 ;; See: https://github.com/hyPiRion/inlein/wiki/Getting-Started
4 4
 
5 5
 '{:dependencies [[org.clojure/clojure "1.10.0"]
6
-                 [dicegen "0.1.1"]]}
6
+                 [dicegen "LATEST"]]}
7 7
 
8 8
 (require '[dicegen.core :as dg])
9 9
 

+ 7776
- 0
resources/eff.wordlist.txt
File diff suppressed because it is too large
View File


+ 39
- 22
src/dicegen/core.clj View File

@@ -22,43 +22,54 @@
22 22
 
23 23
 ;; # The library portion
24 24
 
25
-(defn diceware-line "Convert a diceware line into a key-value pair" [line]
25
+(def default-wordlist "diceware")
26
+
27
+(defn- dice-line "Convert a diceware line into a key-value pair" [line]
26 28
   (let [[key val] (str/split line #"\t")] {key val}))
27 29
 
28
-(def words
29
-  (as-> "diceware.wordlist.txt" x
30
+(defn- words [n]
31
+  (as-> (str n ".wordlist.txt") x
30 32
         (io/resource x)
31 33
         (io/make-input-stream x {})
32 34
         (slurp x)
33 35
         (str/split x #"\n")
34
-        (map diceware-line x)
36
+        (map dice-line x)
35 37
         (apply merge x)))
36 38
 
37 39
 (defn rolldn "Roll 1dn" [n] (-> n rand-int inc))
38 40
 
39 41
 (defn rollxdn "Roll xdn" [x n] (repeatedly x (partial rolldn n)))
40 42
 
41
-(defn random-diceware-address "Roll 5d6 and produce a string of the results" []
43
+(defn random-word-address "Roll 5d6 and produce a string of the results" []
42 44
   (str/join "" (rollxdn 5 6)))
43 45
 
44
-(defn random-diceware "An endless sequence of diceware words" []
45
-  (repeatedly (comp words random-diceware-address)))
46
+(defn random-words "An endless sequence of random words"
47
+  ([wordlist]
48
+   (repeatedly (comp (words wordlist) random-word-address)))
49
+  ([] (random-words default-wordlist)))
46 50
 
47
-(defn password "A password of word length `n`" [n]
48
-  (->> (random-diceware) (take n) (str/join " ")))
51
+(defn password "A password of word length `n`"
52
+  ([wordlist n]
53
+   (->> wordlist random-words (take n) (str/join " ")))
54
+  ([n] (password default-wordlist n)))
49 55
 
50
-(defn passwords "An endless sequence of passwords of word length `n`" [n]
51
-  (repeatedly (partial password n)))
56
+(defn passwords "An endless sequence of passwords of word length `n`"
57
+  ([wordlist n]
58
+   (repeatedly (partial password wordlist n)))
59
+  ([n] (passwords default-wordlist n)))
52 60
 
53 61
 ;; # The app portion
54 62
 
55 63
 (def usage [""
56 64
             "Usage:"
57 65
             "------"
58
-            "dicegen password-length [num-passwords]"
66
+            "dicegen password-length [num-passwords] [wordlist]"
59 67
             ""
60
-            "Where <password-length> is the number of words in each password"
61
-            "and <num-passwords> is the number of passwords to generate"])
68
+            "Where <password-length> is the number of words in each password,"
69
+            "<num-passwords> is the number of passwords to generate"
70
+            "which defaults to 10, and"
71
+            "<wordlist> is either 'diceware' or 'eff'"
72
+            (str "which defaults to " default-wordlist)])
62 73
 
63 74
 (defn printlns [lines] (->> lines (str/join "\n") println))
64 75
 
@@ -76,17 +87,17 @@
76 87
     (catch NumberFormatException _
77 88
       (error-exit (format "%s is not an integer: '%s'" desc i)))))
78 89
 
79
-(defn -main [& [length-str num-passwords-str]]
90
+(defn -main [& [length-str num-passwords-str wordlist]]
80 91
   (when (str/blank? length-str)
81 92
     (error-exit "Please specify a password-length"))
82 93
 
83 94
   (let [num-passwords
84 95
         (if num-passwords-str
85 96
           (require-positive-integer num-passwords-str "num-passwords")
86
-          1)]
97
+          10)]
87 98
     (-> length-str
88 99
         (require-positive-integer "password-length")
89
-        passwords
100
+        ((partial passwords (or wordlist default-wordlist)))
90 101
         ((partial take num-passwords))
91 102
         printlns)))
92 103
 
@@ -94,7 +105,7 @@
94 105
 
95 106
 (comment
96 107
 
97
-  (diceware-line "12345\tthing")
108
+  (dice-line "12345\tthing")
98 109
   ;=> {"12345" "thing"}
99 110
 
100 111
   (rolldn 8)
@@ -103,13 +114,19 @@
103 114
   (rollxdn 3 12)
104 115
   ;=> (10 9 1)
105 116
 
106
-  (take 5 (random-diceware))
117
+  (take 5 (random-words))
107 118
   ;=> ("secant" "cream" "insult" "hear" "kodak")
108 119
 
109
-  (password 5)
110
-  ;=> "amity preen barr jig tulip"
120
+  (take 5 (random-words "eff"))
121
+  ;=> ("till" "sprig" "backstab" "unclothed" "uncooked")
122
+
123
+  (password "eff" 5)
124
+  ;=> "abide query glitter whoopee landfill"
111 125
 
112 126
   (take 2 (passwords 5))
113
-  ;=> ("hoyt aloof engel oooo jp" "hay gina gull milch uw")
127
+  ;=> ("hive piece zs bogus bonus" "cure bask keel vivid fi")
128
+
129
+  (take 2 (passwords "eff" 5))
130
+  ;=> ("army lividly grading primarily pagan" "purist send poet unbolted jab")
114 131
 
115 132
   )