-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathAAEncoder.php
More file actions
117 lines (112 loc) · 4.84 KB
/
Copy pathAAEncoder.php
File metadata and controls
117 lines (112 loc) · 4.84 KB
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
<?php
/**
* Class AAEncoder
* @author Andrey Izman <[email protected]>
* @link https://github.com/mervick/php-aaencoder
* @license MIT
*/
/**
* Class AAEncoder
*/
class AAEncoder
{
/**
* Encode any JavaScript program to Japanese style emoticons (^_^)
* @param string $js
* @param int $level [optional]
* @return string
*/
public static function encode($js, $level=0)
{
$result = "゚ω゚ノ= /`m´)ノ ~┻━┻ //*´∇`*/ ['_']; o=(゚ー゚) =_=3; c=(゚Θ゚) =(゚ー゚)-(゚ー゚); " .
"(゚Д゚) =(゚Θ゚)= (o^_^o)/ (o^_^o);" .
"(゚Д゚)={゚Θ゚: '_' ,゚ω゚ノ : ((゚ω゚ノ==3) +'_') [゚Θ゚] " .
",゚ー゚ノ :(゚ω゚ノ+ '_')[o^_^o -(゚Θ゚)] " .
",゚Д゚ノ:((゚ー゚==3) +'_')[゚ー゚] }; (゚Д゚) [゚Θ゚] =((゚ω゚ノ==3) +'_') [c^_^o];" .
"(゚Д゚) ['c'] = ((゚Д゚)+'_') [ (゚ー゚)+(゚ー゚)-(゚Θ゚) ];" .
"(゚Д゚) ['o'] = ((゚Д゚)+'_') [゚Θ゚];" .
"(゚o゚)=(゚Д゚) ['c']+(゚Д゚) ['o']+(゚ω゚ノ +'_')[゚Θ゚]+ ((゚ω゚ノ==3) +'_') [゚ー゚] + " .
"((゚Д゚) +'_') [(゚ー゚)+(゚ー゚)]+ ((゚ー゚==3) +'_') [゚Θ゚]+" .
"((゚ー゚==3) +'_') [(゚ー゚) - (゚Θ゚)]+(゚Д゚) ['c']+" .
"((゚Д゚)+'_') [(゚ー゚)+(゚ー゚)]+ (゚Д゚) ['o']+" .
"((゚ー゚==3) +'_') [゚Θ゚];(゚Д゚) ['_'] =(o^_^o) [゚o゚] [゚o゚];" .
"(゚ε゚)=((゚ー゚==3) +'_') [゚Θ゚]+ (゚Д゚) .゚Д゚ノ+" .
"((゚Д゚)+'_') [(゚ー゚) + (゚ー゚)]+((゚ー゚==3) +'_') [o^_^o -゚Θ゚]+" .
"((゚ー゚==3) +'_') [゚Θ゚]+ (゚ω゚ノ +'_') [゚Θ゚]; " .
"(゚ー゚)+=(゚Θ゚); (゚Д゚)[゚ε゚]='\\\\'; " .
"(゚Д゚).゚Θ゚ノ=(゚Д゚+ ゚ー゚)[o^_^o -(゚Θ゚)];" .
"(o゚ー゚o)=(゚ω゚ノ +'_')[c^_^o];" .
"(゚Д゚) [゚o゚]='\\\"';" .
"(゚Д゚) ['_'] ( (゚Д゚) ['_'] (゚ε゚+" .
"/*´∇`*/(゚Д゚)[゚o゚]+ ";
for ($i = 0, $len = mb_strlen($js); $i < $len; $i++) {
$code = unpack('N', mb_convert_encoding(mb_substr($js, $i, 1, 'UTF-8'), 'UCS-4BE', 'UTF-8'))[1];
$text = '(゚Д゚)[゚ε゚]+';
if ($code <= 127) {
$text .= preg_replace_callback('/([0-7])/', function($match) use ($level) {
$byte = intval($match[1]);
return ($level ? self::randomize($byte, $level) : self::$bytes[$byte]) . '+';
}, decoct($code));
}
else {
$hex = str_split(substr('000' . dechex($code), -4));
$text .= "(o゚ー゚o)+ ";
for ($i = 0, $len = count($hex); $i < $len; $i++) {
$text .= self::$bytes[hexdec($hex[$i])] . '+ ';
}
}
$result .= $text;
}
$result .= "(゚Д゚)[゚o゚]) (゚Θ゚)) ('_');";
return $result;
}
/**
* @var array
*/
protected static $bytes = [
"(c^_^o)",
"(゚Θ゚)",
"((o^_^o) - (゚Θ゚))",
"(o^_^o)",
"(゚ー゚)",
"((゚ー゚) + (゚Θ゚))",
"((o^_^o) +(o^_^o))",
"((゚ー゚) + (o^_^o))",
"((゚ー゚) + (゚ー゚))",
"((゚ー゚) + (゚ー゚) + (゚Θ゚))",
"(゚Д゚) .゚ω゚ノ",
"(゚Д゚) .゚Θ゚ノ",
"(゚Д゚) ['c']",
"(゚Д゚) .゚ー゚ノ",
"(゚Д゚) .゚Д゚ノ",
"(゚Д゚) [゚Θ゚]",
];
/**
* @param int $byte
* @param int $level
* @return string
*/
protected static function randomize($byte, $level)
{
$random = [
0 => [['+0', '-0'], ['+1', '-1'], ['+3', '-3'], ['+4', '-4']],
1 => [['+1', '-0'], ['+3', '-1', '-1'], ['+4', '-3']],
2 => [['+3', '-1'], ['+4', '-3', '+1'], ['+3', '+3', '-4']],
3 => [['+3', '-0'], ['+4', '-3', '+1', '+1']],
4 => [['+4', '+0'], ['+1', '+3'], ['+4', '-0']],
5 => [['+3', '+1', '+1'], ['+4', '+1'], ['+3', '+3', '-1']],
6 => [['+3', '+3'], ['+4', '+1', '+1'], ['+4', '+3', '-1']],
7 => [['+3', '+4'], ['+3', '+3', '+1'], ['+4', '+4', '-1']],
];
while ($level--) {
$byte = preg_replace_callback('/[0-7]/', function($match) use ($random) {
$numbers = $random[$match[0]][mt_rand(0, count($random[$match[0]]) - 1)];
shuffle($numbers);
$byte = ltrim(implode('', $numbers), '+');
return "($byte)";
}, $byte);
}
$byte = str_replace('+-', '-', $byte);
return str_replace(array_keys(self::$bytes), self::$bytes, $byte);
}
}