Created
January 13, 2023 15:26
-
-
Save motebaya/2c1f8a35cf5b136d4d5f6d07ae534568 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
i convert it from js to python then from python to php LOL | |
credit: github.com/motebaya | |
*/ | |
class Decoder | |
{ | |
private $content; | |
private $h; | |
private $e; | |
private $alpa = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/"; | |
public function __construct($content) | |
{ | |
$this->content = $content; | |
} | |
public function reduce($a, $b, $c) | |
{ | |
$a += array_search($b, $this->h) * ($this->e ** $c); | |
return $a; | |
} | |
public function reduces($it, $intializer) | |
{ | |
$nx = next($it); // next function in python & php is different lol | |
$value = (int)$this->reduce($intializer, $nx, 0); | |
unset($it[array_search($nx, $it)]); | |
foreach (array_slice($it, 1) as $index => $element) { | |
$value = $this->reduce($value, $element, (int)($index) + 1); | |
} | |
return $value; | |
} | |
private function chars($d, $e, $f) | |
{ | |
$g = str_split($this->alpa); | |
$this->h = array_slice($g, 0, $e); | |
$this->e = $e; | |
$i = array_slice($g, 0, $f); | |
$arr = str_split($d); | |
array_push($arr, 'skip'); // add usseles value for delete on list | |
$arr = array_reverse($arr); | |
$j = $this->reduces($arr, 0); | |
$k = ""; | |
while ($j > 0) { | |
$k = $i[$j % $f] . $k; | |
$j = (int)($j - ($j % $f)) / $f; | |
} | |
return (int)$k; | |
} | |
private function execute($h, $u, $n, $t, $e, $r) | |
{ | |
$r = ""; | |
$i = 0; | |
while ($i < strlen($h)) { | |
$s = ""; | |
while ($h[$i] != $n[(int)$e]) { | |
$s .= $h[$i]; | |
$i++; | |
} | |
for ($x = 0; $x < strlen($n); $x++) { | |
$s = str_replace( | |
$n[$x], | |
(string)$x, | |
$s | |
); | |
} | |
$r .= chr( | |
(int)$this->chars( | |
$s, | |
(int)$e, | |
10 | |
) - (int)$t | |
); | |
$i++; | |
} | |
print $r; | |
} | |
public function decode() | |
{ | |
if (preg_match('/\(\"(.*?)",(.*?),"(.*?)",(.*?),(.*?),(.*?)\)/i', $this->content, $match)) { | |
// in python use * or literal eval from ast | |
$this->execute( | |
...array_slice($match, 1) | |
); | |
// print_r($match); | |
} else { | |
die($this->content); | |
} | |
} | |
} | |
(new Decoder( | |
file_get_contents( | |
"snap.html" | |
) | |
))->decode(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment