Skip to content

Instantly share code, notes, and snippets.

@wcypierre
Created July 24, 2013 02:21
Show Gist options
  • Save wcypierre/6067652 to your computer and use it in GitHub Desktop.
Save wcypierre/6067652 to your computer and use it in GitHub Desktop.
#!/usr/bin/php
<?php
// http://w3.tbd.my/thread-14121-post-163114.html#pid163114
//$key = "3"; // 3 = 51, "=" = 61
//echo "Original Algo: \n";
//var_dump(algo2($key));
//$var = base64_encode(str_rot13(implode('.', algo2($key))));
//$var = algo2($key);
$var = "MSwxLDU1LjgsMS41LDEzLjEsMSwxMy41NSwzNC4xLDAsMC41LDEzLjEsMCw1NS4xLDIsMS4zLDIuMSwx​LDEzLjEsMCw1LjEsMCwxLjMsMi41NSwzNC4xLDAsMS4xLDEsOC4xLDEsMTMuMywyLjgsMzQuNSwx";
$test = str_rot13(base64_decode($var));
$arr = explode(".", $test);
for($i = 0; $i < sizeof($arr); $i++)
{
$encode_str[] = explode(",", $arr[$i]);
}
for($let_i = 0; $let_i < sizeof($encode_str); $let_i++)
{
for($let_j = 0; $let_j < sizeof($encode_str[$let_i]); $let_j++)
{
$encode_str[$let_i][$let_j] = rev_algo1((int)$encode_str[$let_i][$let_j]);
}
}
for($let_i = 0; $let_i < sizeof($encode_str); $let_i++)
{
$ascii_str[] = implode('', $encode_str[$let_i]);
}
for($index = 0; $index < sizeof($ascii_str); $index++)
{
echo chr($ascii_str[$index]);
}
function algo2($v){
$b = array();
for($i = 0;$i < strlen($v); $i++){
$b[] = ord($v[$i]);
}
$c = array();
$d = array();
$e = array();
for($i = 0;$i < sizeof($b); $i++){
$temp = "";
$str = (string) $b[$i];
for($j = 0;$j < strlen($str);$j++ ){
$d[] = algo1((int) $str[$j]);
}
$c[] = implode(',',$d);
$e[] = $d;
unset($d);
}
//return $c;
return base64_encode(str_rot13(implode('.',$c)));
}
function algo1($v){
if(is_int($v)){
switch($v){
case 0:
return 0;
break;
case 1:
return 1;
break;
case 2:
return 2;
break;
default:
$tempa = 1;
$tempb = 2;
for($i = 2; $i < $v; $i++){
$tem = $tempb; // tem = b
$tempb = $tempa + $tempb; // a + b
$tempa = $tem; // a = b
}
break;
}
return $tempb;
}
return false;
}
function rev_algo1($v){
if(is_int($v)){
switch($v){
case 0:
return 0;
break;
case 1:
return 1;
break;
case 2:
return 2;
break;
default:
$count = 0;
$tempa = 1;
$tempb = 2;
for($i = 2; $i < $v; $i++){
$tem = $tempb; // tem = b
$tempb = $tempa + $tempb; // a + b
$tempa = $tem; // a = b
$count++;
if($tempb == $v)
{
$count = $count + 2;
$i = $v;
return $count;
}
}
break;
}
return $count;
}
return false;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment