Module: Ronin::Support::Text::Homoglyph
- Defined in:
- lib/ronin/support/text/homoglyph.rb,
lib/ronin/support/text/homoglyph/table.rb,
lib/ronin/support/text/homoglyph/exceptions.rb
Overview
Generates homoglyph typos.
Core-Ext Methods
Defined Under Namespace
Constant Summary collapse
- DATA_DIR =
Path to the
data/text/homoglyphs/
directory. File.(File.join(__dir__,'..','..','..','..','data','text','homoglyphs'))
- ASCII =
ASCII only homoglyph rules.
Table.load_file(File.join(DATA_DIR,'ascii.txt'))
- GREEK =
Greek homoglyph rules.
Table.load_file(File.join(DATA_DIR,'greek.txt'))
- CYRILLIC =
Cyrillic homoglyph rules.
Table.load_file(File.join(DATA_DIR,'cyrillic.txt'))
- PUNCTUATION =
Punctuation/symbol homoglyph rules.
Table.load_file(File.join(DATA_DIR,'punctuation.txt'))
- LATIN_NUMBERS =
Latin numeral homoglyph rules.
Table.load_file(File.join(DATA_DIR,'latin_numbers.txt'))
- FULL_WIDTH =
Full-width homoglyph rules.
Table.load_file(File.join(DATA_DIR,'full_width.txt'))
- DEFAULT =
All homoglyph rules combined.
GREEK + CYRILLIC + PUNCTUATION + LATIN_NUMBERS + FULL_WIDTH
- CHAR_SETS =
Homoglyph rules grouped by character set.
{ ascii: ASCII, greek: GREEK, cyrillic: CYRILLIC, punctuation: PUNCTUATION, latin_numbers: LATIN_NUMBERS, full_width: FULL_WIDTH }
Class Method Summary collapse
-
.each_substitution(word, char_set: nil) {|homoglyph| ... } ⇒ Enumerator
Enumerates over every homoglyph variation of the given word.
-
.substitute(word, char_set: nil) ⇒ String
Returns a random homoglyph substitution of the given word.
-
.table(char_set = nil) ⇒ Table
Looks up a homoglyph character set.
Class Method Details
.each_substitution(word, char_set: nil) {|homoglyph| ... } ⇒ Enumerator
Enumerates over every homoglyph variation of the given word.
The character set to use.
143 144 145 |
# 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) ⇒ String
Returns a random homoglyph substitution of the given word.
The character set to use.
115 116 117 |
# 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) ⇒ Table
Looks up a homoglyph character set.
The character set name.
83 84 85 86 87 88 89 90 91 |
# 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 |