Passport decryption function written in php

WBOY
Release: 2016-07-25 09:02:53
Original
891 people have browsed it
  1. /**

  2. * Passport decryption function
  3. *
  4. * @param string encrypted string
  5. * @param string private key (used for decryption and encryption)
  6. *
  7. * @return string string decrypted by private key result
  8. */
  9. function passport_decrypt($txt, $key) {

  10. // Result of $txt The encrypted string is base64 decoded, and then together with the private key,

  11. //The return value after processing by the passport_key() function
  12. $txt = passport_key(base64_decode($txt), $key);
  13. //Variable initialization

  14. $tmp = '';

  15. // for loop, $i is an integer starting from 0 and ending with the length of the $txt string

  16. for ($i = 0; $i < strlen($txt); $i++) {
  17. // The $tmp string adds one bit at the end, and its content is the $i-th bit of $txt,
  18. // and $txt Take XOR of bit $i + 1. Then $i = $i + 1
  19. $tmp .= $txt[$i] ^ $txt[++$i];
  20. }

  21. // Return the value of $tmp as the result

  22. return $tmp;

  23. }

  24. /**

  25. * Passport key processing function
  26. *
  27. * @param string The string to be encrypted or decrypted
  28. * @param string Private key (for decryption and encryption)
  29. *
  30. * @return string The processed key
  31. */
  32. function passport_key($txt, $encrypt_key) {

  33. // Assign $encrypt_key to the value of $encrypt_key after md5()

  34. $encrypt_key = md5($encrypt_key);

  35. // Variable initialization

  36. $ctr = 0 ;
  37. $tmp = '';

  38. // for loop, $i is an integer starting from 0 to less than the length of the $txt string

  39. for($i = 0; $i < ; strlen($txt); $i++) {
  40. // If $ctr = the length of $encrypt_key, $ctr is cleared
  41. $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
  42. // The $tmp string adds one bit at the end, its content is the $i-th bit of $txt,
  43. // is XORed with the $ctr + 1-th bit of $encrypt_key. Then $ctr = $ctr + 1
  44. $tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
  45. }

  46. // Return the value of $tmp as the result

  47. return $tmp;
  48. }
  49. ?>

Copy code


Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!