Php simple encryption/Decryption

Source: Internet
Author: User
I just learned php soon. Please kindly advise! None? Php *** Lite version of encryption and decryption class * @ author clothing QQ780998900 * @ packgeSimpleTools * @ linkcommoner.cn clothing blog * @ copyrightcommoner.cn * classSimpleCrypt {*** the more complicated the key *, the better, but the string length will be integer.

I just learned php soon. Please kindly advise! None? Php/*** Lite version encryption/Decryption class * @ author cloth QQ 780998900 * @ packge SimpleTools * @ link http://commoner.cn cloth blog * @ copyright http://commoner.cn */class SimpleCrypt {/*** key * The more complex the better, but the string length will be integer.

I just learned php soon. Please kindly advise! <无>
  200? Ceil ($ str_num/10): ceil ($ str_num/8); // generate a random string $ head_rand_loop_num = ($ head_loop_num * 10)-$ head_loop_num; $ end_rand_loop_num = ($ end_loop_num + $ head_loop_num) * 10-$ end_loop_num; $ head_rand_str = null; $ end_rand_str = null; // The first half of the random string; $ I <$ head_rand_loop_num; $ I ++) {$ head_rand_str. = self: $ word [rand (0, 51)];} // The half-end random string for ($ I = 0; $ I <$ end_rand_loop_num; $ I ++) {$ End_rand_str. = self: $ word [rand (0, 51)];} // encrypt the First Half of the content for ($ I = 0; $ I <$ head_loop_num; $ I ++) {$ head_str = base64_encode ($ head_str);} // tear up the variable unset ($ I); // encrypt the second half of the content for ($ I = 0; $ I <$ end_loop_num; $ I ++) {$ end_str = base64_encode ($ end_str);} // merge $ implode_str = $ head_rand_str. $ head_str. self: $ key. base64_encode ($ head_loop_num ). self: $ key. base64_encode ($ end_loop_num ). self: $ key. $ en D_str. $ end_rand_str; $ result = base64_encode ($ implode_str); // to continue later, return $ result first ;} /*** decryption algorithm ** @ param $ str the String to be decrypted * @ return String the decrypted String */public static function decode ($ str) {// obtain the encrypted information $ get = explode (self: $ key, base64_decode ($ str); $ head_str = $ get [0]; $ end_str = $ get [3]; $ head_loop_num = base64_decode ($ get [1]); $ end_loop_num = base64_decode ($ get [2]); // Algorithm for removing random strings $ head_rand_num = ($ Head_loop_num * 10)-$ head_loop_num; $ end_rand_num = ($ end_loop_num + $ head_loop_num) * 10-$ end_loop_num; // remove random strings, get the original $ head_str = substr ($ head_str, $ head_rand_num, strlen ($ head_str); $ end_str = substr ($ end_str, 0, strlen ($ end_str)-$ end_rand_num ); // decrypt the First Half of the data for ($ I = 0; $ I <$ head_loop_num; $ I ++) {$ head_str = base64_decode ($ head_str );} // tear up the variable unset ($ I); // decrypt the half-end part for ($ I = 0; $ I <$ en D_loop_num; $ I ++) {$ end_str = base64_decode ($ end_str);} // merge and decrypt $ result = base64_decode ($ head_str. $ end_str); return $ result ;}}?>

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.