correct-horse-battery-staple 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data.tar.gz.sig +1 -1
  2. data/.gemtest +0 -0
  3. data/Gemfile +53 -0
  4. data/Gemfile.lock +109 -0
  5. data/History.txt +6 -0
  6. data/Manifest.txt +57 -0
  7. data/README.txt +115 -0
  8. data/Rakefile +47 -0
  9. data/bin/chbs +234 -0
  10. data/bin/chbs-mkpass +16 -0
  11. data/correct-horse-battery-staple.gemspec +59 -0
  12. data/lib/correct_horse_battery_staple.rb +117 -0
  13. data/lib/correct_horse_battery_staple/assembler.rb +45 -0
  14. data/lib/correct_horse_battery_staple/backend.rb +6 -0
  15. data/lib/correct_horse_battery_staple/backend/isam_kd.rb +410 -0
  16. data/lib/correct_horse_battery_staple/backend/redis.rb +95 -0
  17. data/lib/correct_horse_battery_staple/backend/redis/d_range.rb +105 -0
  18. data/lib/correct_horse_battery_staple/corpus.rb +33 -0
  19. data/lib/correct_horse_battery_staple/corpus/base.rb +278 -0
  20. data/lib/correct_horse_battery_staple/corpus/isam.rb +258 -0
  21. data/lib/correct_horse_battery_staple/corpus/isam_kd.rb +60 -0
  22. data/lib/correct_horse_battery_staple/corpus/redis.rb +188 -0
  23. data/lib/correct_horse_battery_staple/corpus/redis2.rb +88 -0
  24. data/lib/correct_horse_battery_staple/corpus/serialized.rb +121 -0
  25. data/lib/correct_horse_battery_staple/corpus/sqlite.rb +266 -0
  26. data/lib/correct_horse_battery_staple/generator.rb +40 -0
  27. data/lib/correct_horse_battery_staple/memoize.rb +25 -0
  28. data/lib/correct_horse_battery_staple/parser.rb +5 -0
  29. data/lib/correct_horse_battery_staple/parser/base.rb +5 -0
  30. data/lib/correct_horse_battery_staple/parser/regex.rb +58 -0
  31. data/lib/correct_horse_battery_staple/range_parser.rb +29 -0
  32. data/lib/correct_horse_battery_staple/statistical_array.rb +74 -0
  33. data/lib/correct_horse_battery_staple/stats.rb +22 -0
  34. data/lib/correct_horse_battery_staple/word.rb +90 -0
  35. data/lib/correct_horse_battery_staple/writer.rb +29 -0
  36. data/lib/correct_horse_battery_staple/writer/base.rb +22 -0
  37. data/lib/correct_horse_battery_staple/writer/csv.rb +15 -0
  38. data/lib/correct_horse_battery_staple/writer/file.rb +54 -0
  39. data/lib/correct_horse_battery_staple/writer/isam.rb +50 -0
  40. data/lib/correct_horse_battery_staple/writer/isam_kd.rb +12 -0
  41. data/lib/correct_horse_battery_staple/writer/json.rb +19 -0
  42. data/lib/correct_horse_battery_staple/writer/marshal.rb +10 -0
  43. data/lib/correct_horse_battery_staple/writer/redis.rb +41 -0
  44. data/lib/correct_horse_battery_staple/writer/sqlite.rb +115 -0
  45. data/script/generate_all +34 -0
  46. data/script/load_redis +17 -0
  47. data/script/perftest +74 -0
  48. data/spec/corpus/serialized_spec.rb +62 -0
  49. data/spec/corpus_spec.rb +50 -0
  50. data/spec/correct_horse_battery_staple_spec.rb +73 -0
  51. data/spec/fixtures/100.json +101 -0
  52. data/spec/fixtures/corpus1.csv +101 -0
  53. data/spec/fixtures/corpus100.json +101 -0
  54. data/spec/fixtures/wiktionary1000.htm +648 -0
  55. data/spec/range_parser_spec.rb +54 -0
  56. data/spec/spec_helper.rb +20 -0
  57. data/spec/statistical_array_spec.rb +52 -0
  58. data/spec/support/spec_pry.rb +1 -0
  59. data/spec/word_spec.rb +95 -0
  60. metadata +264 -0
  61. metadata.gz.sig +1 -0
@@ -0,0 +1,54 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+
3
+ describe CorrectHorseBatteryStaple::RangeParser do
4
+
5
+ let :parser do
6
+ CorrectHorseBatteryStaple::RangeParser.new
7
+ end
8
+
9
+ shared_examples_for "integer range" do
10
+ subject { parser.parse(range_string) }
11
+
12
+ it 'should return a range given valid endpoints' do
13
+ subject.should be_instance_of(Range)
14
+ end
15
+ it 'should equal the expected range' do
16
+ subject.should == expected_range
17
+ end
18
+ it 'should have integer endpoints' do
19
+ subject.begin.should be_instance_of(Integer)
20
+ subject.end. should be_instance_of(Integer)
21
+ end
22
+ end
23
+
24
+ dotted_ranges =
25
+ [[0..1, "0..1"],
26
+ [0..-1, "0..-1"],
27
+ [-10..3, "-10..3"],
28
+ [-10.0..2.0, "-10.0..2.0"]]
29
+
30
+ dashed_ranges =
31
+ dotted_ranges.map do |(range, string)|
32
+ [range, string.gsub(/\.\./, '-')]
33
+ end +
34
+ [[100..200, "100-200"],
35
+ [-5..-1, "-5--1"],
36
+ [5..-1, "5--1"],
37
+ [1.0..3, "1.-3"]]
38
+
39
+ scalar_ranges =
40
+ [[-10..-10, "-10"],
41
+ [0..0, "0"],
42
+ [0.5..0.5, ".5"],
43
+ [-2..-2, "-2"],
44
+ [-0.2..-0.2, "-.2"]]
45
+
46
+ (dotted_ranges + dashed_ranges + scalar_ranges).each do |(range, string)|
47
+ it "should parse '#{string}' into [#{range}]" do
48
+ parser.parse(string).should == range
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ # -*- mode: Ruby -*-
@@ -0,0 +1,20 @@
1
+ unless Object.const_defined?("FIXTURES_DIR")
2
+
3
+ GEM_DIR = File.expand_path(File.join(File.dirname(__FILE__), ".."))
4
+ LIB_DIR = File.join(GEM_DIR, "lib")
5
+ BIN_DIR = File.join(GEM_DIR, "bin")
6
+
7
+ SPEC_DIR = File.join(GEM_DIR, "spec")
8
+ FIXTURES_DIR = File.join(SPEC_DIR, "fixtures")
9
+
10
+ $:.unshift LIB_DIR
11
+
12
+ require 'bundler'
13
+ Bundler.setup
14
+
15
+ require 'rspec'
16
+
17
+ Dir[File.join(File.dirname(__FILE__),'support','**','*.rb')].each { |f| require File.expand_path(f) }
18
+
19
+ require 'correct_horse_battery_staple'
20
+ end
@@ -0,0 +1,52 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+
3
+ describe CorrectHorseBatteryStaple::StatisticalArray do
4
+
5
+ context 'construction' do
6
+
7
+ let :base_array do
8
+ [1,3,3,5,7,9,10,12,12,12,18,30,40,45,50,60]
9
+ end
10
+ subject { CorrectHorseBatteryStaple::StatisticalArray.new base_array }
11
+
12
+ context 'basic functions' do
13
+ it "should be the correct size" do
14
+ subject.length.should == 16
15
+ end
16
+
17
+ it "should calculate mean" do
18
+ sprintf("%.4f", subject.mean).should == "19.8125"
19
+ # subject.mean.should =~ 5.42857142857143
20
+ end
21
+
22
+ it "should calculate stddev" do
23
+ sprintf("%.4f", subject.standard_deviation).should == "18.9287"
24
+ end
25
+ end
26
+
27
+ context 'percentiles to index' do
28
+ it "should calculate an index by for a percentile" do
29
+ subject.percentile_index(50).should == 9
30
+ end
31
+ end
32
+
33
+ context 'elements for a percentile range' do
34
+ it "when given a range" do
35
+ subject.select_percentile(50..70).should == [12, 12, 18, 30, 40]
36
+ end
37
+
38
+ it "when given a single number" do
39
+ subject.select_percentile(40).should == [10, 12]
40
+ end
41
+
42
+ it "at the low end" do
43
+ subject.select_percentile(0..10).should == [1, 3, 3, 5]
44
+ end
45
+ end
46
+
47
+
48
+ end
49
+
50
+ end
51
+
52
+
@@ -0,0 +1 @@
1
+ require 'pry'
@@ -0,0 +1,95 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+
3
+ require 'json'
4
+
5
+ describe CorrectHorseBatteryStaple::Word do
6
+
7
+ let :options do
8
+ {:word => "someword", :frequency => 132134, :rank => 11}
9
+ end
10
+
11
+ let :word do
12
+ CorrectHorseBatteryStaple::Word.new(options)
13
+ end
14
+
15
+ context "creation from hash" do
16
+ it "should successfully create from options" do
17
+ word.should be_instance_of(CorrectHorseBatteryStaple::Word)
18
+ end
19
+
20
+ it "should contain the correct word" do
21
+ word.word.should == "someword"
22
+ end
23
+
24
+ it "should contain the correct frequency" do
25
+ word.frequency.should == 132134
26
+ end
27
+
28
+ it "should contain the correct rank" do
29
+ word.rank.should == 11
30
+ end
31
+
32
+ it "should fail when given an options hash without a word" do
33
+ expect { CorrectHorseBatteryStaple::Word.new({}) }.
34
+ to raise_error
35
+ end
36
+ end
37
+
38
+ context "access to member" do
39
+ it "should allow access via .ATTR accessor" do
40
+ word.word.should == "someword"
41
+ end
42
+
43
+ it "should allow access via [:ATTR] accessor" do
44
+ word[:word].should == "someword"
45
+ end
46
+
47
+ it 'should allow access via ["ATTR"] accessor' do
48
+ word["word"].should == "someword"
49
+ end
50
+ end
51
+
52
+ context "setting member" do
53
+ it "should allow setting via .ATTR accessor" do
54
+ word.word = "newword"
55
+ word.word.should == "newword"
56
+ end
57
+
58
+ it "should allow access via [:ATTR] accessor" do
59
+ word[:word] = "newword"
60
+ word.word.should == "newword"
61
+ end
62
+
63
+ it 'should allow access via ["ATTR"] accessor' do
64
+ word["word"] = "newword"
65
+ word.word.should == "newword"
66
+ end
67
+ end
68
+
69
+ context "conversions" do
70
+ context "to hash" do
71
+ subject { word.to_hash }
72
+
73
+ it "should contain the key elements" do
74
+ subject.should have_key("word")
75
+ end
76
+
77
+ it "should not contain unset elements" do
78
+ subject.should_not have_key("probability")
79
+ end
80
+ end
81
+
82
+ context "to JSON" do
83
+ subject { word.to_json }
84
+
85
+ it "should be properly formatted JSON" do
86
+ expect { JSON.parse(subject) }.
87
+ not_to raise_error
88
+ JSON.parse(subject) == word.to_hash
89
+ end
90
+
91
+ end
92
+ end
93
+ end
94
+
95
+ # -*- mode: Ruby -*-
metadata ADDED
@@ -0,0 +1,264 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: correct-horse-battery-staple
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Robert Sanders
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain:
12
+ - ! '-----BEGIN CERTIFICATE-----
13
+
14
+ MIIDPDCCAiSgAwIBAgIBADANBgkqhkiG9w0BAQUFADBEMQ8wDQYDVQQDDAZyb2Jl
15
+
16
+ cnQxHDAaBgoJkiaJk/IsZAEZFgxjdXJpb3Vzc3F1aWQxEzARBgoJkiaJk/IsZAEZ
17
+
18
+ FgNjb20wHhcNMTExMjI5MDc1MTI1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oWBMAymS
47
+
48
+ xy9Wmvt4T+8mZiV7EFgWig==
49
+
50
+ -----END CERTIFICATE-----
51
+
52
+ '
53
+ date: 2012-01-10 00:00:00.000000000 Z
54
+ dependencies:
55
+ - !ruby/object:Gem::Dependency
56
+ name: commander
57
+ requirement: &70120278529620 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '4.0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: *70120278529620
66
+ - !ruby/object:Gem::Dependency
67
+ name: fastercsv
68
+ requirement: &70120278528480 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: 1.5.3
74
+ type: :runtime
75
+ prerelease: false
76
+ version_requirements: *70120278528480
77
+ - !ruby/object:Gem::Dependency
78
+ name: json
79
+ requirement: &70120278527600 !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: 1.6.0
85
+ type: :runtime
86
+ prerelease: false
87
+ version_requirements: *70120278527600
88
+ - !ruby/object:Gem::Dependency
89
+ name: redis
90
+ requirement: &70120278526800 !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: 2.2.2
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: *70120278526800
99
+ - !ruby/object:Gem::Dependency
100
+ name: hiredis
101
+ requirement: &70120278526320 !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: 0.4.0
107
+ type: :runtime
108
+ prerelease: false
109
+ version_requirements: *70120278526320
110
+ - !ruby/object:Gem::Dependency
111
+ name: tupalo-kdtree
112
+ requirement: &70120278525800 !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: 0.2.3
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: *70120278525800
121
+ - !ruby/object:Gem::Dependency
122
+ name: sqlite3
123
+ requirement: &70120278525380 !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: 1.3.0
129
+ type: :runtime
130
+ prerelease: false
131
+ version_requirements: *70120278525380
132
+ - !ruby/object:Gem::Dependency
133
+ name: rubyforge
134
+ requirement: &70120278524940 !ruby/object:Gem::Requirement
135
+ none: false
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: 2.0.4
140
+ type: :development
141
+ prerelease: false
142
+ version_requirements: *70120278524940
143
+ - !ruby/object:Gem::Dependency
144
+ name: hoe
145
+ requirement: &70120278524500 !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ~>
149
+ - !ruby/object:Gem::Version
150
+ version: '2.12'
151
+ type: :development
152
+ prerelease: false
153
+ version_requirements: *70120278524500
154
+ description: ! "Generate a 4 word password from words of size 3-8 characters, with\nfrequencies
155
+ in the 30th-60th percentile. This range gives a nice set\nof uncommon but not completely
156
+ alien words.\n\n $ chbs generate --verbose -W 3..8 -P 30..60\n Corpus size:
157
+ 6396 candidate words of 33075 total\n Entropy: 48 bits (2^48 = 281474976710656)\n
158
+ \ Years to guess at 1000 guesses/sec: 8926\n magnate-thermal-sandbank-augur\n\nWith
159
+ the --verbose flag, the utility will calculate a time-to-guess\nbased on a completely
160
+ arbitrary 1000 guesses/sec. If you'd like a\nmore secure password, either relax
161
+ the various filtering rules (-W and\n-P), add more words to the password, or use
162
+ a larger corpus.\n\nBy default we use the American TV Shows & Scripts corpus taken
163
+ from\nWiktionary.\n\nOthers provided:\n\n* Project Gutenberg 2005 corpus taken from
164
+ Wiktionary.\n* 1 of every 7 of the top 60000 lemmas from wordfrequency.info (6900\n
165
+ \ actual lemmas after processing)\n\nSee http://xkcd.com/936/ for the genesis of
166
+ the idea.\n\nData sources:\n\n http://en.wiktionary.org/wiki/Wiktionary:Frequency_lists\n
167
+ \ http://wordfrequency.info/"
168
+ email:
169
+ - robert@curioussquid.com
170
+ executables:
171
+ - chbs
172
+ - chbs-mkpass
173
+ extensions: []
174
+ extra_rdoc_files:
175
+ - History.txt
176
+ - Manifest.txt
177
+ - README.txt
178
+ files:
179
+ - Gemfile
180
+ - Gemfile.lock
181
+ - History.txt
182
+ - Manifest.txt
183
+ - README.txt
184
+ - Rakefile
185
+ - bin/chbs
186
+ - bin/chbs-mkpass
187
+ - lib/correct_horse_battery_staple.rb
188
+ - lib/correct_horse_battery_staple/assembler.rb
189
+ - lib/correct_horse_battery_staple/backend.rb
190
+ - lib/correct_horse_battery_staple/backend/isam_kd.rb
191
+ - lib/correct_horse_battery_staple/backend/redis.rb
192
+ - lib/correct_horse_battery_staple/backend/redis/d_range.rb
193
+ - lib/correct_horse_battery_staple/corpus.rb
194
+ - lib/correct_horse_battery_staple/corpus/base.rb
195
+ - lib/correct_horse_battery_staple/corpus/isam.rb
196
+ - lib/correct_horse_battery_staple/corpus/isam_kd.rb
197
+ - lib/correct_horse_battery_staple/corpus/redis.rb
198
+ - lib/correct_horse_battery_staple/corpus/redis2.rb
199
+ - lib/correct_horse_battery_staple/corpus/serialized.rb
200
+ - lib/correct_horse_battery_staple/corpus/sqlite.rb
201
+ - lib/correct_horse_battery_staple/generator.rb
202
+ - lib/correct_horse_battery_staple/memoize.rb
203
+ - lib/correct_horse_battery_staple/parser.rb
204
+ - lib/correct_horse_battery_staple/parser/base.rb
205
+ - lib/correct_horse_battery_staple/parser/regex.rb
206
+ - lib/correct_horse_battery_staple/range_parser.rb
207
+ - lib/correct_horse_battery_staple/statistical_array.rb
208
+ - lib/correct_horse_battery_staple/stats.rb
209
+ - lib/correct_horse_battery_staple/word.rb
210
+ - lib/correct_horse_battery_staple/writer.rb
211
+ - lib/correct_horse_battery_staple/writer/base.rb
212
+ - lib/correct_horse_battery_staple/writer/csv.rb
213
+ - lib/correct_horse_battery_staple/writer/file.rb
214
+ - lib/correct_horse_battery_staple/writer/isam.rb
215
+ - lib/correct_horse_battery_staple/writer/isam_kd.rb
216
+ - lib/correct_horse_battery_staple/writer/json.rb
217
+ - lib/correct_horse_battery_staple/writer/marshal.rb
218
+ - lib/correct_horse_battery_staple/writer/redis.rb
219
+ - lib/correct_horse_battery_staple/writer/sqlite.rb
220
+ - script/generate_all
221
+ - script/load_redis
222
+ - script/perftest
223
+ - spec/corpus/serialized_spec.rb
224
+ - spec/corpus_spec.rb
225
+ - spec/correct_horse_battery_staple_spec.rb
226
+ - spec/fixtures/100.json
227
+ - spec/fixtures/corpus1.csv
228
+ - spec/fixtures/corpus100.json
229
+ - spec/fixtures/wiktionary1000.htm
230
+ - spec/range_parser_spec.rb
231
+ - spec/spec_helper.rb
232
+ - spec/statistical_array_spec.rb
233
+ - spec/support/spec_pry.rb
234
+ - spec/word_spec.rb
235
+ - correct-horse-battery-staple.gemspec
236
+ - .gemtest
237
+ homepage: http://github.com/rsanders/correct-horse-battery-staple
238
+ licenses: []
239
+ post_install_message:
240
+ rdoc_options:
241
+ - --main
242
+ - README.txt
243
+ require_paths:
244
+ - lib
245
+ required_ruby_version: !ruby/object:Gem::Requirement
246
+ none: false
247
+ requirements:
248
+ - - ! '>='
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ required_rubygems_version: !ruby/object:Gem::Requirement
252
+ none: false
253
+ requirements:
254
+ - - ! '>='
255
+ - !ruby/object:Gem::Version
256
+ version: '0'
257
+ requirements: []
258
+ rubyforge_project: correct-horse-battery-staple
259
+ rubygems_version: 1.8.10
260
+ signing_key:
261
+ specification_version: 3
262
+ summary: Generate a 4 word password from words of size 3-8 characters, with frequencies
263
+ in the 30th-60th percentile
264
+ test_files: []