Class: BruteTools::BruteforceGenerator
- Inherits:
-
Object
- Object
- BruteTools::BruteforceGenerator
- Defined in:
- lib/brutetools/bruteforce_generator.rb
Instance Method Summary collapse
-
#initialize(alphabet, start = 0) ⇒ BruteforceGenerator
constructor
A new instance of BruteforceGenerator.
- #next ⇒ Object
Constructor Details
#initialize(alphabet, start = 0) ⇒ BruteforceGenerator
Returns a new instance of BruteforceGenerator.
3 4 5 6 7 8 9 10 |
# File 'lib/brutetools/bruteforce_generator.rb', line 3 def initialize(alphabet, start = 0) @alphabet = alphabet @alphabet = @alphabet.split('') if @alphabet.kind_of? String @start = start @start = @alphabet[0] * @start if @start.kind_of? Numeric @length = @start.length @buff = @start.split('').map{ |e| @alphabet.index(e) } end |
Instance Method Details
#next ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/brutetools/bruteforce_generator.rb', line 12 def next return nil if @buff.all?{ |o| o == @alphabet.size - 1 } poped = [] poped << @buff.pop while @buff.last == @alphabet.size - 1 @buff[-1] += 1 @buff += ([0] * poped.length) @buff.map{ |i| @alphabet[i] }.join end |