标题:求高手帮忙,帮我反写个程序,谢谢
只看楼主
as4491
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2015-2-9
 问题点数:0 回复次数:1 
求高手帮忙,帮我反写个程序,谢谢
<?
function sample($s)
{
$hexchars = '0123456789ABCDEF';
if ( !$s || strlen($s) <= 0 )
{
echo "null string.";
return "";
}
$len = strlen($s);
$ret = '';
$curc = 0;
    $nextc = ord(substr($s, 0, 1));
for ($i=1; $i<$len; $i++ )
{
$curc = $nextc;
$nextc = ord(substr($s, $i, 1));
$curc ^= $nextc;
//echo '<br> 0x'. substr($hexchars, ($curc & 0xF0) >> 4, 1) . substr($hexchars, $curc & 0x0F, 1);
$ret .= substr($hexchars, ($curc & 0xF0) >> 4, 1);
$ret .= substr($hexchars, $curc & 0x0F, 1);
}
$curc = $nextc ^ 0x7C;
$ret .= substr($hexchars, ($curc & 0xF0) >> 4, 1);
echo $ret;
echo "<br>";
$ret .= substr($hexchars, $curc & 0x0F, 1);
return $ret;
}
$a="srvaddr=127.0.0.1";
$b=sample($a);
echo $b;
function sample2($s)
{
    //现在就想写个程序,把这个$b给还原成$a,请高手帮忙写个
}
$c=sample2($b);
echo $c;


?>
搜索更多相关主题的帖子: function return null 
2015-02-09 19:03
asmdaydream
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:中原
等 级:版主
威 望:13
帖 子:257
专家分:840
注 册:2009-5-10
得分:0 
来得有点晚
程序代码:
function sample2($s) {
        function getOrd($encrypt='',$pos,$str='0123456789ABCDEF'){
            $firest_ord = strpos($str,$encrypt[$pos-1]);
            $before4 = $firest_ord << 4 & 0XF0;     
            $last_ord = strpos($str,$encrypt[$pos]);
            $last4 = $last_ord & 0x0F;              
            return $last4 | $before4;
        }
        $hexchars = '0123456789ABCDEF';
        $result = '';
        $length = strlen($s);
        $last_ord = getOrd($s, $length-1, $hexchars);

        $nextc = $last_ord ^ 0X7C;
        for($i=$length-3;$i>0;$i=$i-2)
        {
            $result .= chr($nextc);
            $curc  = getOrd($s, $i, $hexchars);
            $curc ^= $nextc;
            $nextc = $curc;
        }
        $result .= chr($nextc);
        return strrev($result);
    }

常走夜路不怕黑 长沙PHP高薪招聘群6K+ 95926136
2015-03-18 10:03



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-441922-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014793 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved