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
18 19 20 |
# File 'lib/unisec/confusables.rb', line 18 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)
25 26 27 28 29 30 31 |
# File 'lib/unisec/confusables.rb', line 25 def self.list_display(chr, map: true) Confusables.list(chr, map: map).each do |confu| puts "#{Utils::String.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.
40 41 42 43 44 45 46 47 |
# File 'lib/unisec/confusables.rb', line 40 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
51 52 53 54 55 |
# File 'lib/unisec/confusables.rb', line 51 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 |