Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
116 lines (104 sloc) 4.07 KB
# hexchat-homoglyph.pl
# Converts text into visually similar yet different characters.
# Author: William Woodruff
# ------------------------
# This code is licensed by William Woodruff under the MIT License.
# http://opensource.org/licenses/MIT
use strict;
use warnings;
use utf8;
use Xchat qw(:all);
my $PLUGIN_NAME = 'homoglyph';
my $PLUGIN_VERS = '1.1';
my $PLUGIN_DESC = 'converts characters into visually similar glyphs';
my %GLYPHS = (
'!' => ['!', 'ǃ', ''],
'"' => ['"', '״', '', ''],
'$' => ['$', ''],
'%' => ['%', ''],
'&' => ['&', ''],
'(' => ['(', '', ''],
')' => [')', '', ''],
'*' => ['*', '', ''],
'+' => ['+', ''],
',' => [',', '', ''],
'-' => ['-', '', '�-'],
'.' => ['.', '٠', '۔', '܁', '܂', '', '', '', '', ''],
'/' => ['/', '̸', '', '', '', '', '', '', ''],
'0' => ['0', 'O', 'o', 'Ο', 'ο', 'О', 'о', 'Օ', '', ''],
'1' => ['1', 'I', 'ا', ''],
'2' => ['2', ''],
'3' => ['3', ''],
'4' => ['4', ''],
'5' => ['5', ''],
'6' => ['6', ''],
'7' => ['7', ''],
'8' => ['8', 'Ց', ''],
'9' => ['9', ''],
':' => [':', '։', '܃', '܄', '', '', ''],
';' => [';', ';', ''],
'<' => ['<', '', ''],
'=' => ['=', ''],
'>' => ['>', '', ''],
'?' => ['?', '', '¿'],
'@' => ['@', ''],
'[' => ['[', ''],
'\\' => ['\\', ''],
']' => [']', ''],
'^' => ['^', ''],
'_' => ['_', '_'],
'`' => ['`', ''],
'a' => ['A', 'a', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'à', 'á', 'â', 'ã', 'ä', 'å', 'ɑ', 'Α', 'α', 'а', '', '', ''],
'b' => ['B', 'b', 'ß', 'ʙ', 'Β', 'β', 'В', 'Ь', '', '', '', ''],
'c' => ['C', 'c', 'ϲ', 'Ϲ', 'С', 'с', '', '', '', '', ''],
'd' => ['D', 'd', 'Ď', 'ď', 'Đ', 'đ', 'ԁ', 'ժ', '', '', '', '', ''],
'e' => ['E', 'e', 'È', 'É', 'Ê', 'Ë', 'é', 'ê', 'ë', 'Ē', 'ē', 'Ĕ', 'ĕ', 'Ė', 'ė', 'Ę', 'Ě', 'ě', 'Ε', 'Е', 'е', '', '', ''],
'f' => ['F', 'f', 'Ϝ', '', ''],
'g' => ['G', 'g', 'ɡ', 'ɢ', 'Ԍ', 'ն', '', '', ''],
'h' => ['H', 'h', 'ʜ', 'Η', 'Н', 'һ', '', '', ''],
'i' => ['I', 'i', 'l', 'ɩ', 'Ι', 'І', 'і', 'ا', '', '', '', '', '', ''],
'j' => ['J', 'j', 'ϳ', 'Ј', 'ј', 'յ', '', '', ''],
'k' => ['K', 'k', 'Κ', 'κ', 'К', '', '', '', '', ''],
'l' => ['L', 'l', 'ʟ', 'ι', 'ا', '', '', '', '', ''],
'm' => ['M', 'm', 'Μ', 'Ϻ', 'М', '', '', '', '', '', ''],
'n' => ['N', 'n', 'ɴ', 'Ν', '', ''],
'o' => ['0', 'O', 'o', 'Ο', 'ο', 'О', 'о', 'Օ', '', ''],
'p' => ['P', 'p', 'Ρ', 'ρ', 'Р', 'р', '', '', ''],
'q' => ['Q', 'q', '', '', '', ''],
'r' => ['R', 'r', 'ʀ', 'Ի', '', '', '', ''],
's' => ['S', 's', 'Ѕ', 'ѕ', 'Տ', '', '', '𐐠', '', ''],
't' => ['T', 't', 'Τ', 'τ', 'Т', '', '', ''],
'u' => ['U', 'u', 'μ', 'υ', 'Ա', 'Ս', '', '', ''],
'v' => ['V', 'v', 'ν', 'Ѵ', 'ѵ', '', '', '', '', ''],
'w' => ['W', 'w', 'ѡ', '', '', ''],
'x' => ['X', 'x', 'Χ', 'χ', 'Х', 'х', '', '', '', ''],
'y' => ['Y', 'y', 'ʏ', 'Υ', 'γ', 'у', 'Ү', '', ''],
'z' => ['Z', 'z', 'Ζ', '', '', ''],
'{' => ['{', ''],
'|' => ['|', 'ǀ', 'ا', ''],
'}' => ['}', ''],
'~' => ['~', '', '']
);
register($PLUGIN_NAME, $PLUGIN_VERS, $PLUGIN_DESC, \&on_unload);
Xchat::printf("Loaded %s version %s", $PLUGIN_NAME, $PLUGIN_VERS);
sub on_unload {
Xchat::printf("%s version %s unloaded.", $PLUGIN_NAME, $PLUGIN_VERS);
}
hook_command('hg', \&homoglyphify, {help_text => "Usage: /hg <text> to homoglyphify the given text."});
sub homoglyphify {
if (defined $_[1][1]) {
my $text = lc($_[1][1]);
my $result = '';
foreach (split //, $text) {
if (exists $GLYPHS{$_}) {
my @glyphs = @{$GLYPHS{$_}};
$result .= $glyphs[rand @glyphs];
}
else {
$result .= $_;
}
}
command("say $result");
}
return EAT_ALL;
}