|
开源函数代码如下
function decode( $string, $key )
{
$key = md5( $key );
$key_length = strlen( $key );
$string = base64_decode( $string );
$string_length = strlen( $string );
$rndkey = $box = array( );
$result = "";
$i = 0;
for ( ; $i <= 255; ++$i )
{
$rndkey[$i] = ord( $key[$i % $key_length] );
$box[$i] = $i;
}
$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 ( substr( $result, 0, 8 ) == substr( md5( substr( $result, 8 ).$key ), 0, 8 ) )
{
return substr( $result, 8 );
}
}
请问高手们,如何根据这个写出加密函数?非常感谢 |
|