Passport decryption function written in php
Release: 2016-07-25 09:02:53
Original
891 people have browsed it
-
-
/** - * 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
|
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31