phoenix_password 0.1.1
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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/phoenix_password/version.rb +3 -0
- data/lib/phoenix_password.rb +497 -0
- data/phoenix_password-0.1.0.gem +0 -0
- data/phoenix_password.gemspec +28 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 38394d2c8e3ea4b79601f843c71a0e955e86a54e
|
4
|
+
data.tar.gz: b34dd40504267f84d970fda0f70ed6559cdc7604
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5ffc168512e8e567c627a77bf05488f811b96e46e71820c52110a447e450ea98c1bd78989db07858b39ebb47e74adfc2fd090655077e39d7cef7170135424030
|
7
|
+
data.tar.gz: 5935ff4314ced67a5410e6cc0392466b8fc9cdc4d9540f3c9f187121a778cbdf2cbb74f515bf7abec674bb161d26b0280764769a5d6f7806e483000d3fab4963
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at spirosa84@hotmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Spiros Avlonitis
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# PhoenixPassword
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/phoenix_password`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'phoenix_password'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install phoenix_password
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/phoenix_password. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "phoenix_password"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,497 @@
|
|
1
|
+
require "phoenix_password/version"
|
2
|
+
|
3
|
+
class PhoenixPassword
|
4
|
+
def self.generate_combinations(data)
|
5
|
+
characters=data[:characters]
|
6
|
+
if !data[:extra_chars].nil?
|
7
|
+
characters.push(data[:extra_chars][data[:iteration]-1]) if data[:iteration] != 0
|
8
|
+
end
|
9
|
+
combination=Array.new(data[:cmb_length],data[:characters].first)
|
10
|
+
combination_length=combination.length
|
11
|
+
i=0
|
12
|
+
possible_combinations=characters.length**combination_length
|
13
|
+
chars_used=Array.new(data[:cmb_length],0)
|
14
|
+
|
15
|
+
while i < possible_combinations
|
16
|
+
x=1
|
17
|
+
change_count=1
|
18
|
+
while x < combination_length
|
19
|
+
if chars_used[x] == characters.length
|
20
|
+
chars_used[x] = 0
|
21
|
+
end
|
22
|
+
if combination[x] == characters.last && combination[x+1] == characters.last
|
23
|
+
change_count +=1
|
24
|
+
if change_count == combination_length -1
|
25
|
+
chars_used[0] += 1
|
26
|
+
end
|
27
|
+
end
|
28
|
+
x +=1
|
29
|
+
end
|
30
|
+
|
31
|
+
y=0
|
32
|
+
until y == combination_length
|
33
|
+
combination[y]=characters[chars_used[y]]
|
34
|
+
y+=1
|
35
|
+
end
|
36
|
+
|
37
|
+
if data[:extra_chars].nil? || data[:iteration] == 0
|
38
|
+
yield(combination.join())
|
39
|
+
else
|
40
|
+
yield(combination.join()) if combination.include?(characters.last)
|
41
|
+
end
|
42
|
+
|
43
|
+
z=combination_length-1
|
44
|
+
while 1 < z
|
45
|
+
if z == combination_length-1
|
46
|
+
chars_used[z-1] +=1 if combination[z] == characters.last
|
47
|
+
else
|
48
|
+
diff=(combination_length-1)-z
|
49
|
+
last_chars=0
|
50
|
+
count_diff=1
|
51
|
+
while count_diff <= diff
|
52
|
+
if combination[z] == characters.last && combination[z+count_diff] == characters.last
|
53
|
+
last_chars +=1
|
54
|
+
end
|
55
|
+
count_diff +=1
|
56
|
+
end
|
57
|
+
if last_chars == (combination_length-1)-z
|
58
|
+
chars_used[z-1] +=1
|
59
|
+
end
|
60
|
+
end
|
61
|
+
z-=1
|
62
|
+
end
|
63
|
+
chars_used[combination_length-1] +=1
|
64
|
+
i+=1
|
65
|
+
end
|
66
|
+
return characters
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.matching_combinations(info)
|
70
|
+
data={:characters=>info[:characters],:cmb_length=>info[:cmb_length],:type=>info[:type]}
|
71
|
+
unless info[:extra_chars].nil?
|
72
|
+
data[:extra_chars]=info[:extra_chars]
|
73
|
+
end
|
74
|
+
|
75
|
+
matching_file=create_file(info) if !info[:piped]
|
76
|
+
|
77
|
+
char_sum=data[:characters].length
|
78
|
+
total_characters=data[:characters].length
|
79
|
+
unless data[:extra_chars].nil?
|
80
|
+
total_characters=data[:characters].length+data[:extra_chars].length
|
81
|
+
data[:iteration]=0
|
82
|
+
if info[:skip_first] || !info[:piped]
|
83
|
+
data[:iteration] +=1
|
84
|
+
char_sum +=1
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
matching=0
|
89
|
+
begin
|
90
|
+
generate_combinations(data) do |combination;i|
|
91
|
+
if matching_check({:combination=>combination,:match_limit=>info[:match_limit]})
|
92
|
+
if info[:piped]
|
93
|
+
puts combination
|
94
|
+
elsif !matching_file.nil?
|
95
|
+
if data[:extra_chars].nil?
|
96
|
+
matching_file.puts(combination)
|
97
|
+
elsif data[:iteration] >= 1
|
98
|
+
matching_file.puts(combination)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
matching +=1
|
102
|
+
end
|
103
|
+
end
|
104
|
+
data[:iteration]+=1 unless data[:iteration].nil?
|
105
|
+
char_sum +=1
|
106
|
+
end while char_sum <= total_characters
|
107
|
+
matching_file.close unless matching_file.nil?
|
108
|
+
return matching
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.matching_check(info)
|
112
|
+
combination=info[:combination]
|
113
|
+
i=0
|
114
|
+
x=0
|
115
|
+
u=0
|
116
|
+
while i < (combination.length-1)
|
117
|
+
if combination[i] == combination[i+1]
|
118
|
+
return true if info[:match_limit].nil?
|
119
|
+
if i == 0
|
120
|
+
x +=1
|
121
|
+
elsif combination[i] == combination[i-1] || combination[i] == combination[i+info[:match_limit]]
|
122
|
+
x+=1
|
123
|
+
end
|
124
|
+
else
|
125
|
+
u +=1
|
126
|
+
end
|
127
|
+
if x == info[:match_limit] || u == combination.length-1
|
128
|
+
return false
|
129
|
+
end
|
130
|
+
i+=1
|
131
|
+
end
|
132
|
+
return true
|
133
|
+
end
|
134
|
+
|
135
|
+
def self.unique_combinations(info)
|
136
|
+
data={:characters=>info[:characters],:cmb_length=>info[:cmb_length],:type=>info[:type]}
|
137
|
+
unless info[:extra_chars].nil?
|
138
|
+
data[:extra_chars]=info[:extra_chars]
|
139
|
+
end
|
140
|
+
|
141
|
+
unique_file=create_file(info) unless info[:piped]
|
142
|
+
|
143
|
+
total_characters=data[:characters].length
|
144
|
+
char_sum= data[:characters].length
|
145
|
+
unless data[:extra_chars].nil?
|
146
|
+
total_characters=data[:characters].length+data[:extra_chars].length
|
147
|
+
data[:iteration]=0
|
148
|
+
if info[:skip_first] || !info[:piped]
|
149
|
+
data[:iteration]+=1
|
150
|
+
char_sum +=1
|
151
|
+
end
|
152
|
+
end
|
153
|
+
unique_combs=0
|
154
|
+
uniqueness=info[:uniqueness_type]
|
155
|
+
begin
|
156
|
+
generate_combinations(data) do |combination|
|
157
|
+
unique_chars=check_uniqueness(combination,uniqueness)
|
158
|
+
if unique_chars == combination.length-1
|
159
|
+
puts combination if info[:piped]
|
160
|
+
unless unique_file.nil?
|
161
|
+
unless data[:extra_chars].nil?
|
162
|
+
if data[:iteration] != 0
|
163
|
+
unique_file.puts(combination)
|
164
|
+
end
|
165
|
+
else
|
166
|
+
unique_file.puts(combination)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
unique_combs= unique_combs+1
|
170
|
+
end
|
171
|
+
end
|
172
|
+
data[:iteration] +=1 if !data[:iteration].nil?
|
173
|
+
char_sum +=1
|
174
|
+
end while char_sum <= total_characters
|
175
|
+
|
176
|
+
unless unique_file.nil?
|
177
|
+
unique_file.close
|
178
|
+
end
|
179
|
+
puts unique_combs
|
180
|
+
return unique_combs
|
181
|
+
end
|
182
|
+
|
183
|
+
def self.check_uniqueness(combination,uniqueness)
|
184
|
+
i=0
|
185
|
+
unique_chars=0
|
186
|
+
chars_check=[]
|
187
|
+
while i < (combination.length-1)
|
188
|
+
if combination[i] != combination[i+1]
|
189
|
+
if uniqueness.nil?
|
190
|
+
unique_chars+=1
|
191
|
+
elsif uniqueness == "single"
|
192
|
+
if i == 0
|
193
|
+
unique_chars+=1
|
194
|
+
chars_check.push(combination[i])
|
195
|
+
elsif !chars_check.include?(combination[i])
|
196
|
+
chars_check << combination[i]
|
197
|
+
if !chars_check.include?(combination[i+1])
|
198
|
+
unique_chars +=1
|
199
|
+
else
|
200
|
+
return 0
|
201
|
+
end
|
202
|
+
end
|
203
|
+
elsif uniqueness == "repeat"
|
204
|
+
if i == 0
|
205
|
+
unique_chars+=1
|
206
|
+
chars_check.push(combination[i])
|
207
|
+
elsif chars_check.include?(combination[i])
|
208
|
+
unique_chars+=1
|
209
|
+
elsif i == (combination.length-2)
|
210
|
+
#since in last iteration compare against the next character as well
|
211
|
+
unique_chars +=1 if chars_check.include?(combination[i]) || chars_check.include?(combination[i+1])
|
212
|
+
else
|
213
|
+
chars_check.push(combination[i])
|
214
|
+
end
|
215
|
+
|
216
|
+
return combination.length-1 if i == (combination.length-2) && unique_chars > 1
|
217
|
+
end
|
218
|
+
else
|
219
|
+
return 0
|
220
|
+
end
|
221
|
+
i+=1
|
222
|
+
end
|
223
|
+
return unique_chars
|
224
|
+
end
|
225
|
+
|
226
|
+
def self.get_single_combs(data)
|
227
|
+
i=0
|
228
|
+
single_combinations=0
|
229
|
+
extra_singe=0
|
230
|
+
extra_chars=data[:characters].length+data[:extra_chars].length if !data[:extra_chars].nil?
|
231
|
+
while i < data[:cmb_length]-1
|
232
|
+
if i == 0
|
233
|
+
single_combinations=(data[:characters].length-1)*data[:characters].length
|
234
|
+
extra_singe=extra_chars*(extra_chars-1) if !extra_chars.nil?
|
235
|
+
else
|
236
|
+
single_combinations=single_combinations*(data[:characters].length-(i+1))
|
237
|
+
extra_singe=extra_singe*(extra_chars-(i+1)) if !extra_chars.nil?
|
238
|
+
end
|
239
|
+
i+=1
|
240
|
+
end
|
241
|
+
return extra_singe - single_combinations if !data[:extra_chars].nil?
|
242
|
+
return single_combinations
|
243
|
+
end
|
244
|
+
|
245
|
+
def self.get_combinations(data)
|
246
|
+
if data[:extra_chars].nil?
|
247
|
+
base=data[:characters].length
|
248
|
+
else
|
249
|
+
old_base=data[:characters].length
|
250
|
+
old_combinations=old_base**data[:cmb_length]
|
251
|
+
x=0
|
252
|
+
post_matches=0
|
253
|
+
while x < data[:cmb_length]-1
|
254
|
+
if x == 0
|
255
|
+
post_matches=old_base
|
256
|
+
elsif x == 1
|
257
|
+
post_matches=(old_base**x)+(1*(old_base-1))
|
258
|
+
else
|
259
|
+
post_matches=(old_base**x)+(post_matches*(old_base-1))
|
260
|
+
end
|
261
|
+
x+=1
|
262
|
+
end
|
263
|
+
old_matches=old_base*post_matches
|
264
|
+
base=data[:characters].length+data[:extra_chars].length
|
265
|
+
end
|
266
|
+
possible_combinations=base**data[:cmb_length]
|
267
|
+
previous_matches=0
|
268
|
+
i=0
|
269
|
+
|
270
|
+
while i < data[:cmb_length]-1
|
271
|
+
if i==0
|
272
|
+
previous_matches=base
|
273
|
+
elsif i== 1
|
274
|
+
previous_matches=(base**i)+(1*(base-1))
|
275
|
+
else
|
276
|
+
previous_matches=(base**i)+(previous_matches*(base-1))
|
277
|
+
end
|
278
|
+
i+=1
|
279
|
+
end
|
280
|
+
matches=base*previous_matches
|
281
|
+
|
282
|
+
if data[:type]=='unique'
|
283
|
+
if data[:uniqueness_type].nil?
|
284
|
+
return (possible_combinations-matches)-(old_combinations-old_matches) if !data[:extra_chars].nil?
|
285
|
+
return possible_combinations-matches
|
286
|
+
else
|
287
|
+
single_combs=get_single_combs(data)
|
288
|
+
if data[:uniqueness_type]=="single"
|
289
|
+
return single_combs
|
290
|
+
elsif data[:uniqueness_type]=="repeat"
|
291
|
+
return ((possible_combinations-matches)-(old_combinations-old_matches))-single_combs if !data[:extra_chars].nil?
|
292
|
+
return (possible_combinations-matches)-single_combs
|
293
|
+
end
|
294
|
+
end
|
295
|
+
else
|
296
|
+
return matches-old_matches if !data[:extra_chars].nil?
|
297
|
+
return matches
|
298
|
+
end
|
299
|
+
return 0
|
300
|
+
end
|
301
|
+
|
302
|
+
def self.get_above_limit(data)
|
303
|
+
if data[:extra_chars].nil?
|
304
|
+
base=data[:characters].length
|
305
|
+
else
|
306
|
+
old_base=data[:characters].length
|
307
|
+
previous_matches=0
|
308
|
+
previous_mult=0
|
309
|
+
i=0
|
310
|
+
while i < (data[:cmb_length] -1)
|
311
|
+
if i == (data[:match_limit]-1)
|
312
|
+
previous_matches=old_base
|
313
|
+
old_matches=previous_matches
|
314
|
+
elsif i == data[:match_limit]
|
315
|
+
previous_matches=previous_matches+(1*(old_base-1))
|
316
|
+
previous_mult=1
|
317
|
+
else
|
318
|
+
temp_mult=previous_matches
|
319
|
+
previous_matches=(old_base**(i-1)+previous_mult*(old_base-1))+(previous_matches*(old_base-1))
|
320
|
+
previous_mult=temp_mult
|
321
|
+
end
|
322
|
+
|
323
|
+
i+=1
|
324
|
+
end
|
325
|
+
|
326
|
+
old_matches=old_base*previous_matches if data[:cmb_length] != (data[:match_limit]+1)
|
327
|
+
base=data[:characters].length+data[:extra_chars].length
|
328
|
+
end
|
329
|
+
|
330
|
+
previous_matches=0
|
331
|
+
previous_mult=0
|
332
|
+
i=0
|
333
|
+
while i < (data[:cmb_length] -1)
|
334
|
+
if i == (data[:match_limit]-1)
|
335
|
+
previous_matches=base
|
336
|
+
return previous_matches if data[:cmb_length] == (data[:match_limit]+i) && data[:extra_chars].nil?
|
337
|
+
elsif i == data[:match_limit]
|
338
|
+
previous_matches=previous_matches+(1*(base-1))
|
339
|
+
previous_mult=1
|
340
|
+
else
|
341
|
+
temp_mult=previous_matches
|
342
|
+
previous_matches=(base**(i-1))+(previous_mult*(base-1))+(previous_matches*(base-1))
|
343
|
+
previous_mult=temp_mult*(base-1)
|
344
|
+
|
345
|
+
end
|
346
|
+
i+=1
|
347
|
+
end
|
348
|
+
|
349
|
+
unless data[:extra_chars].nil?
|
350
|
+
return base-old_base if data[:cmb_length] == (data[:match_limit]+1)
|
351
|
+
return (base*previous_matches)-old_matches
|
352
|
+
else
|
353
|
+
return base*previous_matches
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
def self.get_size(data)
|
358
|
+
bytes=data[:combinations]*(data[:cmb_length]+1)
|
359
|
+
kilo_bytes=bytes/1000.0
|
360
|
+
mega_bytes=kilo_bytes/1000.0
|
361
|
+
giga_bytes=mega_bytes/1000.0
|
362
|
+
tera_bytes=giga_bytes/1000.0
|
363
|
+
peta_bytes=tera_bytes/1000.0
|
364
|
+
all_sizes= {:bytes=>bytes,:kilo=>kilo_bytes,:mega=>mega_bytes,:giga=>giga_bytes,:tera=>tera_bytes,:peta=>peta_bytes}
|
365
|
+
return_sizes= {}
|
366
|
+
all_sizes.each do |key,value|
|
367
|
+
if kilo_bytes < 1
|
368
|
+
return_sizes[key]=value
|
369
|
+
break
|
370
|
+
end
|
371
|
+
return_sizes[key]=value if value > 0.01 && key != :bytes
|
372
|
+
end
|
373
|
+
yield(return_sizes)
|
374
|
+
return return_sizes
|
375
|
+
end
|
376
|
+
|
377
|
+
|
378
|
+
def self.create_file(data)
|
379
|
+
continue=file_info(data)
|
380
|
+
case continue
|
381
|
+
when /(y|Y)/
|
382
|
+
if data[:file_append]
|
383
|
+
return File.open("#{data[:file_append]}.txt","a")
|
384
|
+
else
|
385
|
+
puts "Creating file"
|
386
|
+
print "Enter save file name:"
|
387
|
+
file_name=gets.chomp
|
388
|
+
data[:file_append]=file_name if !data[:file_append].nil?
|
389
|
+
return File.open("#{file_name}.txt","w")
|
390
|
+
end
|
391
|
+
|
392
|
+
when /(n|N)/
|
393
|
+
puts "Goodbye"
|
394
|
+
exit
|
395
|
+
else
|
396
|
+
puts "Invalid option"
|
397
|
+
exit
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
def self.file_info(data)
|
402
|
+
if data[:file_append].nil? || !data[:file_append]
|
403
|
+
if data[:write_cmbs].nil?
|
404
|
+
poss_combs=get_combinations(data)
|
405
|
+
unless data[:match_limit].nil?
|
406
|
+
poss_combs -= get_above_limit(data)
|
407
|
+
end
|
408
|
+
matching_file_size=get_size({:cmb_length=>data[:cmb_length],:combinations=>poss_combs}){}
|
409
|
+
else
|
410
|
+
poss_combs=0
|
411
|
+
matching_file_size={:bytes=>0,:kilo=>0,:mega=>0,:giga=>0,:tera=>0,:peta=>0}
|
412
|
+
dataB=data.clone
|
413
|
+
data[:write_cmbs].each do |n|
|
414
|
+
dataB[:cmb_length]=n
|
415
|
+
current_combs=get_combinations(dataB)
|
416
|
+
poss_combs +=current_combs
|
417
|
+
unless data[:match_limit].nil?
|
418
|
+
poss_combs -= get_above_limit(dataB)
|
419
|
+
current_combs -= get_above_limit(dataB)
|
420
|
+
end
|
421
|
+
get_size({:cmb_length=>n,:combinations=>current_combs})do |sizes|
|
422
|
+
sizes.each do |key,value|
|
423
|
+
matching_file_size[key] +=value
|
424
|
+
end
|
425
|
+
matching_file_size[:bytes]=0 if matching_file_size[:kilo] >= 1
|
426
|
+
end
|
427
|
+
end
|
428
|
+
end
|
429
|
+
puts "Possible #{data[:type]} combinations #{poss_combs}."
|
430
|
+
size_string="File size:"
|
431
|
+
matching_file_size.each do |key,value|
|
432
|
+
next if value == 0
|
433
|
+
size_string += " #{"%.2f"% value}#{key.capitalize}#{'Bytes' if key != :bytes}"
|
434
|
+
end
|
435
|
+
puts size_string
|
436
|
+
puts "Do you wish to continue ?"
|
437
|
+
puts "y|Y n|N"
|
438
|
+
return gets.chomp
|
439
|
+
|
440
|
+
elsif data[:file_append]
|
441
|
+
return "y"
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
def self.multi_length_matching(data)
|
446
|
+
dataB=data.clone
|
447
|
+
i=0
|
448
|
+
while i < data[:cmb_length].length
|
449
|
+
dataB[:cmb_length] = data[:cmb_length][i]
|
450
|
+
dataB[:characters]=data[:characters].clone
|
451
|
+
matching_combinations(dataB)
|
452
|
+
i+=1
|
453
|
+
end
|
454
|
+
end
|
455
|
+
|
456
|
+
def self.multi_length_unique(data)
|
457
|
+
dataB=data.clone
|
458
|
+
i=0
|
459
|
+
while i < data[:cmb_length].length
|
460
|
+
dataB[:cmb_length] = data[:cmb_length][i]
|
461
|
+
dataB[:characters]=data[:characters].clone
|
462
|
+
unique_combinations(dataB)
|
463
|
+
i+=1
|
464
|
+
end
|
465
|
+
end
|
466
|
+
|
467
|
+
def self.combinations(data)
|
468
|
+
case data[:type]
|
469
|
+
when "matching"
|
470
|
+
if data[:cmb_length].length == 1
|
471
|
+
data[:cmb_length]=data[:cmb_length][0]
|
472
|
+
matching_combinations(data)
|
473
|
+
elsif data[:piped]
|
474
|
+
multi_length_matching(data)
|
475
|
+
else
|
476
|
+
data[:file_append]=false
|
477
|
+
data[:write_cmbs]=data[:cmb_length].clone
|
478
|
+
multi_length_matching(data)
|
479
|
+
end
|
480
|
+
|
481
|
+
when "unique"
|
482
|
+
if data[:cmb_length].length == 1
|
483
|
+
data[:cmb_length]=data[:cmb_length].first
|
484
|
+
unique_combinations(data)
|
485
|
+
elsif data[:piped]
|
486
|
+
multi_length_unique(data)
|
487
|
+
else
|
488
|
+
data[:file_append]=false
|
489
|
+
data[:write_cmbs]=data[:cmb_length].clone
|
490
|
+
multi_length_unique(data)
|
491
|
+
end
|
492
|
+
else
|
493
|
+
puts "Invalid combination type"
|
494
|
+
exit
|
495
|
+
end
|
496
|
+
end
|
497
|
+
end
|
Binary file
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'phoenix_password/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "phoenix_password"
|
8
|
+
spec.version = PhoenixPassword::VERSION
|
9
|
+
spec.authors = ["Spiros Avlonitis"]
|
10
|
+
spec.email = ["spirosa84@hotmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{PhoenixPassword is an all purpose password genrator.}
|
13
|
+
spec.description = %q{Phoenix password generator provides you with several options for generating passwords, which characters are to be used,combination length,character uniqueness etc.}
|
14
|
+
spec.homepage = "https://github.com/spirosavlonitis/phoenix_password"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
26
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.5"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: phoenix_password
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Spiros Avlonitis
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '12.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '12.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.5'
|
55
|
+
description: Phoenix password generator provides you with several options for generating
|
56
|
+
passwords, which characters are to be used,combination length,character uniqueness
|
57
|
+
etc.
|
58
|
+
email:
|
59
|
+
- spirosa84@hotmail.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- ".rspec"
|
66
|
+
- ".travis.yml"
|
67
|
+
- CODE_OF_CONDUCT.md
|
68
|
+
- Gemfile
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- bin/console
|
73
|
+
- bin/setup
|
74
|
+
- lib/phoenix_password.rb
|
75
|
+
- lib/phoenix_password/version.rb
|
76
|
+
- phoenix_password-0.1.0.gem
|
77
|
+
- phoenix_password.gemspec
|
78
|
+
homepage: https://github.com/spirosavlonitis/phoenix_password
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.6.11
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: PhoenixPassword is an all purpose password genrator.
|
102
|
+
test_files: []
|