1. Discuz Authcode
0 Verify data Validity//substr ($result, 16) = = SUBSTR (MD5 ($result, 0) $keyb), and/or Verify data integrity//validation, please Look at the unencrypted plaintext format if (substr ($result, 0, 10) = = 0 | | substr ($result, 0, Ten)-time () > 0) && substr ($result, ten, +) = = substr (MD5 (SUBSTR ( $result, 26). $KEYB), 0, +) {return substr ($result, 26); } else {return '; }} else {//To keep the dynamic key in the ciphertext, which is why the same plaintext, the production of different ciphertext can be decrypted after the reason//because the encrypted ciphertext may be some special characters, the copy process may be lost, so the base64 encoding Return $KEYC. Str_replace (' = ', ' ', Base64_encode ($result)); }} $a = "www.test.com"; $b = Authcode ($a, "ENCODE", "abc123"); Echo $b. "
" ; Echo Authcode ($b, "DECODE", "abc123");
2. Simple symmetric encryption algorithm
* @date 2013-08-13 19:30 * @update 2014-10-10 10:10 * @return String */function encode ($string = ", $skey = ' cxphp ') {$STRARR = Str_split (Base64_encode ($string)); $strCount = count ($STRARR); foreach (Str_split ($skey) as $key = + $value) $key < $strCount && $strArr [$key].= $va Lue; return Str_replace (Array (' = ', ' + ', '/'), Array (' o0o0o ', ' o000o ', ' oo00o '), join (', $STRARR)); /** * Decryption of simple symmetric encryption algorithm * @param string $string The string to decrypt * @param string $skey Decrypt key * @author Anyon Zou
* @date 2013-08-13 19:30 * @update 2014-10-10 10:10 * @return String */function decode ($string = ", $skey = ' cxphp ') {$STRARR = Str_split (Str_replace (' o0o0o ', ' o000o ', ' oo00o '), array (' = ', ' + ', '/') , $string), 2); $strCount = count ($STRARR); foreach (Str_split ($skey) as $key = + $value) $key <= $strCount && isset ($strArr [$key ] && $STRARR [$key] [1] = = = $value && $strArr [$key] = $STRARR [$key] [0]; Return Base64_decode (Join (', $STRARR)); } Echo '
' ; $str = ' 56,15123365247,54, four classical styles '; Echo "string:" . $str .
" ; echo "encode:" . ($enstring = encode ($str)). '
' ; Echo "decode:" . Decode ($enstring);
3. DES encryption and decryption
key = $key; if ($iv = = 0) {$this, iv = $key; }else{$this IV = $IV; }}//Cryptographic function Encrypt ($STR) {$size = Mcrypt_get_block_size (Mcrypt_des, MCR YPT_MODE_CBC); $str = Pkcs5pad ($str, $size), $this $data = MCRYPT_CBC (Mcrypt_des, $this, Key, $str, Mcrypt_encrypt, $this, iv); $data =strtoupper (Bin2Hex ($data)); Returns the uppercase hexadecimal string return Base64_encode ($data); }//Decryption function decrypt ($str) {$str = Base64_decode ($STR); $strBin = $this->hex2bin (strtolower ($STR)); $str = MCRYPT_CBC (Mcrypt_des, $this, Key, $str, Mcrypt_decrypt, $this, iv); $str = $this-Pkcs5unpad ($STR); return $str; } function Hex2bin ($hexData) {$binData = ""; for ($i = 0; $i < strlen ($hexData); $i + = 2) {$binData. = Chr (Hexdec (substr ($hexData, $i, 2))); } return $binData; } function Pkcs5pad ($text, $blocksize) {$pad = $blocksize-(strlen ($text)% $blocksize); Return $text. Str_repeat (Chr ($pad), $pad); } function Pkcs5unpad ($text) {$pad = Ord ($text {strlen ($text)-1}); if ($pad > strlen ($text)) return false; if (strspn ($text, Chr ($pad), strlen ($text)-$pad)! = $pad) return false; Return substr ($text, 0,-1 * $pad); }} $str = ' abc '; $key = ' 12345678 '; Within 8 bits $crypt = new DES ($key); $MSTR = $crypt-Encrypt ($STR); $STR = $crypt-Decrypt ($MSTR); Echo $str. ' <=> '. $MSTR;
4. PHP Hex2bin
' ; echo Hexxbin ($t);