Passport decryption functions written by PHP

Source: Internet
Author: User
  1. /**

  2. * Passport decryption function
  3. *
  4. * @param string of strings after encryption
  5. * @param string private key (for decryption and encryption)
  6. *
  7. * Results of @return string strings being decrypted by private key
  8. */
  9. function Passport_decrypt ($txt, $key) {

  10. The result of the $txt is that the encrypted string is Base64 decoded and then, together with the private key,

  11. 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 starting from 0 to an integer less than $txt string length

  16. for ($i = 0; $i < strlen ($txt); $i + +) {
  17. $tmp string adds a bit to the end of the $txt $i bit,
  18. With $txt $i + 1-bit XOR. Then $i = $i + 1
  19. $tmp. = $txt [$i] ^ $txt [+ + $i];
  20. }

  21. Returns the value of the $tmp as a result

  22. return $tmp;

  23. }

  24. /**

  25. * Passport Key processing function
  26. *
  27. * @param string to be encrypted or to be decrypted
  28. * @param string private key (for decryption and encryption)
  29. *
  30. * @return The key after string processing
  31. */
  32. function Passport_key ($txt, $encrypt _key) {

  33. Assigns $encrypt _key to $encrypt _key by MD5 ()

  34. $encrypt _key = MD5 ($encrypt _key);

  35. Variable initialization

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

  38. For loop, $i starting from 0 to an integer less than $txt string length

  39. for ($i = 0; $i < strlen ($txt); $i + +) {
  40. $ctr zeroed If $ctr = $encrypt the length of the _key
  41. $ctr = $ctr = = strlen ($encrypt _key)? 0: $ctr;
  42. $tmp string adds a bit to the end of the $txt $i bit,
  43. With $encrypt _key $ctr + 1-bit XOR. Then $ctr = $ctr + 1
  44. $tmp. = $txt [$i] ^ $encrypt _key[$ctr + +];
  45. }

  46. Returns the value of the $tmp as a result

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

Copy Code
  • Related Article

    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.