module Ronin::Support::Text::Homoglyph

Generates [homoglyph](homoglyphs.net/) typos.

## Core-Ext Methods

@since 1.0.0

@api public

Constants

ASCII

ASCII only homoglyph rules.

CHAR_SETS

Homoglyph rules grouped by character set.

CYRILLIC

Cyrillic homoglyph rules.

DATA_DIR

Path to the ‘data/text/homoglyphs/` directory.

DEFAULT

All homoglyph rules combined.

FULL_WIDTH

Full-width homoglyph rules.

GREEK

Greek homoglyph rules.

LATIN_NUMBERS

Latin numeral homoglyph rules.

PUNCTUATION

Punctuation/symbol homoglyph rules.

Public Class Methods

each_substitution(word, char_set: nil, &block) click to toggle source

Enumerates over every homoglyph variation of the given word.

@param [String] word

The given word to mutate.

@param [:ascii, :greek, :cyrillic, :punctuation, :latin_numbers,

      :full_width, nil] char_set
The character set to use.

@yield [homoglyph]

The given block will be passed each homoglyph variation of the given
word.

@yieldparam [String] homoglyph

A variation of the given word.

@return [Enumerator]

If no block is given, an Enumerator object will be returned.

@see Table#each_substitution @see String#each_homoglyph @see String#homoglyphs

# File lib/ronin/support/text/homoglyph.rb, line 143
def self.each_substitution(word, char_set: nil, &block)
  self.table(char_set).each_substitution(word,&block)
end
substitute(word, char_set: nil) click to toggle source

Returns a random homoglyph substitution of the given word.

@param [String] word

The given word to mutate.

@param [:ascii, :greek, :cyrillic, :punctuation, :latin_numbers,

      :full_width, nil] char_set
The character set to use.

@return [String]

A random homoglyphic variation of the given word.

@raise [ArgumentError]

Could not find any matching characters to replace in the given text.

@raise [NotViable]

No homoglyph replaceable characters were found in the String.

@see Table#substitute @see String#homoglyph

# File lib/ronin/support/text/homoglyph.rb, line 115
def self.substitute(word, char_set: nil)
  self.table(char_set).substitute(word)
end
table(char_set=nil) click to toggle source

Looks up a homoglyph character set.

@param [:ascii, :greek, :cyrillic, :punctuation, :latin_numbers,

      :full_width, nil] char_set
The character set name.

@return [Table]

The specific homoglyph character set or {DEFAULT} if no name was
given.
# File lib/ronin/support/text/homoglyph.rb, line 83
def self.table(char_set=nil)
  if char_set
    CHAR_SETS.fetch(char_set) do
      raise(ArgumentError,"unknown homoglyph character set (#{char_set.inspect}), must be #{CHAR_SETS.keys.map(&:inspect).join(', ')}")
    end
  else
    DEFAULT
  end
end