PHP Cryptographic decryption class instance code _php instance

Source: Internet
Author: User
The key code is as follows:

<?phpfunction I_array_column ($input, $columnKey, $indexKey =null) {if (!function_exists (' Array_column ')) {$ Columnkeyisnumber = (Is_numeric ($columnKey))? true:false; $indexKeyIsNull = (Is_null ($indexKey))? true:false;$ Indexkeyisnumber = (Is_numeric ($indexKey))? true:false; $result = Array (); foreach (array) $input as $key = = $row) {if ($ Columnkeyisnumber) {$tmp = Array_slice ($row, $columnKey, 1); $tmp = (Is_array ($tmp) &&!empty ($tmp))? Current ($ TMP): null;} else{$tmp = isset ($row [$columnKey])? $row [$columnKey]:null;} if (! $indexKeyIsNull) {if ($indexKeyIsNumber) {$key = Array_slice ($row, $indexKey, 1); $key = (Is_array ($key) &&! Empty ($key))? Current ($key): null; $key = Is_null ($key)? 0: $key;} else{$key = isset ($row [$indexKey])? $row [$indexKey]:0;}} $result [$key] = $tmp;} return $result;} Else{return Array_column ($input, $columnKey, $indexKey);}} function Randcode ($len, $mode = 2) {$rcode = '; switch ($mode) {Case 1://Remove 0, O, O, L, etc. easily confusing characters $chars = ' Abcdefghjklmnpqrstuvwxyz23456789abcdefghijkmnpqrstuvwxyz '; BreaK;case 2://Pure digital $chars = ' 0123456789 '; Break;case 3://full digit + uppercase letter $chars = ' Abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz '; Break;case 4://full digit + uppercase letter + some special characters $chars = ' abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz~!@#$%^&* () '; break;} $count = strlen ($chars)-1;mt_srand ((double) microtime () * 1000000); for ($i = 0; $i < $len; $i + +) {$rcode. = $chars [Mt_r and (0, $count)];} return $rcode;} /*** $string Clear Text or ciphertext * $operation encrypt encode or decrypt decode* $key key * $expiry key validity period */function Authcode ($string, $operation = ' DECODE '  , $key = ", $expiry = 0) {$ckey _length = 4; $key = MD5 ($key); $keya = MD5 (substr ($key, 0, +)); $keyb = MD5 (substr ($key, 16, ); $KEYC = $ckey _length? ($operation = = ' DECODE '? substr ($string, 0, $ckey _length): substr (MD5 (Microtime ()),-$ckey _length)): "; $cryptkey = $key A.MD5 ($keya. $keyc); $key _length = strlen ($cryptkey); $string = = $operation = = ' DECODE '? Base64_decode (substr ($string, $ckey _length)): sprintf ('%010d ', $expiry? $expiry + Time (): 0). substR (MD5 ($string. $keyb), 0, +). $string $string _length = strlen ($string); $result = "; $box = range (0, 255); $rndkey = Array () ; for ($i = 0; $i <= 255; $i + +) {$rndkey [$i] = Ord ($cryptkey [$i% $key _length]);}  for ($j = $i = 0; $i < $i + +) {$j = ($j + $box [$i] + $rndkey [$i])%, $tmp = $box [$i]; $box [$i] = $box [$j]; $box [$j] = $tmp;} for ($a = $j = $i = 0; $i < $string _length; $i + +) {$a = ($a + 1)%, $j = ($j + $box [$a])%, $tmp = $box [$a]; $box [$ A] = $box [$j]; $box [$j] = $tmp; $result. = Chr (ord ($string [$i]) ^ ($box [($box [$a] + $box [$j])% 256]));} if ($operation = = ' DECODE ') {if (substr ($result, 0, ten) = = 0 | | substr ($result, 0,)-time () > 0) && substr ($ result, (+) = = substr (MD5 ($result, 0)) {return substr ($result, +),} else {return ';}} else {return $KEYC. Str_replace (' = ', ' ', Base64_encode ($result));}}

The above is a small part of the code to introduce you to the PHP encryption and decryption class instance codes, I hope we have some help, if you have any questions please give me a message, small series will promptly reply to you. Thank you very much for the support of the Scripting House website!

  • 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.