求一解密函数的对应加密函数
本帖最后由 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 <= 255;++$i)
{
$rndkey[$i] = ord( $cryptkey[$i % $key_length] );
}
$j = $i = 0;
for ( ;$i < 256;++$i)
{
$j = ( $j + $box[$i] + $rndkey[$i] ) % 256;
$tmp = $box[$i];
$box[$i] = $box[$j];
$box[$j] = $tmp;
}
$a = $j = $i = 0;
for ( ;$i < $string_length;++$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 < substr( $result, 0, 10 ) - time( ) ) && substr( $result, 10, 16 ) == substr( md5( substr( $result, 26 ).$keyb ), 0, 16 ) )
{
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 ) );
$Leskey = base64_decode( $Leskey );
$Leskey = json_decode( $Leskey, TRUE );
return $Leskey;
}
561eqDNvqSI/n6UPGqb5XbORsuT9a26W6M415bRUYpP4enT5Kb/BLd5MI7Jvvt2RE35r1lHrdtC5MYNUtP7gpbqY0GeUbLXRUrUL9ABC1XTFD4zlVf3VoM4HUdEUxHAkVivkA2G1ywT2VXlLNrnuq9AXs65GXrD0G2ILS693cfGAwn4xL4QI313FVYtHWLK/EIcg0HyRMxMR5P8fftAA+Fw42c5c31G8yCh96lNfBcrhsjuO7tqJuiBSuKQBH3bbxfnum1yb1RgI8myw23tlrtdDBoPiNpCgm1usa2L+lAXLhvE8yqRLg5T8ZVXxwvO1quV8zMpBrY/XxRu5+Nn6AvXsKUwdyhVCp2jgj5S4Yr0CWcyiUg