本帖最后由 xuzuning 于 2013-02-21 10:07:35 编辑
现在已知一解密函数(readkey)如下,求对应的加密函数
<br>
function authcode( $string, $operation = "DECODE", $key = "", $expiry = 0 )<br>
{<br>
$ckey_length = 4;<br>
$key = md5( $key != "" ? $key : "a2264dxLupVMlkqR" );<br>
$keya = md5( substr( $key, 0, 16 ) );<br>
$keyb = md5( substr( $key, 16, 16 ) );<br>
$keyc = $ckey_length ? $operation == "DECODE" ? substr( $string, 0, $ckey_length ) : substr( md5( microtime( ) ), 0 - $ckey_length ) : "";<br>
$cryptkey = $keya.md5( $keya.$keyc );<br>
$key_length = strlen( $cryptkey );<br>
$string = $operation == "DECODE" ? base64_decode( substr( $string, $ckey_length ) ) : sprintf( "%010d", $expiry ? $expiry + time( ) : 0 ).substr( md5( $string.$keyb ), 0, 16 ).$string;<br>
$string_length = strlen( $string );<br>
$result = "";<br>
$box = range( 0, 255 );<br>
$rndkey = array( );<br>
$i = 0;<br>
for ( ; $i
{<br>
$rndkey[$i] = ord( $cryptkey[$i % $key_length] );<br>
}<br>
$j = $i = 0;<br>
for ( ; $i
{<br>
$j = ( $j + $box[$i] + $rndkey[$i] ) % 256;<br>
$tmp = $box[$i];<br>
$box[$i] = $box[$j];<br>
$box[$j] = $tmp;<br>
}<br>
$a = $j = $i = 0;<br>
for ( ; $i
{<br>
$a = ( $a + 1 ) % 256;<br>
$j = ( $j + $box[$a] ) % 256;<br>
$tmp = $box[$a];<br>
$box[$a] = $box[$j];<br>
$box[$j] = $tmp;<br>
$result .= chr( ord( $string[$i] ) ^ $box[( $box[$a] + $box[$j] ) % 256] );<br>
}<br>
if ( $operation == "DECODE" )<br>
{<br>
if ( ( substr( $result, 0, 10 ) == 0 || 0
{<br>
return substr( $result, 26 );<br>
}<br>
return "";<br>
}<br>
return $keyc.str_replace( "=", "", base64_encode( $result ) );<br>
}<br>
function readkey( $keys )<br>
{<br>
$Leskey = authcode( $keys, "DECODE", "a2264dxLupVMlkqR" );<br>
$Leskey = base64_decode( $Leskey );<br>
$firstStr = substr( $Leskey, 0, 1 );<br>
$Leskey = substr( $Leskey, 1 );<br>
$Leskey = strrev( substr( $Leskey, 0, $firstStr ) ).chr( ord( substr( $Leskey, $firstStr, 1 ) ) ^ $firstStr ).strrev( substr( $Leskey, $firstStr + 1 ) ); <div class="clear">
</div>
登录后复制