Passport decryption function written in php

Source: Internet
Author: User
Passport decryption function written in php

  1. /**

  2. * Passport decryption function
  3. *
  4. * @ Param string the encrypted string
  5. * @ Param string private key (used for decryption and encryption)
  6. *
  7. * @ Return string result after private key decryption
  8. */
  9. Function passport_decrypt ($ txt, $ key ){

  10. // $ Txt results in base64 decoding of the encrypted string, and then together with the private key,

  11. // Return value after passport_key () function processing
  12. $ Txt = passport_key (base64_decode ($ txt), $ key );

  13. // Variable initialization

  14. $ Tmp = '';

  15. // For loop, $ I is an integer starting from 0 to less than $ txt string length

  16. For ($ I = 0; $ I <strlen ($ txt); $ I ++ ){
  17. // $ Tmp adds a bit at the end of the string, whose content is the $ I bit of $ txt,
  18. // It is the same as the $ I + 1 bits in $ txt. 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 to be decrypted
  28. * @ Param string private key (used 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 $ txt string length

  39. For ($ I = 0; $ I <strlen ($ txt); $ I ++ ){
  40. // If $ ctr = $ encrypt_key length, $ ctr is cleared.
  41. $ Ctr = strlen ($ encrypt_key )? 0: $ ctr;
  42. // $ Tmp adds a bit at the end of the string, whose content is the $ I bit of $ txt,
  43. // It is the same or as the $ ctr + 1 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. ?>

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.