...
求一解密函数的对应加密函数
本帖最后由 xuzuning 于 2013-02-21 10:07:35 编辑 现在已知一解密函数(readkey)如下,求对应的加密函数
function authcode( $string, $operation = "DECODE", $key = "", $expiry = 0 )
{
$ckey_length = 4;
$key = md5( $key != "" ? $key : "a2264dxLupVMlkqR" );
$keya = md5( substr( $key, 0, 16 ) );
$keyb = md5( substr( $key, 16, 16 ) );
$keyc = $ckey_length ? $operation == "DECODE" ? substr( $string, 0, $ckey_length ) : substr( md5( microtime( ) ), 0 - $ckey_length ) : "";
$cryptkey = $keya.md5( $keya.$keyc );
$key_length = strlen( $cryptkey );
$string = $operation == "DECODE" ? base64_decode( substr( $string, $ckey_length ) ) : sprintf( "%010d", $expiry ? $expiry + time( ) : 0 ).substr( md5( $string.$keyb ), 0, 16 ).$string;
$string_length = strlen( $string );
$result = "";
$box = range( 0, 255 );
$rndkey = array( );
$i = 0;
for ( ; $i {
$rndkey[$i] = ord( $cryptkey[$i % $key_length] );
}
$j = $i = 0;
for ( ; $i {
$j = ( $j + $box[$i] + $rndkey[$i] ) % 256;
$tmp = $box[$i];
$box[$i] = $box[$j];
$box[$j] = $tmp;
}
$a = $j = $i = 0;
for ( ; $i {
$a = ( $a + 1 ) % 256;
$j = ( $j + $box[$a] ) % 256;
$tmp = $box[$a];
$box[$a] = $box[$j];
$box[$j] = $tmp;
$result .= chr( ord( $string[$i] ) ^ $box[( $box[$a] + $box[$j] ) % 256] );
}
if ( $operation == "DECODE" )
{
if ( ( substr( $result, 0, 10 ) == 0 || 0 {
return substr( $result, 26 );
}
return "";
}
return $keyc.str_replace( "=", "", base64_encode( $result ) );
}
function readkey( $keys )
{
$Leskey = authcode( $keys, "DECODE", "a2264dxLupVMlkqR" );
$Leskey = base64_decode( $Leskey );
$firstStr = substr( $Leskey, 0, 1 );
$Leskey = substr( $Leskey, 1 );
$Leskey = strrev( substr( $Leskey, 0, $firstStr ) ).chr( ord( substr( $Leskey, $firstStr, 1 ) ) ^ $firstStr ).strrev( substr( $Leskey, $firstStr + 1 ) );
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
相关文章
相关视频
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论