phoenix_password 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b67209defe960aa06e2dd8ef0e3b539fa33589b0
4
- data.tar.gz: 2b1197738e6ceafed97e289ba324ed2886ba5d69
3
+ metadata.gz: 7429ba7459dcd2b4b309516ad63da99f76d3d296
4
+ data.tar.gz: c92da9f74996bb727193d87ba8c3733f2cb07f5f
5
5
  SHA512:
6
- metadata.gz: 2311c6f8615fef5d89f446badc2425a7fa6eec519fc61982fdc408fe93d28874e838cdd9331df518d0965bc2c6c4fcbddd7105db77088d4473180f072845a20c
7
- data.tar.gz: 731a165b18de335834021a0aef6e7a60d2eedafc84414cf3b78d4189c375c1fd3e8dec66d5779759b1fdaf8e37140860776e22f2be88a9ecbaa432f66f89bb44
6
+ metadata.gz: 3c766082ad076343dad9b382e798dc38313360b41a097c01dca8b8c743cd548d9fc2a58e5acc16cbaf6288863e76da977500d311c735d9c3424c6ecc10b8abb9
7
+ data.tar.gz: 9bcd73a84b9327bd71f8025a22e3293bb1869bf915f0b6ce3d5aeb311be9d38536fd853d9868fd7c6488b52e66dd73a9e551e8c77fd143c262d749866a9c0fde
data/README.md CHANGED
@@ -43,7 +43,7 @@ This is a list of the options available to you and what they do
43
43
  obj_a=PhoenixPassword.new()
44
44
  obj_b=PhoenixPassword.new({:rules=>true})
45
45
  obj_c=PhoenixPassword.new({:rules=>true,:stricness=>2})
46
- obj_d=PhoenixPassword.new({:rules=>true,:stricness=>2,:own_rules=>[/regexp_a/,regexp_b]})
46
+ obj_d=PhoenixPassword.new({:rules=>true,:stricness=>2,:own_rules=>[/regexp_a/,/regexp_b/]})
47
47
  ```
48
48
 
49
49
  You can initialize a PhoenixPassword object in 4 different ways.
@@ -91,7 +91,7 @@ Filters combinations that have only letters AAAAAA
91
91
  **d)own_rules**
92
92
 
93
93
  ```ruby
94
- obj_d=PhoenixPassword.new({:rules=>true,:stricness=>2,:own_rules=>[/regexp_a/,regexp_b]})
94
+ obj_d=PhoenixPassword.new({:rules=>true,:stricness=>2,:own_rules=>[/regexp_a/,/regexp_b/]})
95
95
  ```
96
96
 
97
97
  If you want to use your own combination filtering rules you must use the own_rules key and add an array with Regexp objects.
@@ -99,6 +99,94 @@ If you want to use your own combination filtering rules you must use the own_rul
99
99
  The rules that you will add will be implemented after all the rules that are used by the strictness level have been checked.Make sure when using your rules that you don't filter twice things that have been already checked.
100
100
 
101
101
  ==================================================================================================
102
+
103
+ **Checkpoint and Restore**
104
+
105
+ In order to be able to use the checkpoint functionality it is required that you have mysql
106
+ database and mysql2 gem installed.
107
+
108
+ If don't want to change the settings that are provided by default, you will have to do the following steps in you database:
109
+
110
+ a)Create a database called phoenix_password
111
+
112
+ create database phoenix_password
113
+
114
+ b)Grant all privileges on that database to a user named phoenix,with the password Gordian100!
115
+
116
+ grant all privileges on phoenix_password.* to 'phoenix'@'localhost' identified by 'Gordian100!';
117
+
118
+ c)Create a checkpoint table in the phoenix_password database as follows
119
+
120
+ create table checkpoint ( id int not null auto_increment primary key,combination varchar(200) not null,chars_used varchar(255) not null,i bigint unsigned not null);
121
+
122
+ You can customize the settings if you want but you must change the phoenix_password.rb file accordingly.
123
+
124
+
125
+ **Checkpoint**
126
+
127
+ ```ruby
128
+ PhoenixPassword.new({:checkpoint=>true,:check_fraction=>2,:check_cmb=>7})
129
+ ```
130
+ check_cmb:
131
+
132
+ Is to be used when you want to set a checkpoint in a specific combination length when generating multiple length combinations.
133
+ Example:
134
+
135
+
136
+ ```ruby
137
+ PhoenixPassword.new(:checkpoint=>true,:check_cmb=>7,:check_fraction=>4).combinations({:piped=>false,:type=>'matching',
138
+ :characters=>[0,1,2,3,4,5,6,7,8,9],:cmb_length=>[6,7,8]})
139
+ ```
140
+
141
+ check_fraction:
142
+
143
+ Is optional if not set it's by default set to 2 meaning 1/2 of the total combinations.You can set it to a greater value if you want to create checkpoint sooner, a vale of 4 will mean that when about 1/4 of the total combinations is tested a checkpoint is set and the program exits.I recommend that you use even numbers as a check_fraction value.
144
+
145
+ If you are dealing with an odd number of total combinations say 11^6=1771561 using the 2 fraction will result in you having to do three iterations of the program before you get the full amount of combinations:
146
+
147
+ 1)1771561/2=885780,5 rounded to_i 885780 = %49.99
148
+
149
+ 2)1771561/2=885780,5 rounded to_i 885780 = %49.99
150
+
151
+ 3)1771561-1771560=1 1/1771561 = %0.000000564
152
+
153
+ **Restore**
154
+
155
+ ```ruby
156
+ PhoenixPassword.new(:restore=>true,:restore_cmb=>7)
157
+
158
+ PhoenixPassword.new(:restore=>true,:restore_cmb=>7,:checkpoint=>true,:check_cmb=>7,:check_fraction=>4)
159
+ ```
160
+
161
+ In order to restore you must use the same file name as when the checkpoint was set,since the new combinations will be appended to it.
162
+
163
+ restore_cmb:
164
+
165
+ Is to be used when restoring from a multiple combination process.In the previous example in order to do a proper restore you must set restore_cmb=>7 as that will discard all of the 6 length combinations.
166
+
167
+ You can use restore and checkpoint at the same time resulting in resuming from where you left off and creating a new checkpoint when the check_fraction is met here is an example:
168
+
169
+ ```ruby
170
+ PhoenixPassword.new(:checkpoint=>true,:check_cmb=>7,:check_fraction=>4)
171
+
172
+ PhoenixPassword.new(:restore=>true,:checkpoint=>true,:check_fraction=>4)
173
+ ```
174
+
175
+ When operation has finished you should have about 2/4 of the total combinations.
176
+
177
+ You can restore and set checkpoint in a multi combination as well.
178
+
179
+ ```ruby
180
+ PhoenixPassword.new(:checkpoint=>true,:check_cmb=>7,:check_fraction=>4)
181
+
182
+ PhoenixPassword.new(:restore=>true,:restore_cmb=>7,:checkpoint=>true,:check_cmb=>7,:check_fraction=>4)
183
+ ```
184
+
185
+ If you continue to restore you will be notified when all the combinations have been generated and how to change to the next combination length.
186
+
187
+ ==================================================================================================
188
+
189
+
102
190
  ```ruby
103
191
  :piped=>(true or false)
104
192
  ```
data/lib/file_size.rb ADDED
@@ -0,0 +1,511 @@
1
+ module FileSize
2
+
3
+
4
+ def get_size(data)
5
+ bytes=data[:combinations]*(data[:cmb_length]+1)
6
+ kilo_bytes=bytes/1000.0
7
+ mega_bytes=kilo_bytes/1000.0
8
+ giga_bytes=mega_bytes/1000.0
9
+ tera_bytes=giga_bytes/1000.0
10
+ peta_bytes=tera_bytes/1000.0
11
+ all_sizes= {:bytes=>bytes,:kilo=>kilo_bytes,:mega=>mega_bytes,:giga=>giga_bytes,:tera=>tera_bytes,:peta=>peta_bytes}
12
+ return_sizes= {}
13
+ all_sizes.each do |key,value|
14
+ if kilo_bytes < 1
15
+ return_sizes[key]=value
16
+ break
17
+ end
18
+ return_sizes[key]=value if value > 0.01 && key != :bytes
19
+ end
20
+ yield(return_sizes) if block_given?
21
+ return return_sizes
22
+ end
23
+
24
+ def cap_limit_matching(data)
25
+ cap_data={}
26
+ total_chars=data[:characters].join()
27
+ caps_matched= total_chars.scan(/[A-Z]/)
28
+ cap_data[:characters]=[]
29
+ data[:characters].each do |char|
30
+ next if caps_matched.include?(char)
31
+ cap_data[:characters].push(char)
32
+ end
33
+ base=cap_data[:characters].length
34
+ cap_matches=0
35
+ case data[:cmb_length]
36
+ when 3
37
+ cap_matches += base*2
38
+ when 4
39
+ cap_matches+=get_combinations({:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-1})*2
40
+ cap_matches+=(base**2)*2
41
+ else
42
+ cap_matches+=get_combinations({:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-1})*2
43
+ cap_matches+=(get_combinations({:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-2})*base)*(data[:cmb_length]-2)
44
+ end
45
+
46
+ if !data[:extra_chars].nil?
47
+ all_chars=data[:characters]+data[:extra_chars]
48
+ new_cap_matches=cap_limit_matching({:cmb_length=>data[:cmb_length],:characters=>all_chars})
49
+ return new_cap_matches-(cap_matches*caps_matched.length)
50
+ else
51
+ return cap_matches*caps_matched.length
52
+ end
53
+
54
+ end
55
+
56
+ def cap_limit_matching_l(data)
57
+ cap_data={}
58
+ total_chars=data[:characters].join()
59
+ caps_matched= total_chars.scan(/[A-Z]/)
60
+ cap_data[:characters]=[]
61
+ data[:characters].each do |char|
62
+ next if caps_matched.include?(char)
63
+ cap_data[:characters].push(char)
64
+ end
65
+ base=cap_data[:characters].length
66
+ cap_matches=0
67
+ no_limit_matches=get_combinations({:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-1})
68
+ case data[:cmb_length]
69
+ when 3
70
+ cap_matches += base*2
71
+ when 4
72
+ cap_matches+=(no_limit_matches-get_above_limit({:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-1,:match_limit=>data[:match_limit]}))*2
73
+ cap_matches+=(base**2)*2
74
+ else
75
+
76
+ #XXA
77
+ cap_matches+=(no_limit_matches-get_above_limit({:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-1,:match_limit=>data[:match_limit]}))*2
78
+ no_limit_matches=get_combinations({:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-2})
79
+ #XAX
80
+ cap_matches+=((no_limit_matches-get_above_limit({:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-2,:match_limit=>data[:match_limit]}))*base)*2
81
+ x=data[:cmb_length]-4
82
+ if x == 1
83
+ cap_matches +=get_combinations({:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-2})*base
84
+ elsif x == 2
85
+ grt_half_no_limit=get_combinations({:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-3})
86
+ grt_half_limit =grt_half_no_limit-get_above_limit({:characters=>cap_data[:characters],:match_limit=>data[:match_limit],:cmb_length=>data[:cmb_length]-3})
87
+ cap_matches +=(((grt_half_limit*base**2)+(base*base**3))-(grt_half_no_limit*base))*2
88
+ else
89
+ #AXX
90
+ i=3
91
+ p=0
92
+ l=0
93
+ begin
94
+ grt_half=get_combinations({:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-(3+l)})
95
+ grt_half_limit =grt_half-get_above_limit({:characters=>cap_data[:characters],:match_limit=>data[:match_limit],:cmb_length=>data[:cmb_length]-(3+l)})
96
+ if i == 3
97
+ if data[:cmb_length] <=8
98
+ cap_matches +=(((grt_half_limit*base**2)+(base*base**(x+1)))-(grt_half*base))*2
99
+ else
100
+ cap_matches +=((grt_half_limit*((base**2)-base))+(base*base**(x+1)))*2
101
+
102
+ end
103
+ else
104
+ lsr_half=get_combinations({:characters=>cap_data[:characters],:cmb_length=>i-1})
105
+ lsr_half_limit=lsr_half-get_above_limit(:characters=>cap_data[:characters],:match_limit=>data[:match_limit],:cmb_length=>i-1)
106
+ cap_matches +=(((grt_half_limit*(base**(2+p)))+(lsr_half_limit*base**(x+1-p)))-(grt_half*lsr_half))*2
107
+
108
+ end
109
+ p+=1
110
+ l+=1
111
+ i+=1
112
+ end while i < (data[:cmb_length]/2.0).ceil
113
+
114
+
115
+
116
+ if x%2 == 1
117
+ no_limit_matches=get_combinations({:characters=>cap_data[:characters],:cmb_length=>x-(p-1)})
118
+ half_point=(((no_limit_matches-get_above_limit({:characters=>cap_data[:characters],:cmb_length=>x-(p-1),:match_limit=>data[:match_limit]})))*base**(x-(p-1)))*2
119
+ if data[:cmb_length] == 7
120
+ cap_matches+=half_point-((half_point/base))
121
+ else
122
+ half_no_limit=get_combinations(:characters=>cap_data[:characters],:cmb_length=>x-1)
123
+ half_no_limit_b=get_combinations(:characters=>cap_data[:characters],:cmb_length=>x-2)
124
+
125
+ if data[:cmb_length] >= 9 && data[:extra_chars].nil?
126
+ puts "!------Approximately less than------!"
127
+ end
128
+ cap_matches+=half_point-((half_point/base))
129
+
130
+ end
131
+
132
+ else
133
+ no_limit_matches_a=get_combinations({:characters=>cap_data[:characters],:cmb_length=>(x-l)+1})
134
+ greater_half=(((no_limit_matches_a-get_above_limit({:characters=>cap_data[:characters],:cmb_length=>(x-l)+1,:match_limit=>data[:match_limit]})))*base**(x-l))
135
+ no_limit_matches_b=get_combinations({:characters=>cap_data[:characters],:cmb_length=>(x-l)})
136
+ lesser_half=(((no_limit_matches_b-get_above_limit({:characters=>cap_data[:characters],:cmb_length=>(x-l),:match_limit=>data[:match_limit]})))*base**(x-l+1))
137
+
138
+ if data[:cmb_length] == 10 && data[:extra_chars].nil?
139
+ puts "!------Approximately less than------!"
140
+ elsif data[:cmb_length] == 12 && data[:extra_chars].nil?
141
+ puts "!------Approximately more than------!"
142
+ end
143
+ cap_matches+=((greater_half+lesser_half)-((no_limit_matches_a*no_limit_matches_b)-(no_limit_matches_b*base)))*2
144
+ end
145
+
146
+ end
147
+
148
+ end
149
+
150
+ if (cap_data[:characters].length <= 2 || data[:cmb_length] >= 13) && data[:extra_chars].nil?
151
+ puts "!!!----Inaccurate information----!!!"
152
+ end
153
+
154
+ if !data[:extra_chars].nil?
155
+ all_chars=data[:characters]+data[:extra_chars]
156
+ new_cap_matches=cap_limit_matching_l({:cmb_length=>data[:cmb_length],:characters=>all_chars,:match_limit=>data[:match_limit]})
157
+ return new_cap_matches-(cap_matches*caps_matched.length)
158
+ else
159
+ return cap_matches*caps_matched.length
160
+ end
161
+ end
162
+
163
+ def unique_cap_limit(data)
164
+ cap_data={}
165
+ total_chars=data[:characters].join()
166
+ caps_matched= total_chars.scan(/[A-Z]/)
167
+ cap_data[:characters]=[]
168
+ data[:characters].each do |char|
169
+ next if caps_matched.include?(char)
170
+ cap_data[:characters].push(char)
171
+ end
172
+ base=cap_data[:characters].length
173
+ unique_cap_limit=0
174
+ if data[:uniqueness_type] == 'single'
175
+ if data[:cmb_length] == 3
176
+ unique_cap_limit=(((base**2)-(base))*3)
177
+ else
178
+ previous_single=get_single_combs(:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-1,:type=>"unique")
179
+ unique_cap_limit=previous_single*data[:cmb_length]
180
+ end
181
+ else
182
+ case data[:cmb_length]
183
+ when 3
184
+ if data[:uniqueness_type].nil?
185
+ unique_cap_limit=((base**2)*3)-(base*2)
186
+ else
187
+ unique_cap_limit=((base**2)*3)-(base*2)-(((base**2)-(base))*3)
188
+ end
189
+ when 4
190
+ previous_unique=get_combinations(:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-1,:type=>"unique")
191
+ if data[:uniqueness_type].nil?
192
+ unique_cap_limit=(previous_unique*2)+((((base**2)-base)*base)*2)
193
+ else
194
+ previous_single=get_single_combs(:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-1,:type=>"unique")
195
+ unique_cap_limit=(previous_unique*2)+((((base**2)-base)*base)*2)-(previous_single*data[:cmb_length])
196
+ end
197
+ else
198
+ previous_unique_a=get_combinations(:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-1,:type=>"unique")
199
+ previous_unique_b=get_combinations(:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-2,:type=>"unique")
200
+ if data[:uniqueness_type].nil?
201
+ unique_cap_limit=(previous_unique_a*2)+((previous_unique_b*base)*(data[:cmb_length]-2))
202
+ else
203
+ previous_single=get_single_combs(:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-1,:type=>"unique")
204
+ unique_cap_limit=(previous_unique_a*2)+((previous_unique_b*base)*(data[:cmb_length]-2))-(previous_single*data[:cmb_length])
205
+ end
206
+ end
207
+ end
208
+
209
+ if !data[:extra_chars].nil?
210
+ all_chars=data[:characters]+data[:extra_chars]
211
+ new_unique_cap_limit=unique_cap_limit({:cmb_length=>data[:cmb_length],:characters=>all_chars,:uniqueness_type=>data[:uniqueness_type]})
212
+ return new_unique_cap_limit-(unique_cap_limit*caps_matched.length)
213
+ else
214
+ return unique_cap_limit*caps_matched.length
215
+ end
216
+ end
217
+
218
+ def cap_limit_combs(data,x=0)
219
+ if data[:type] == "matching"
220
+ if !data[:match_limit].nil?
221
+ puts "Combinations and file size may vary when using match_limit" if x == 0
222
+ cap_limit_matching_l(data)
223
+ else
224
+ cap_limit_matching(data)
225
+ end
226
+ else
227
+ unique_cap_limit(data)
228
+ end
229
+ end
230
+
231
+ def get_above_limit(data)
232
+ if data[:extra_chars].nil?
233
+ base=data[:characters].length
234
+ else
235
+ old_base=data[:characters].length
236
+ previous_matches=0
237
+ previous_mult=0
238
+ i=0
239
+ while i < (data[:cmb_length] -1)
240
+ if i == (data[:match_limit]-1)
241
+ previous_matches=old_base
242
+ old_matches=previous_matches
243
+ elsif i == data[:match_limit]
244
+ previous_matches=previous_matches+(1*(old_base-1))
245
+ previous_mult=1
246
+ else
247
+ temp_mult=previous_matches
248
+ previous_matches=(old_base**(i-1)+previous_mult*(old_base-1))+(previous_matches*(old_base-1))
249
+ previous_mult=temp_mult
250
+ end
251
+
252
+ i+=1
253
+ end
254
+
255
+ old_matches=old_base*previous_matches if data[:cmb_length] != (data[:match_limit]+1)
256
+ base=data[:characters].length+data[:extra_chars].length
257
+ end
258
+
259
+ previous_matches=0
260
+ previous_mult=0
261
+ i=1
262
+ while i < (data[:cmb_length] -1)
263
+ if i == (data[:match_limit]-1)
264
+ previous_matches=base
265
+ return previous_matches if data[:cmb_length] == (data[:match_limit]+i) && data[:extra_chars].nil?
266
+ elsif i == data[:match_limit]
267
+ previous_matches=previous_matches+(1*(base-1))
268
+ previous_mult=1
269
+ else
270
+ temp_mult=previous_matches
271
+ previous_matches=(base**(i-1))+(previous_mult*(base-1))+(previous_matches*(base-1))
272
+ previous_mult=temp_mult
273
+
274
+ end
275
+ i+=1
276
+ end
277
+
278
+ unless data[:extra_chars].nil?
279
+ return base-old_base if data[:cmb_length] == (data[:match_limit]+1)
280
+ return (base*previous_matches)-old_matches
281
+ else
282
+ return base*previous_matches
283
+ end
284
+ end
285
+
286
+ def get_single_combs(data)
287
+ i=0
288
+ single_combinations=0
289
+ extra_singe=0
290
+ extra_chars=data[:characters].length+data[:extra_chars].length if !data[:extra_chars].nil?
291
+ while i < data[:cmb_length]-1
292
+ if i == 0
293
+ single_combinations=(data[:characters].length-1)*data[:characters].length
294
+ extra_singe=extra_chars*(extra_chars-1) if !extra_chars.nil?
295
+ else
296
+ single_combinations=single_combinations*(data[:characters].length-(i+1))
297
+ extra_singe=extra_singe*(extra_chars-(i+1)) if !extra_chars.nil?
298
+ end
299
+ i+=1
300
+ end
301
+ return extra_singe - single_combinations if !data[:extra_chars].nil?
302
+ return single_combinations
303
+ end
304
+
305
+ def get_combinations(data)
306
+ if data[:extra_chars].nil?
307
+ base=data[:characters].length
308
+ else
309
+ old_base=data[:characters].length
310
+ old_combinations=old_base**data[:cmb_length]
311
+ x=0
312
+ post_matches=0
313
+ while x < data[:cmb_length]-1
314
+ if x == 0
315
+ post_matches=old_base
316
+ elsif x == 1
317
+ post_matches=(old_base**x)+(1*(old_base-1))
318
+ else
319
+ post_matches=(old_base**x)+(post_matches*(old_base-1))
320
+ end
321
+ x+=1
322
+ end
323
+ old_matches=old_base*post_matches
324
+ base=data[:characters].length+data[:extra_chars].length
325
+ end
326
+ previous_matches=0
327
+ i=0
328
+
329
+ while i < data[:cmb_length]-1
330
+ if i==0
331
+ previous_matches=base
332
+ elsif i== 1
333
+ previous_matches=(base**i)+(1*(base-1))
334
+ else
335
+ previous_matches=(base**i)+(previous_matches*(base-1))
336
+ end
337
+ i+=1
338
+ end
339
+ matches=base*previous_matches
340
+
341
+ if data[:type]=='unique'
342
+ possible_combinations=base**data[:cmb_length]
343
+ if data[:uniqueness_type].nil?
344
+ return (possible_combinations-matches)-(old_combinations-old_matches) if !data[:extra_chars].nil?
345
+ return possible_combinations-matches
346
+ else
347
+ single_combs=get_single_combs(data)
348
+ if data[:uniqueness_type]=="single"
349
+ return single_combs
350
+ elsif data[:uniqueness_type]=="repeat"
351
+ return ((possible_combinations-matches)-(old_combinations-old_matches))-single_combs if !data[:extra_chars].nil?
352
+ return (possible_combinations-matches)-single_combs
353
+ end
354
+ end
355
+ else
356
+ return matches-old_matches if !data[:extra_chars].nil?
357
+ return matches
358
+ end
359
+ return 0
360
+ end
361
+
362
+ def get_strictness_one(letters,digits,cmb_length)
363
+ combinations=0
364
+ if cmb_length % 2 != 0
365
+ ceiling=(cmb_length/2.0).ceil
366
+ floor=(cmb_length/2.0).floor
367
+ end
368
+
369
+ if cmb_length == 6
370
+ combinations+=get_combinations({:characters=>digits,:cmb_length=>(cmb_length/2)})*2
371
+ combinations+=get_combinations({:characters=>letters,:cmb_length=>(cmb_length/2)})*2
372
+
373
+ elsif cmb_length == 7
374
+ combinations+=get_combinations({:characters=>digits,:cmb_length=>floor})*2
375
+ combinations+=get_combinations({:characters=>letters,:cmb_length=>ceiling})*2
376
+ elsif cmb_length == 8
377
+ combinations+=get_combinations({:characters=>digits,:cmb_length=>(cmb_length/2)})*2
378
+ combinations+=get_combinations({:characters=>letters,:cmb_length=>(cmb_length/2)})*2
379
+ elsif cmb_length == 9
380
+ combinations+=get_combinations({:characters=>digits,:cmb_length=>floor})*2
381
+ combinations+=get_combinations({:characters=>letters,:cmb_length=>ceiling})*2
382
+ elsif cmb_length == 10
383
+ combinations+=get_combinations({:characters=>digits,:cmb_length=>(cmb_length/2)})*2
384
+ combinations+=get_combinations({:characters=>letters,:cmb_length=>(cmb_length/2)})*2
385
+ elsif cmb_length == 11
386
+ combinations+=get_combinations({:characters=>digits,:cmb_length=>floor})*2
387
+ combinations+=get_combinations({:characters=>letters,:cmb_length=>ceiling})*2
388
+ elsif cmb_length == 12
389
+ combinations+=get_combinations({:characters=>digits,:cmb_length=>(cmb_length/2)})*2
390
+ combinations+=get_combinations({:characters=>letters,:cmb_length=>(cmb_length/2)})*2
391
+ elsif cmb_length == 13
392
+ combinations+=get_combinations({:characters=>digits,:cmb_length=>floor})*2
393
+ combinations+=get_combinations({:characters=>letters,:cmb_length=>ceiling})*2
394
+ elsif cmb_length == 14
395
+ combinations+=get_combinations({:characters=>digits,:cmb_length=>(cmb_length/2)})*2
396
+ combinations+=get_combinations({:characters=>letters,:cmb_length=>(cmb_length/2)})*2
397
+ elsif cmb_length == 15
398
+ combinations+=get_combinations({:characters=>digits,:cmb_length=>floor})*2
399
+ combinations+=get_combinations({:characters=>letters,:cmb_length=>ceiling})*2
400
+ end
401
+
402
+ return combinations
403
+ end
404
+
405
+ def get_rule_size(data)
406
+ characters=data[:characters].join()
407
+ digits=characters.scan(/[0-9]/)
408
+
409
+ if data[:cap_limit]
410
+ letters=characters.scan(/[a-z]/i)
411
+ else
412
+ letters=characters.scan(/[A-Z]/i)
413
+ end
414
+
415
+ combinations=0
416
+ if data[:extra_chars].nil?
417
+
418
+ if letters.length > 0
419
+ combinations+=get_strictness_one(letters,digits,data[:cmb_length])
420
+ end
421
+
422
+ if @strictness >= 2
423
+ combinations +=get_combinations({:cmb_length=>data[:cmb_length],
424
+ :characters=>digits})
425
+ end
426
+
427
+ if @strictness == 3
428
+ combinations +=get_combinations({:cmb_length=>data[:cmb_length],
429
+ :characters=>letters,:extra_chars=>data[:extra_chars]})
430
+ end
431
+ end
432
+ return combinations
433
+ end
434
+
435
+ def file_info(data)
436
+ if data[:write_cmbs].nil?
437
+ poss_combs=get_combinations(data)
438
+ if !data[:match_limit].nil?
439
+ if !data[:cap_limit].nil?
440
+ poss_combs=cap_limit_combs(data)
441
+ else
442
+ poss_combs -= get_above_limit(data)
443
+ end
444
+ elsif !data[:cap_limit].nil?
445
+ poss_combs=cap_limit_combs(data)
446
+ end
447
+
448
+ if @rules
449
+ poss_combs -=get_rule_size(data)
450
+ end
451
+
452
+ file_size=get_size({:cmb_length=>data[:cmb_length],:combinations=>poss_combs})
453
+ else
454
+ poss_combs=0
455
+ file_size={:bytes=>0,:kilo=>0,:mega=>0,:giga=>0,:tera=>0,:peta=>0}
456
+ dataB=data.clone
457
+ cmb_count=data[:write_cmbs].length if !data[:cap_limit].nil?
458
+ data[:write_cmbs].each do |n|
459
+ dataB[:cmb_length]=n
460
+ if data[:cap_limit].nil?
461
+ current_combs=get_combinations(dataB)
462
+ if @rules
463
+ current_combs-=get_rule_size(dataB)
464
+ end
465
+ poss_combs +=current_combs
466
+ unless data[:match_limit].nil?
467
+ poss_combs -= get_above_limit(dataB)
468
+ current_combs -= get_above_limit(dataB)
469
+ end
470
+ else
471
+ current_combs=cap_limit_combs(dataB,cmb_count)
472
+ cmb_count -= 1
473
+ poss_combs +=cap_limit_combs(dataB,cmb_count)
474
+ end
475
+ get_size({:cmb_length=>n,:combinations=>current_combs})do |sizes|
476
+ sizes.each do |key,value|
477
+ file_size[key] +=value
478
+ end
479
+ file_size[:bytes]=0 if file_size[:kilo] >= 1
480
+ end
481
+ end
482
+ end
483
+ puts "Possible #{data[:type]} combinations #{poss_combs}."
484
+ size_string="File size:"
485
+ file_size.each do |key,value|
486
+ next if value == 0
487
+ size_string += " #{"%.2f"% value}#{key.capitalize}#{'Bytes' if key != :bytes}"
488
+ end
489
+ puts size_string
490
+ puts "Do you wish to continue ?"
491
+ puts "y|Y n|N"
492
+ return gets.chomp
493
+ end
494
+
495
+ def create_file(data)
496
+ continue=file_info(data)
497
+ case continue
498
+ when /(y|Y)/
499
+ print "Enter file name:"
500
+ file_name=gets.chomp
501
+ @fh=File.open("#{file_name}.txt","a")
502
+ puts "Creating file"
503
+ when /(n|N)/
504
+ puts "Goodbye"
505
+ exit
506
+ else
507
+ puts "Invalid option"
508
+ exit
509
+ end
510
+ end
511
+ end
@@ -1,3 +1,3 @@
1
1
  class PhoenixPassword
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -1,13 +1,92 @@
1
1
  require "phoenix_password/version"
2
2
  require_relative 'realistic'
3
+ require_relative 'file_size'
3
4
 
4
5
  class PhoenixPassword
5
6
  prepend Realistic
7
+ prepend FileSize
6
8
 
7
9
  def initialize(data={})
8
10
  @rules=data[:rules]
9
11
  @strictness=data[:strictness] ? data[:strictness] : 0
10
12
  @own_rules=data[:own_rules] if data[:own_rules].is_a?(Array) && data[:own_rules][0].is_a?(Regexp)
13
+ @checkpoint=data[:checkpoint]
14
+ @restore=data[:restore]
15
+
16
+ if data[:checkpoint] || data[:restore]
17
+ require 'mysql2'
18
+ @client=Mysql2::Client.new({:host=>'localhost',:username=>'phoenix',
19
+ :password=>'Gordian100!',:database=>'phoenix_password'})
20
+ if data[:checkpoint]
21
+ @check_fraction=data[:check_fraction] ? data[:check_fraction] : 2
22
+ @check_cmb=data[:check_cmb]
23
+ end
24
+
25
+ if data[:restore]
26
+ @restore_cmb=data[:restore_cmb]
27
+ @restored=false
28
+ end
29
+ end
30
+ end
31
+
32
+
33
+ def set_check_point(possible_combinations,characters,cmb_length,combination,chars_used,i)
34
+ if @check_cmb
35
+ if @restore
36
+ if i == (possible_combinations/(characters.length*@check_fraction))+@i && cmb_length == @check_cmb
37
+ @client.query("update checkpoint set combination='#{combination.join()}',chars_used='#{chars_used}',i=#{i} where id=1")
38
+ @client.close
39
+ if !@piped
40
+ @fh.close
41
+ puts "Checkpoint set"
42
+ end
43
+ exit
44
+ elsif cmb_length > @check_cmb
45
+ @client.query("update checkpoint set combination='#{Array.new(cmb_length,characters.first).join()}',chars_used='#{Array.new(cmb_length,0)}',i=0 where id=1")
46
+ @client.close
47
+ if !@piped
48
+ puts "#{@type} combinations of length #{@check_cmb} finished"
49
+ puts "Check point set to the begining of #{cmb_length} combinations"
50
+ puts "Set :restore_cmb=>#{cmb_length}"
51
+ puts "If planning to use checkpoint set check_cmb=>#{cmb_length}"
52
+ @fh.close
53
+ end
54
+ exit
55
+ end
56
+ else
57
+ if i == possible_combinations/(characters.length*@check_fraction) && cmb_length == @check_cmb
58
+ @client.query("update checkpoint set combination='#{combination.join()}',chars_used='#{chars_used}',i=#{i} where id=1")
59
+ @client.close
60
+ if !@piped
61
+ @fh.close
62
+ puts "Checkpoint set"
63
+ end
64
+ exit
65
+ end
66
+ end
67
+ else
68
+ if @restore
69
+ if i == (possible_combinations/(characters.length*@check_fraction))+@i
70
+ @client.query("update checkpoint set combination='#{combination.join()}',chars_used='#{chars_used}',i=#{i} where id=1")
71
+ @client.close
72
+ if !@piped
73
+ @fh.close
74
+ puts "Checkpoint set"
75
+ end
76
+ exit
77
+ end
78
+ else
79
+ if i == possible_combinations/(characters.length*@check_fraction)
80
+ @client.query("update checkpoint set combination='#{combination.join()}',chars_used='#{chars_used}',i=#{i} where id=1")
81
+ @client.close
82
+ if !@piped
83
+ @fh.close
84
+ puts "Checkpoint set"
85
+ end
86
+ exit
87
+ end
88
+ end
89
+ end
11
90
  end
12
91
 
13
92
  def generate_combinations(data)
@@ -20,8 +99,27 @@ class PhoenixPassword
20
99
  i=0
21
100
  possible_combinations=characters.length**combination_length
22
101
  chars_used=Array.new(data[:cmb_length],0)
23
-
102
+
103
+ if @restore && !@restored
104
+ restore=@client.query("select * from checkpoint where id=1")
105
+ combination=restore.to_a[0]["combination"].split('')
106
+ chars_used=restore.to_a[0]["chars_used"]
107
+ chars_used=chars_used.gsub(/[^0-9,]/,'')
108
+ chars_used=chars_used.split(',')
109
+ c=0
110
+ chars_used.each do |char|
111
+ chars_used[c]=char.to_i
112
+ c+=1
113
+ end
114
+ i=restore.to_a[0]["i"]
115
+ @i=i
116
+ @restored=true
117
+ end
118
+
24
119
  while i < possible_combinations/characters.length
120
+ if @checkpoint
121
+ set_check_point(possible_combinations,characters,data[:cmb_length],combination,chars_used,i)
122
+ end
25
123
  x=1
26
124
  change_count=1
27
125
  while x < combination_length
@@ -153,7 +251,7 @@ class PhoenixPassword
153
251
  data[:extra_chars]=info[:extra_chars]
154
252
  end
155
253
 
156
- matching_file=create_file(info) if !info[:piped]
254
+ create_file(info) if !info[:piped] && @fh.nil?
157
255
 
158
256
  char_sum=data[:characters].length
159
257
  total_characters=data[:characters].length
@@ -172,9 +270,9 @@ class PhoenixPassword
172
270
  combinations.each do |combination|
173
271
  if matching_check({:combination=>combination,:match_limit=>info[:match_limit],:cap_limit=>info[:cap_limit]})
174
272
  if info[:piped]
175
- puts combination
273
+ puts combination
176
274
  else
177
- matching_file.puts(combination)
275
+ @fh.puts(combination)
178
276
  end
179
277
  matching +=1
180
278
  end
@@ -185,7 +283,7 @@ class PhoenixPassword
185
283
  rescue => e
186
284
  raise
187
285
  end while char_sum <= total_characters
188
- matching_file.close unless matching_file.nil?
286
+
189
287
  return matching
190
288
  end
191
289
 
@@ -223,7 +321,7 @@ class PhoenixPassword
223
321
  data[:extra_chars]=info[:extra_chars]
224
322
  end
225
323
 
226
- unique_file=create_file(info) unless info[:piped]
324
+ create_file(info) if !info[:piped] && @fh.nil?
227
325
 
228
326
  total_characters=data[:characters].length
229
327
  char_sum= data[:characters].length
@@ -245,7 +343,7 @@ class PhoenixPassword
245
343
  if info[:piped]
246
344
  puts combination
247
345
  else
248
- unique_file.puts(combination)
346
+ @fh.puts(combination)
249
347
  end
250
348
  unique_combs= unique_combs+1
251
349
  end
@@ -257,10 +355,6 @@ class PhoenixPassword
257
355
  raise
258
356
  end while char_sum <= total_characters
259
357
 
260
- unless unique_file.nil?
261
- unique_file.close
262
- end
263
-
264
358
  return unique_combs
265
359
  end
266
360
 
@@ -311,448 +405,16 @@ class PhoenixPassword
311
405
  return unique_chars
312
406
  end
313
407
 
314
- def get_single_combs(data)
315
- i=0
316
- single_combinations=0
317
- extra_singe=0
318
- extra_chars=data[:characters].length+data[:extra_chars].length if !data[:extra_chars].nil?
319
- while i < data[:cmb_length]-1
320
- if i == 0
321
- single_combinations=(data[:characters].length-1)*data[:characters].length
322
- extra_singe=extra_chars*(extra_chars-1) if !extra_chars.nil?
323
- else
324
- single_combinations=single_combinations*(data[:characters].length-(i+1))
325
- extra_singe=extra_singe*(extra_chars-(i+1)) if !extra_chars.nil?
326
- end
327
- i+=1
328
- end
329
- return extra_singe - single_combinations if !data[:extra_chars].nil?
330
- return single_combinations
331
- end
332
-
333
- def get_combinations(data)
334
- if data[:extra_chars].nil?
335
- base=data[:characters].length
336
- else
337
- old_base=data[:characters].length
338
- old_combinations=old_base**data[:cmb_length]
339
- x=0
340
- post_matches=0
341
- while x < data[:cmb_length]-1
342
- if x == 0
343
- post_matches=old_base
344
- elsif x == 1
345
- post_matches=(old_base**x)+(1*(old_base-1))
346
- else
347
- post_matches=(old_base**x)+(post_matches*(old_base-1))
348
- end
349
- x+=1
350
- end
351
- old_matches=old_base*post_matches
352
- base=data[:characters].length+data[:extra_chars].length
353
- end
354
- previous_matches=0
355
- i=0
356
-
357
- while i < data[:cmb_length]-1
358
- if i==0
359
- previous_matches=base
360
- elsif i== 1
361
- previous_matches=(base**i)+(1*(base-1))
362
- else
363
- previous_matches=(base**i)+(previous_matches*(base-1))
364
- end
365
- i+=1
366
- end
367
- matches=base*previous_matches
368
-
369
- if data[:type]=='unique'
370
- possible_combinations=base**data[:cmb_length]
371
- if data[:uniqueness_type].nil?
372
- return (possible_combinations-matches)-(old_combinations-old_matches) if !data[:extra_chars].nil?
373
- return possible_combinations-matches
374
- else
375
- single_combs=get_single_combs(data)
376
- if data[:uniqueness_type]=="single"
377
- return single_combs
378
- elsif data[:uniqueness_type]=="repeat"
379
- return ((possible_combinations-matches)-(old_combinations-old_matches))-single_combs if !data[:extra_chars].nil?
380
- return (possible_combinations-matches)-single_combs
381
- end
382
- end
383
- else
384
- return matches-old_matches if !data[:extra_chars].nil?
385
- return matches
386
- end
387
- return 0
388
- end
389
-
390
- def get_above_limit(data)
391
- if data[:extra_chars].nil?
392
- base=data[:characters].length
393
- else
394
- old_base=data[:characters].length
395
- previous_matches=0
396
- previous_mult=0
397
- i=0
398
- while i < (data[:cmb_length] -1)
399
- if i == (data[:match_limit]-1)
400
- previous_matches=old_base
401
- old_matches=previous_matches
402
- elsif i == data[:match_limit]
403
- previous_matches=previous_matches+(1*(old_base-1))
404
- previous_mult=1
405
- else
406
- temp_mult=previous_matches
407
- previous_matches=(old_base**(i-1)+previous_mult*(old_base-1))+(previous_matches*(old_base-1))
408
- previous_mult=temp_mult
409
- end
410
-
411
- i+=1
412
- end
413
-
414
- old_matches=old_base*previous_matches if data[:cmb_length] != (data[:match_limit]+1)
415
- base=data[:characters].length+data[:extra_chars].length
416
- end
417
-
418
- previous_matches=0
419
- previous_mult=0
420
- i=1
421
- while i < (data[:cmb_length] -1)
422
- if i == (data[:match_limit]-1)
423
- previous_matches=base
424
- return previous_matches if data[:cmb_length] == (data[:match_limit]+i) && data[:extra_chars].nil?
425
- elsif i == data[:match_limit]
426
- previous_matches=previous_matches+(1*(base-1))
427
- previous_mult=1
428
- else
429
- temp_mult=previous_matches
430
- previous_matches=(base**(i-1))+(previous_mult*(base-1))+(previous_matches*(base-1))
431
- previous_mult=temp_mult
432
-
433
- end
434
- i+=1
435
- end
436
-
437
- unless data[:extra_chars].nil?
438
- return base-old_base if data[:cmb_length] == (data[:match_limit]+1)
439
- return (base*previous_matches)-old_matches
440
- else
441
- return base*previous_matches
442
- end
443
- end
444
-
445
- def cap_limit_matching(data)
446
- cap_data={}
447
- total_chars=data[:characters].join()
448
- caps_matched= total_chars.scan(/[A-Z]/)
449
- cap_data[:characters]=[]
450
- data[:characters].each do |char|
451
- next if caps_matched.include?(char)
452
- cap_data[:characters].push(char)
453
- end
454
- base=cap_data[:characters].length
455
- cap_matches=0
456
- case data[:cmb_length]
457
- when 3
458
- cap_matches += base*2
459
- when 4
460
- cap_matches+=get_combinations({:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-1})*2
461
- cap_matches+=(base**2)*2
462
- else
463
- cap_matches+=get_combinations({:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-1})*2
464
- cap_matches+=(get_combinations({:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-2})*base)*(data[:cmb_length]-2)
465
- end
466
-
467
- if !data[:extra_chars].nil?
468
- all_chars=data[:characters]+data[:extra_chars]
469
- new_cap_matches=cap_limit_matching({:cmb_length=>data[:cmb_length],:characters=>all_chars})
470
- return new_cap_matches-(cap_matches*caps_matched.length)
471
- else
472
- return cap_matches*caps_matched.length
473
- end
474
-
475
- end
476
-
477
- def cap_limit_matching_l(data)
478
- cap_data={}
479
- total_chars=data[:characters].join()
480
- caps_matched= total_chars.scan(/[A-Z]/)
481
- cap_data[:characters]=[]
482
- data[:characters].each do |char|
483
- next if caps_matched.include?(char)
484
- cap_data[:characters].push(char)
485
- end
486
- base=cap_data[:characters].length
487
- cap_matches=0
488
- no_limit_matches=get_combinations({:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-1})
489
- case data[:cmb_length]
490
- when 3
491
- cap_matches += base*2
492
- when 4
493
- cap_matches+=(no_limit_matches-get_above_limit({:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-1,:match_limit=>data[:match_limit]}))*2
494
- cap_matches+=(base**2)*2
495
- else
496
-
497
- #XXA
498
- cap_matches+=(no_limit_matches-get_above_limit({:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-1,:match_limit=>data[:match_limit]}))*2
499
- no_limit_matches=get_combinations({:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-2})
500
- #XAX
501
- cap_matches+=((no_limit_matches-get_above_limit({:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-2,:match_limit=>data[:match_limit]}))*base)*2
502
- x=data[:cmb_length]-4
503
- if x == 1
504
- cap_matches +=get_combinations({:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-2})*base
505
- elsif x == 2
506
- grt_half_no_limit=get_combinations({:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-3})
507
- grt_half_limit =grt_half_no_limit-get_above_limit({:characters=>cap_data[:characters],:match_limit=>data[:match_limit],:cmb_length=>data[:cmb_length]-3})
508
- cap_matches +=(((grt_half_limit*base**2)+(base*base**3))-(grt_half_no_limit*base))*2
509
- else
510
- #AXX
511
- i=3
512
- p=0
513
- l=0
514
- begin
515
- grt_half=get_combinations({:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-(3+l)})
516
- grt_half_limit =grt_half-get_above_limit({:characters=>cap_data[:characters],:match_limit=>data[:match_limit],:cmb_length=>data[:cmb_length]-(3+l)})
517
- if i == 3
518
- if data[:cmb_length] <=8
519
- cap_matches +=(((grt_half_limit*base**2)+(base*base**(x+1)))-(grt_half*base))*2
520
- else
521
- cap_matches +=((grt_half_limit*((base**2)-base))+(base*base**(x+1)))*2
522
-
523
- end
524
- else
525
- lsr_half=get_combinations({:characters=>cap_data[:characters],:cmb_length=>i-1})
526
- lsr_half_limit=lsr_half-get_above_limit(:characters=>cap_data[:characters],:match_limit=>data[:match_limit],:cmb_length=>i-1)
527
- cap_matches +=(((grt_half_limit*(base**(2+p)))+(lsr_half_limit*base**(x+1-p)))-(grt_half*lsr_half))*2
528
-
529
- end
530
- p+=1
531
- l+=1
532
- i+=1
533
- end while i < (data[:cmb_length]/2.0).ceil
534
-
535
-
536
-
537
- if x%2 == 1
538
- no_limit_matches=get_combinations({:characters=>cap_data[:characters],:cmb_length=>x-(p-1)})
539
- half_point=(((no_limit_matches-get_above_limit({:characters=>cap_data[:characters],:cmb_length=>x-(p-1),:match_limit=>data[:match_limit]})))*base**(x-(p-1)))*2
540
- if data[:cmb_length] == 7
541
- cap_matches+=half_point-((half_point/base))
542
- else
543
- half_no_limit=get_combinations(:characters=>cap_data[:characters],:cmb_length=>x-1)
544
- half_no_limit_b=get_combinations(:characters=>cap_data[:characters],:cmb_length=>x-2)
545
-
546
- if data[:cmb_length] >= 9 && data[:extra_chars].nil?
547
- puts "!------Approximately less than------!"
548
- end
549
- cap_matches+=half_point-((half_point/base))
550
-
551
- end
552
-
553
- else
554
- no_limit_matches_a=get_combinations({:characters=>cap_data[:characters],:cmb_length=>(x-l)+1})
555
- greater_half=(((no_limit_matches_a-get_above_limit({:characters=>cap_data[:characters],:cmb_length=>(x-l)+1,:match_limit=>data[:match_limit]})))*base**(x-l))
556
- no_limit_matches_b=get_combinations({:characters=>cap_data[:characters],:cmb_length=>(x-l)})
557
- lesser_half=(((no_limit_matches_b-get_above_limit({:characters=>cap_data[:characters],:cmb_length=>(x-l),:match_limit=>data[:match_limit]})))*base**(x-l+1))
558
-
559
- if data[:cmb_length] == 10 && data[:extra_chars].nil?
560
- puts "!------Approximately less than------!"
561
- elsif data[:cmb_length] == 12 && data[:extra_chars].nil?
562
- puts "!------Approximately more than------!"
563
- end
564
- cap_matches+=((greater_half+lesser_half)-((no_limit_matches_a*no_limit_matches_b)-(no_limit_matches_b*base)))*2
565
- end
566
-
567
- end
568
-
569
- end
570
-
571
- if (cap_data[:characters].length <= 2 || data[:cmb_length] >= 13) && data[:extra_chars].nil?
572
- puts "!!!----Inaccurate information----!!!"
573
- end
574
-
575
- if !data[:extra_chars].nil?
576
- all_chars=data[:characters]+data[:extra_chars]
577
- new_cap_matches=cap_limit_matching_l({:cmb_length=>data[:cmb_length],:characters=>all_chars,:match_limit=>data[:match_limit]})
578
- return new_cap_matches-(cap_matches*caps_matched.length)
579
- else
580
- return cap_matches*caps_matched.length
581
- end
582
- end
583
-
584
- def unique_cap_limit(data)
585
- cap_data={}
586
- total_chars=data[:characters].join()
587
- caps_matched= total_chars.scan(/[A-Z]/)
588
- cap_data[:characters]=[]
589
- data[:characters].each do |char|
590
- next if caps_matched.include?(char)
591
- cap_data[:characters].push(char)
592
- end
593
- base=cap_data[:characters].length
594
- unique_cap_limit=0
595
- if data[:uniqueness_type] == 'single'
596
- if data[:cmb_length] == 3
597
- unique_cap_limit=(((base**2)-(base))*3)
598
- else
599
- previous_single=get_single_combs(:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-1,:type=>"unique")
600
- unique_cap_limit=previous_single*data[:cmb_length]
601
- end
602
- else
603
- case data[:cmb_length]
604
- when 3
605
- if data[:uniqueness_type].nil?
606
- unique_cap_limit=((base**2)*3)-(base*2)
607
- else
608
- unique_cap_limit=((base**2)*3)-(base*2)-(((base**2)-(base))*3)
609
- end
610
- when 4
611
- previous_unique=get_combinations(:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-1,:type=>"unique")
612
- if data[:uniqueness_type].nil?
613
- unique_cap_limit=(previous_unique*2)+((((base**2)-base)*base)*2)
614
- else
615
- previous_single=get_single_combs(:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-1,:type=>"unique")
616
- unique_cap_limit=(previous_unique*2)+((((base**2)-base)*base)*2)-(previous_single*data[:cmb_length])
617
- end
618
- else
619
- previous_unique_a=get_combinations(:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-1,:type=>"unique")
620
- previous_unique_b=get_combinations(:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-2,:type=>"unique")
621
- if data[:uniqueness_type].nil?
622
- unique_cap_limit=(previous_unique_a*2)+((previous_unique_b*base)*(data[:cmb_length]-2))
623
- else
624
- previous_single=get_single_combs(:characters=>cap_data[:characters],:cmb_length=>data[:cmb_length]-1,:type=>"unique")
625
- unique_cap_limit=(previous_unique_a*2)+((previous_unique_b*base)*(data[:cmb_length]-2))-(previous_single*data[:cmb_length])
626
- end
627
- end
628
- end
629
-
630
- if !data[:extra_chars].nil?
631
- all_chars=data[:characters]+data[:extra_chars]
632
- new_unique_cap_limit=unique_cap_limit({:cmb_length=>data[:cmb_length],:characters=>all_chars,:uniqueness_type=>data[:uniqueness_type]})
633
- return new_unique_cap_limit-(unique_cap_limit*caps_matched.length)
634
- else
635
- return unique_cap_limit*caps_matched.length
636
- end
637
-
638
- end
639
-
640
- def cap_limit_combs(data,x=0)
641
- if data[:type] == "matching"
642
- if !data[:match_limit].nil?
643
- puts "Combinations and file size may vary when using match_limit" if x == 0
644
- cap_limit_matching_l(data)
645
- else
646
- cap_limit_matching(data)
647
- end
648
- else
649
- unique_cap_limit(data)
650
- end
651
- end
652
-
653
- def get_size(data)
654
- bytes=data[:combinations]*(data[:cmb_length]+1)
655
- kilo_bytes=bytes/1000.0
656
- mega_bytes=kilo_bytes/1000.0
657
- giga_bytes=mega_bytes/1000.0
658
- tera_bytes=giga_bytes/1000.0
659
- peta_bytes=tera_bytes/1000.0
660
- all_sizes= {:bytes=>bytes,:kilo=>kilo_bytes,:mega=>mega_bytes,:giga=>giga_bytes,:tera=>tera_bytes,:peta=>peta_bytes}
661
- return_sizes= {}
662
- all_sizes.each do |key,value|
663
- if kilo_bytes < 1
664
- return_sizes[key]=value
665
- break
666
- end
667
- return_sizes[key]=value if value > 0.01 && key != :bytes
668
- end
669
- yield(return_sizes) if block_given?
670
- return return_sizes
671
- end
672
-
673
-
674
- def create_file(data)
675
- continue=file_info(data)
676
- case continue
677
- when /(y|Y)/
678
- if data[:file_append]
679
- return File.open("#{data[:file_append]}.txt","a")
680
- else
681
- puts "Creating file"
682
- print "Enter save file name:"
683
- file_name=gets.chomp
684
- data[:file_append]=file_name if !data[:file_append].nil?
685
- return File.open("#{file_name}.txt","w")
686
- end
687
-
688
- when /(n|N)/
689
- puts "Goodbye"
690
- exit
691
- else
692
- puts "Invalid option"
693
- exit
694
- end
695
- end
408
+ def multi_length(data)
409
+ dataB=data.clone
696
410
 
697
- def file_info(data)
698
- if data[:file_append].nil? || !data[:file_append]
699
- if data[:write_cmbs].nil?
700
- poss_combs=get_combinations(data)
701
- if !data[:match_limit].nil?
702
- if !data[:cap_limit].nil?
703
- poss_combs=cap_limit_combs(data)
704
- else
705
- poss_combs -= get_above_limit(data)
706
- end
707
- elsif !data[:cap_limit].nil?
708
- poss_combs=cap_limit_combs(data)
709
- end
710
- matching_file_size=get_size({:cmb_length=>data[:cmb_length],:combinations=>poss_combs})
711
- else
712
- poss_combs=0
713
- matching_file_size={:bytes=>0,:kilo=>0,:mega=>0,:giga=>0,:tera=>0,:peta=>0}
714
- dataB=data.clone
715
- cmb_count=data[:write_cmbs].length if !data[:cap_limit].nil?
716
- data[:write_cmbs].each do |n|
717
- dataB[:cmb_length]=n
718
- if data[:cap_limit].nil?
719
- current_combs=get_combinations(dataB)
720
- poss_combs +=current_combs
721
- unless data[:match_limit].nil?
722
- poss_combs -= get_above_limit(dataB)
723
- current_combs -= get_above_limit(dataB)
724
- end
725
- else
726
- current_combs=cap_limit_combs(dataB,cmb_count)
727
- cmb_count -= 1
728
- poss_combs +=cap_limit_combs(dataB,cmb_count)
729
- end
730
- get_size({:cmb_length=>n,:combinations=>current_combs})do |sizes|
731
- sizes.each do |key,value|
732
- matching_file_size[key] +=value
733
- end
734
- matching_file_size[:bytes]=0 if matching_file_size[:kilo] >= 1
735
- end
736
- end
737
- end
738
- puts "Possible #{data[:type]} combinations #{poss_combs}."
739
- size_string="File size:"
740
- matching_file_size.each do |key,value|
741
- next if value == 0
742
- size_string += " #{"%.2f"% value}#{key.capitalize}#{'Bytes' if key != :bytes}"
411
+ if @restore_cmb && @restore
412
+ temp_cmbs=data[:cmb_length].clone
413
+ temp_cmbs.each do |n|
414
+ data[:cmb_length].delete(n) if n < @restore_cmb
743
415
  end
744
- puts size_string
745
- puts "Do you wish to continue ?"
746
- puts "y|Y n|N"
747
- return gets.chomp
748
-
749
- elsif data[:file_append]
750
- return "y"
751
416
  end
752
- end
753
417
 
754
- def multi_length(data)
755
- dataB=data.clone
756
418
  i=0
757
419
  while i < data[:cmb_length].length
758
420
  dataB[:cmb_length] = data[:cmb_length][i]
@@ -762,32 +424,28 @@ class PhoenixPassword
762
424
  elsif data[:type] == 'matching'
763
425
  matching_combinations(dataB)
764
426
  end
765
-
766
427
  i+=1
767
428
  end
768
429
  end
769
430
 
770
431
  def combinations(data)
771
432
  @type=data[:type]
772
- puts "File size estimates are invalid when
773
- using rules" if @rules && data[:piped]
433
+ @piped=data[:piped]
434
+ puts "File size estimates are invalid when using rules" if @rules && !data[:piped]
774
435
  case data[:type]
775
436
  when "matching"
776
437
  if data[:cmb_length].length == 1
777
438
  data[:cmb_length]=data[:cmb_length][0]
778
439
  matching_combinations(data)
779
440
  else
780
- data[:file_append]=false
781
441
  data[:write_cmbs]=data[:cmb_length].clone
782
442
  multi_length(data)
783
443
  end
784
-
785
444
  when "unique"
786
445
  if data[:cmb_length].length == 1
787
446
  data[:cmb_length]=data[:cmb_length].first
788
447
  unique_combinations(data)
789
448
  else
790
- data[:file_append]=false
791
449
  data[:write_cmbs]=data[:cmb_length].clone
792
450
  multi_length(data)
793
451
  end
@@ -795,5 +453,10 @@ class PhoenixPassword
795
453
  puts "Invalid combination type"
796
454
  exit
797
455
  end
456
+ if !@piped
457
+ @fh.close
458
+ @client.close if @client
459
+ puts "File created"
460
+ end
798
461
  end
799
462
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phoenix_password
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Spiros Avlonitis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-20 00:00:00.000000000 Z
11
+ date: 2017-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mysql2
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.4.6
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.4.6
55
69
  description: Phoenix password generator provides you with several options for generating
56
70
  passwords, which characters are to be used,combination length,character uniqueness
57
71
  etc.
@@ -68,6 +82,7 @@ files:
68
82
  - LICENSE.txt
69
83
  - README.md
70
84
  - Rakefile
85
+ - lib/file_size.rb
71
86
  - lib/phoenix_password.rb
72
87
  - lib/phoenix_password/version.rb
73
88
  - lib/realistic.rb