-
-
/** - * Passport decryption function
- *
- * @param string encrypted string
- * @param string private key (used for decryption and encryption)
- *
- * @return string string decrypted by private key result
- */
- function passport_decrypt($txt, $key) {
// Result of $txt The encrypted string is base64 decoded, and then together with the private key,
- //The return value after processing by the passport_key() function
- $txt = passport_key(base64_decode($txt), $key);
//Variable initialization
- $tmp = '';
// for loop, $i is an integer starting from 0 and ending with the length of the $txt string
- for ($i = 0; $i < strlen($txt); $i++) {
- // The $tmp string adds one bit at the end, and its content is the $i-th bit of $txt,
- // and $txt Take XOR of bit $i + 1. Then $i = $i + 1
- $tmp .= $txt[$i] ^ $txt[++$i];
- }
// Return the value of $tmp as the result
- return $tmp;
}
/**
- * Passport key processing function
- *
- * @param string The string to be encrypted or decrypted
- * @param string Private key (for decryption and encryption)
- *
- * @return string The processed key
- */
- function passport_key($txt, $encrypt_key) {
// Assign $encrypt_key to the value of $encrypt_key after md5()
- $encrypt_key = md5($encrypt_key);
// Variable initialization
- $ctr = 0 ;
- $tmp = '';
// for loop, $i is an integer starting from 0 to less than the length of the $txt string
- for($i = 0; $i < ; strlen($txt); $i++) {
- // If $ctr = the length of $encrypt_key, $ctr is cleared
- $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
- // The $tmp string adds one bit at the end, its content is the $i-th bit of $txt,
- // is XORed with the $ctr + 1-th bit of $encrypt_key. Then $ctr = $ctr + 1
- $tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
- }
// Return the value of $tmp as the result
- return $tmp;
- }
- ?>
-
Copy code
|