1. corresponding encryption function of the decryption function

Source: Internet
Author: User
Find the corresponding encryption function of the decryption function. this post is finally edited by xuzuning from 2013-02-21:07:35. now the read key function is as follows. request the corresponding encryption function & nbsp; authcode (& nbsp; $ string, & nbsp; $ operation & nbsp; DECODE, & nbsp; $ find the corresponding encryption function of the decryption function

This post was last edited by xuzuning at 10:07:35

The following is a decryption function (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 ) );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.