Class: Unisec::Confusables
- Inherits:
-
Object
- Object
- Unisec::Confusables
- Defined in:
- lib/unisec/confusables.rb
Overview
Operations about Unicode confusable characters (homoglyphs).
Class Method Summary collapse
-
.list(chr, map: true) ⇒ Array<String>
List confusables characters for a given character.
-
.list_display(chr, map: true) ⇒ Object
Display a CLI-friendly output listing all confusables corresponding to a character (code point).
-
.randomize(str) ⇒ String
Replace all characters with random confusables when possible.
-
.randomize_display(str) ⇒ Object
Display a CLI-friendly output of a string where characters are replaces with random confusables.
Class Method Details
.list(chr, map: true) ⇒ Array<String>
List confusables characters for a given character
16 17 18 |
# File 'lib/unisec/confusables.rb', line 16 def self.list(chr, map: true) Unicode::Confusable.list(chr, map) end |
.list_display(chr, map: true) ⇒ Object
Display a CLI-friendly output listing all confusables corresponding to a character (code point)
23 24 25 26 27 28 29 |
# File 'lib/unisec/confusables.rb', line 23 def self.list_display(chr, map: true) Confusables.list(chr, map: map).each do |confu| puts "#{Properties.char2codepoint(confu).ljust(9)} #{confu.ljust(4)} " \ "#{TwitterCldr::Shared::CodePoint.get(confu.codepoints.first).name}" end nil end |
.randomize(str) ⇒ String
Replace all characters with random confusables when possible.
38 39 40 41 42 43 44 45 |
# File 'lib/unisec/confusables.rb', line 38 def self.randomize(str) out = '' str.each_char do |chr| confu = Confusables.list(chr, map: false).sample out += confu.nil? ? chr : confu end out end |
.randomize_display(str) ⇒ Object
Display a CLI-friendly output of a string where characters are replaces with random confusables
49 50 51 52 53 |
# File 'lib/unisec/confusables.rb', line 49 def self.randomize_display(str) display = ->(key, value) { puts Paint[key, :red, :bold].ljust(23) + " #{value}" } display.call('Original:', str) display.call('Transformed:', Unisec::Confusables.randomize(str)) end |