App-mimic

 view release on metacpan or  search on metacpan

bin/mimic  view on Meta::CPAN

our $DATE = '2015-10-25'; # DATE
our $VERSION = '0.01'; # VERSION

# IFUNBUILT
# use strict;
# END IFUNBUILT

use Getopt::Long::EvenLess qw(GetOptions);

my $mode = 'mimic';
my $percentage = 1;

my $sh = "\x{02591}"; # shade character

sub _list {
    require Unicode::Homoglyph;

    my $all_hgs = \@Unicode::Homoglyph::Homoglyphs;

    for my $hg (@$all_hgs) {
        print $sh, (map {$_, $sh} sort keys %$hg), "\n";

bin/mimic  view on Meta::CPAN

                $asciis{$_} = $ascii;
            }
        }
    }

    my $re;
    if ($mode eq 'mimic') {
        $re = "(?:" . join("|", map {quotemeta} sort keys %uni_homoglyphs) . ")";
        $re = qr/$re/o;
        while (<>) {
            s/($re)/rand()*100 < $percentage ?
                $uni_homoglyphs{$1}[rand()*@{ $uni_homoglyphs{$1} }] : $1/eg;
            print;
        }
    } else {
        $re = "(?:" . join("|", map {sprintf("\\x{%04X}", ord($_))} sort keys %asciis). ")";
        $re = qr/$re/o;
        if ($mode eq 'reverse') {
            while (<>) {
                s/($re)/$asciis{$1}/eg;
                print;

bin/mimic  view on Meta::CPAN

binmode(STDIN , ":utf8");
binmode(STDOUT, ":utf8");
GetOptions(
    '--help|h' => sub {
        print <<'_';
Usage: mimic [options]

Options:
  -h, --help            show this help message and exit
  -m CHANCE, --me-harder=CHANCE
                        replacement percent
  -e CHAR, --explain=CHAR
                        show a char's homoglyphs
  -l, --list            show all homoglyphs
  -c, --check           check input for suspicious chars
  -r, --reverse         reverse operation, clean a mimicked file
_
        exit 0;
    },
    'me-harder|m=s' => sub {
        $percentage = $_[1];
    },
    'explain|e=s' => sub {
        _explain($_[1]);
        exit 0;
    },
    'list|l' => sub {
        _list();
        exit 0;
    },
    'check|c' => sub {



( run in 0.386 second using v1.01-cache-2.11-cpan-05162d3a2b1 )