/**
* Function: Encrypt string processing
* Parameter one: Content that needs to be encrypted
* Parameter two: key
*/
function Passport_encrypt ($STR, $key) {//encryption function
Srand (Double) microtime () * 1000000);
$encrypt _key=md5 (rand (0, 32000));
$ctr = 0;
$tmp = ";
for ($i =0; $i
<>
$ctr = $ctr ==strlen ($encrypt _key)? 0: $ctr;
$tmp. = $encrypt _key[$ctr]. ($str [$i] ^ $encrypt _key[$ctr + +]);
}
Return Base64_encode (Passport_key ($tmp, $key));
}
/**
* Function: Decryption of strings
* Parameter one: ciphertext to be decrypted
* Parameter two: key
*/
function Passport_decrypt ($STR, $key) {//decryption functions
$str =passport_key (Base64_decode ($STR), $key);
$tmp = ";
for ($i =0; $i<>
$MD 5= $str [$i];
$tmp. = $str [+ + $i] ^ $MD 5;
}
return $tmp;
}
/**
* Auxiliary functions
*/
function Passport_key ($str, $encrypt _key) {
$encrypt _key=md5 ($encrypt _key);
$ctr = 0;
$tmp = ";
for ($i =0; $i<>
$ctr = $ctr ==strlen ($encrypt _key)? 0: $ctr;
$tmp. = $str [$i] ^ $encrypt _key[$ctr + +];
}
return $tmp;
}
$str = ' Author: www.phpernote.com ';
$key = ' 658JR ';
$encrypt =passport_encrypt ($str, $key);
$decrypt =passport_decrypt ($encrypt, $key);
Echo ' original: ', $str. '
";
Echo ' ciphertext: ', $encrypt. "
";
echo ' translation: ', $decrypt. '
";
http://www.bkjia.com/PHPjc/780021.html www.bkjia.com true http://www.bkjia.com/PHPjc/780021.html techarticle PHP/** * Function: Encrypt the string * parameter one: What needs to be encrypted * parameter two: Key */function Passport_encrypt ($STR, $key) {//Cryptographic function Srand ((double) micro ...