把Python源码改成了PHP版,还在学PHP,因为两种语言有不同,调试了老半天,挖了几个坑,填了几个坑
使用 命令行解释脚本
$ php url.php
www.262235.xyz/index.php/archives/299/ -->
https://www.baidu.com/link?url=a3f48d30fc293c5e471ef23de092fddc99fdd688685fefb97e96dcc7fd825b7d3c4eabfd798bbe9d68b609937ce2c51147ad0004bc38c1
PHP语言的全局变量要在函数中 global $x, $y, $ascii, $data;
全局申明才能使用
- 重新改了函数版,和 Python就更加象了
<?php
//$ascii码表x,y位置
$ascii = [
0 => [ ' ', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/' ],
1 => [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?' ],
2 => [ '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L','M', 'N', 'O' ],
3 => [ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\',']', '^', '_' ],
4 => [ '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o' ],
5 => [ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', ' ' ]
];
//url第N个位置对应的(x,y),目前只得到80位的url
$data = [
[13, 10], [10, 1], [16, 15], [7, 6], [5, 13], [18, 9], [13, 11], [7, 12],
[10, 5], [15, 9], [15, 9], [13, 5], [16, 11], [0, 1], [8, 2], [8, 5],
[0, 0], [17, 15], [14, 8], [2, 1], [10, 5], [17, 14], [16, 5], [3, 8],
[14, 9], [5, 8], [15, 1], [3, 15], [13, 10], [10, 12], [5, 7], [0, 2],
[18, 14], [0, 15], [1, 6], [13, 5], [2, 1], [15, 14], [18, 8], [18, 9],
[1, 10], [14, 14], [13, 2], [5, 3], [5, 8], [0, 4], [1, 5], [16, 1],
[8, 1], [2, 5], [10, 7], [10, 15], [14, 14], [17, 3], [15, 0], [14, 5],
[7, 7], [3, 4], [14, 8], [12, 0], [13, 12], [12, 3], [6, 5], [3, 1],
[1, 14], [5, 4], [0, 12], [7, 0], [10, 7], [15, 12], [8, 2], [18, 15],
[3, 12], [1, 12], [0, 15], [17, 4], [17, 2], [11, 1], [3, 12], [11, 5],
[0, 13], [1, 1], [2, 12]
];
//所有的y值
$y = ['0123456789abcdef', '1032547698badcfe', '23016745ab89efcd', '32107654ba98fedc',
'45670123cdef89ab', '54761032dcfe98ba', '67452301efcdab89', '76543210fedcba98',
'89abcdef01234567', '98badcfe10325476', 'ab89efcd23016745', 'ba98fedc32107654',
'cdef89ab45670123', 'dcfe98ba54761032', 'efcdab8967452301', 'fedcba9876543210'];
//所有的x值
$x = ['016745', '107654', '234567', '321076', '325476', '452301', '543210',
'670123', '765432', '761032', '89abcd', '89efcd', '98fedc', 'abcdef',
'badcfe', 'cdab89', 'dcba98', 'ef89ab', 'fe98ba' ];
// 测试数组 var_dump($ascii[3]); print sizeof($data); var_dump($x);
function encode_url($url){
global $x, $y, $ascii, $data;
$mi = '';
for ($i = 0; $i != strlen($url); $i++){
$ch = $url[$i]; $f_real_x = -1; $f_real_y = -1;
for ($real_x = 0; $real_x != sizeof($ascii); $real_x++){
$real_y_chs = $ascii[$real_x];
for($real_y = 0; $real_y != sizeof($real_y_chs); $real_y++){
$real_y_ch= $real_y_chs[$real_y];
if ($real_y_ch == $ch){
$f_real_x = $real_x;
$f_real_y = $real_y;
}
}
}
if (($f_real_y != -1) && ($f_real_x != -1)) {
$this_data_x = $x[$data[$i][0]];
$encode_x = $this_data_x[$f_real_x];
$mi .= $encode_x;
$this_data_y = $y[$data[$i][1]];
$encode_y = $this_data_y[$f_real_y];
$mi .= $encode_y;
}
}
return 'https://www.baidu.com/link?url=a3f48d30fc293c5e471ef23de092fddc99' . $mi;
}
$url ="www.262235.xyz/index.php/archives/299/";
$t = encode_url($url);
print $url . " --> " . $t;
?>
开始第一版程序 因为不知道函数里使用全局变量,所以循序调试语句
$url ="www.262235.xyz/index.php/archives/298/";
$mi = '';
for ($i = 0; $i != strlen($url); $i++){
$ch = $url[$i]; $f_real_x = -1; $f_real_y = -1;
for ($real_x = 0; $real_x != sizeof($ascii); $real_x++){
$real_y_chs = $ascii[$real_x];
for($real_y = 0; $real_y != sizeof($real_y_chs); $real_y++){
$real_y_ch= $real_y_chs[$real_y];
if ($real_y_ch == $ch){
$f_real_x = $real_x;
$f_real_y = $real_y;
}
}
}
// 开始卡在了这里 '.和/等标点符号就丢失' 改成了 -1 判断 网上其他版本,不判断无条件执行下面编码语句也行
if (($f_real_y != -1) && ($f_real_x != -1)) {
$this_data_x = $x[$data[$i][0]];
$encode_x = $this_data_x[$f_real_x];
$mi .= $encode_x;
$this_data_y = $y[$data[$i][1]];
$encode_y = $this_data_y[$f_real_y];
$mi .= $encode_y;
}
}
$bdurl = 'https://www.baidu.com/link?url=a3f48d30fc293c5e471ef23de092fddc99' . $mi;
echo $bdurl . " <--> " . "www.262235.xyz/index.php/archives/298/" ;
网上有人贡献版本,同我 Python改php方法一样,只是精简了语句
function baidu($domain='www.abeip.com'){
global $x, $y, $ascii, $data;
$domains = str_split($domain);
$mi='';
for($i=0;$i<count($domains);$i++){
$f_real_x =''; $f_real_y ='';
for($real_x=0;$real_x<count($ascii);$real_x++){
$real_y_chs=$ascii[$real_x];
for($real_y=0;$real_y<count($real_y_chs);$real_y++){
if($real_y_chs[$real_y]==$domains[$i]){
$f_real_x = $real_x ;
$f_real_y = $real_y;
} } }
// 这里不判断 $ascii码表x,y 问题其实也不大
$this_data_x=$x[$data[$i][0]];
$encode_x = $this_data_x[$f_real_x];
$this_data_y = $y[$data[$i][1]];
$encode_y = $this_data_y[$f_real_y];
$mi = $mi. $encode_x. $encode_y;
return 'http://www.baidu.com/link?url=a3f48d30fc293c5e471ef23de092fddc99' . $mi;
}
相关推荐: [云筏测评系列] NAT-EU 9元服务器 by 有福吧
原文:https://www.ufbar.com/vpstest/226.html 云筏,以重塑国人商家形象为口号的主机商。品牌推出伊始,有5元/月的NAT大盘鸡优惠活动,可谓力度空前。如今,5元/月的NAT已成传家宝,但云筏依然有9元/月的低价NAT售卖,配…
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
喜欢就支持一下吧
请登录后发表评论
注册