-
Notifications
You must be signed in to change notification settings - Fork 34
/
eyes_dropper.pl
executable file
·166 lines (140 loc) · 4.13 KB
/
eyes_dropper.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/perl
# Daniel "Trizen" Șuteu
# Created on: 01 July 2011 (00:01 AM)
# Latest edit on: 24 December 2011
# Transforms a phrase in a Perl regex, using only punctuation characters.
use strict;
use warnings;
use List::Util ('shuffle');
my $phrase;
my @content;
my %chars_table;
my $quote = 0;
my $compact = 0;
my $exec_code = 0;
my $eval_code = 0;
my $brake_after = 8;
my @symbols = shuffle(qw'^ + " * [ & | < ` / { > ; : ( ) ? - = } @ . ] $ _ % !', (',', '#'));
foreach my $arg (@ARGV) {
if (-f $arg) {
open my $fh, '<', $arg or die $!;
sysread $fh, $phrase, -s $arg;
close $fh;
next;
}
if (substr($arg, 0, 1) eq '-') {
if ($arg =~ /^-+(?:h|help|usage|\?)$/) {
usage();
}
elsif ($arg =~ /^-+exec(?:ute)?$/) {
$exec_code = 1;
}
elsif ($arg =~ /^-+e(?:val)?$/) {
$eval_code = 1;
}
elsif ($arg =~ /^-+e(?:val)?2$/) {
$eval_code = 2;
}
elsif ($arg =~ /^-+c(?:ompact)?$/) {
$compact = 1;
}
elsif ($arg =~ /^-+q(?:uote(?:meta)?)?$/) {
$quote = 1;
}
elsif ($arg =~ /^-+(\d+)$/) {
$brake_after = $1;
}
}
}
unless (defined $phrase) {
my @words = grep { substr($_, 0, 1) ne '-' } @ARGV;
$phrase =
@words
? join(' ', @words)
: 'Just another Perl hacker,';
}
sub usage {
print "
usage: $0 [...]
\noptions:
/my/file : encode text from a file
-num : newline before N chars (ex: -10)
-exec : execute code (unix only)
-print : print text using single quotes (default)
-eval : eval code using single quotes
-eval2 : eval code using a code block
-compact : compact code (not for files)
-quote : quotemeta special characters\n\n";
exit;
}
my $char_to_quote = $quote ? qr/['\\{}]/ : qr/['\\]/;
my $action;
if ($exec_code) {
$action = q[$x='/tmp/.x';open my $fh,">$x";system qq|perl $x| if print $fh];
}
elsif ($eval_code) {
$action = 'eval';
}
else {
$action = 'print';
}
if ($compact) {
$phrase =~ s/~/\\~/g;
$phrase = "$action q~$phrase\n";
}
elsif (defined $action and not $eval_code == 2) {
push @content, qq[use re 'eval';'\n'=~('(?{'.];
$phrase = "$action <<'Q_M';\n$phrase\nQ_M\n";
}
elsif (defined $action and $eval_code == 2) {
push @content, q[''=~('(?{'.];
$phrase = "${action} {$phrase}";
}
my %memoize;
LOOP_1: foreach my $letter (split(//, $phrase, 0)) {
if (exists $chars_table{$letter}) {
next LOOP_1 if $chars_table{$letter} eq 'Not found!';
$compact ? push(@content, $chars_table{$letter})
: (
ref($chars_table{$letter}) eq 'ARRAY' ? push(@content, "('$chars_table{$letter}[0]'^'$chars_table{$letter}[1]').")
: push(@content, $chars_table{$letter})
);
next LOOP_1;
}
foreach my $simb (@symbols) {
foreach my $chr (@symbols) {
next if exists $memoize{$simb . $chr};
next if exists $memoize{$chr . $simb};
++$memoize{$simb . $chr};
++$memoize{$chr . $simb};
$chars_table{$simb ^ $chr} = [$simb, $chr];
if (exists $chars_table{$letter}) {
if ($compact) {
push @content, [$simb, $chr];
next LOOP_1;
}
else {
push @content, "('${simb}'^'${chr}').";
next LOOP_1;
}
}
}
}
if (not $compact) {
$letter = quotemeta $letter if $letter =~ /$char_to_quote/o;
push @content, "('${letter}').";
$chars_table{$letter} = "('${letter}').";
}
else {
$chars_table{$letter} = 'Not found!';
}
}
if ($compact) {
print q[''=~('(?{'.('], (map { $content[$_][0] } 0 .. $#content), q['^'], (map { $content[$_][1] } 0 .. $#content), q[').'~})');], "\n";
}
else {
for (my $i = $brake_after - 1 ; $i <= $#content ; $i += $brake_after) {
splice @content, $i, 0, "\n";
}
print @content, "'})');\n";
}