-1

我正在使用可以选择对链接进行编码的 Flash 播放器。我可以使用下面的代码成功地对它们进行编码,但我找不到解码回来的方法,而且它们不提供该选项。

链接正在与播放器一起使用,当我需要编辑它们时,我的问题就开始了。我看到的不是普通链接,而是编码版本。

<?php
    function uppod_enc_replace($str){
            $uppod_tmp_a=Array('G','d','R','0','M','Y','4','v','6','u','t','i','f','c','s','l','B','5','n','2','V','Z','J','m','L','=');
            $uppod_tmp_b=Array('1','w','Q','o','9','U','a','N','x','D','X','7','z','H','y','3','e','g','T','W','b','8','k','I','p','r');
            $uppod_tmp=$str;
            $uppod_tmp_from=$uppod_tmp_a;
            $uppod_tmp_to=$uppod_tmp_b;

            for($i=0;$i<sizeof($uppod_tmp_from);$i++){

                $uppod_tmp=uppod_enc_replace_ab($uppod_tmp_from[$i],$uppod_tmp_to[$i],$uppod_tmp);
            }
            return $uppod_tmp;
    }
    function uppod_enc_replace_ab($a,$b,$tmp){
            $tmp=preg_replace('/'.$a.'/','___',$tmp);
            $tmp=preg_replace('/'.$b.'/',$a,$tmp);
            $tmp=preg_replace('/___/',$b,$tmp);
            return $tmp;
    }
    function uppod_encode($str,$lkey=''){
            $tmp=uppod_enc_replace(base64_encode($str));
            if($lkey!=''){
                    $tmpn=rand(0,strlen($tmp));
                    $tmp=substr($tmp,0,$tmpn).uppod_enc_replace(base64_encode($lkey)).substr($tmp,$tmpn);
            }
            return $tmp;
    }
?>

到目前为止我已经尝试过:

switching places 
                    $uppod_tmp_from=$uppod_tmp_a;
                    $uppod_tmp_to=$uppod_tmp_b;
changing base64_encode to base64_decode 

测试:

stackoverflow.com
encodes to:
HlQhUWXNwIbs8I6NwsgjVWor

changing base64_encode to base64_decode and switching places with $uppod_tmp_from=$uppod_tmp_a; $uppod_tmp_to=$uppod_tmp_b;
decodes to:
n!RB▒▒▒▒▒▒#Yj+[
4

2 回答 2

2

通过稍微修改uppod_enc_replace功能:

function uppod_enc_replace($str, $direction = 'encode'){
    $uppod_tmp_a=Array('G','d','R','0','M','Y','4','v','6','u','t','i','f','c','s','l','B','5','n','2','V','Z','J','m','L','=');
    $uppod_tmp_b=Array('1','w','Q','o','9','U','a','N','x','D','X','7','z','H','y','3','e','g','T','W','b','8','k','I','p','r');
    $uppod_tmp=$str;
    if($direction == 'encode'){
        $uppod_tmp_from = $uppod_tmp_a;
        $uppod_tmp_to = $uppod_tmp_b;
    }else{
        $uppod_tmp_to = $uppod_tmp_a;
        $uppod_tmp_from = $uppod_tmp_b;
    }

    for($i=0;$i<sizeof($uppod_tmp_from);$i++){
        $uppod_tmp=uppod_enc_replace_ab($uppod_tmp_from[$i],$uppod_tmp_to[$i],$uppod_tmp);
    }
    return $uppod_tmp;
}

解码函数将如下所示:

function uppod_decode($str, $lkey = ''){
    if($lkey!=''){
        $eKey = uppod_enc_replace(base64_decode($lkey));
        $str = str_replace($eKey, '', $str);
    }
    return base64_decode(uppod_enc_replace($str, 'decode'));
}

测试用例:

$url = 'http://www.google.com/';

$encoded = uppod_encode($url);
$decoded = uppod_decode($encoded);

var_dump($decoded);

$key = base64_encode('p45sw0rd');

$encoded2 = uppod_encode($url, $key);
$decoded2 = uppod_decode($encoded2, $key);

var_dump($decoded2);

// outputs:
// string(22) "http://www.google.com/"
// string(22) "http://www.google.com/"
于 2012-10-20T11:24:04.490 回答
0

编码脚本正在做:

  1. base64_encode()
  2. 切换一些字母

因此,要对其进行解码,您需要:

  1. 换回字母
  2. base64_decode() 之后
于 2012-10-20T11:06:01.707 回答