Parent

Included Modules

Wordlist::List

Attributes

max_length[RW]

Maximum length of words

min_length[RW]

Minimum length of words

Public Class Methods

new(options={},&block) click to toggle source

Creates a new List object with the given options. If a block is given, it will be passed the newly created List object.

options may include the following keys:

:max_length:The maximum length of words produced by the list.
:min_length:The minimum length of words produced by the list.
# File lib/wordlist/list.rb, line 25
    def initialize(options={},&block)
      @mutators = []

      @max_length = nil
      @min_length = 0

      if options[:max_length]
        @max_length = options[:max_length]
      end

      if options[:min_length]
        @min_length = options[:min_length]
      end

      block.call(self) if block
    end

Public Instance Methods

each(&block) click to toggle source

Alias for each_mutation

each_mutation(&block) click to toggle source

Enumerates through every unique mutation, of every unique word, using the mutator rules define for the list. Every possible unique mutation will be passed to the given block.

  list.each_mutation do |word|
    puts word
  end
# File lib/wordlist/list.rb, line 101
    def each_mutation(&block)
      mutation_filter = UniqueFilter.new()

      mutator_stack = [lambda { |mutated_word|
        # skip words shorter than the minimum length
        next if mutated_word.length < @min_length

        # truncate words longer than the maximum length
        mutated_word = mutated_word[0,@max_length] if @max_length

        if mutation_filter.saw!(mutated_word)
          yield mutated_word
        end
      }]

      (@mutators.length-1).downto(0) do |index|
        mutator_stack.unshift(lambda { |word|
          prev_mutator = @mutators[index]
          next_mutator = mutator_stack[index+1]

          prev_mutator.each(word,&next_mutator)
        })
      end

      each_unique(&(mutator_stack.first))
    end
Also aliased as: each
each_unique() click to toggle source

Enumerates through every unique word in the list, passing each unique word to the given block.

  list.each_unique do |word|
    puts word
  end
# File lib/wordlist/list.rb, line 80
    def each_unique
      unique_filter = UniqueFilter.new()

      each_word do |word|
        if unique_filter.saw!(word)
          yield word
        end
      end

      unique_filter = nil
    end
each_word(&block) click to toggle source

Enumerate through every word in the list, passing each word to the given block. By default this method passes nothing to the given block.

  list.each_word do |word|
    puts word
  end
# File lib/wordlist/list.rb, line 69
    def each_word(&block)
    end
mutate(pattern,substitute=nil,&block) click to toggle source

Adds a mutation rule for the specified pattern, to be replaced using the specified substitute. If a block is given, and the substitute data omitted, then the block will be used to replace data matched by the pattern.

  list.mutate 'o', '0'

  list.mutate '0', 0x41

  list.mutate(/[oO]/) do |match|
    match.swapcase
  end
# File lib/wordlist/list.rb, line 56
    def mutate(pattern,substitute=nil,&block)
      @mutators << Mutator.new(pattern,substitute,&block)
    end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.