Copy Code code as follows:
Class syscrypt{
Private $crypt _key= ' http://www.jb51.net ';//Key
Public function __construct ($crypt _key) {
$this->crypt_key= $crypt _key;
}
Public function Encrypt ($txt) {
Srand (Double) microtime () *1000000);
$encrypt _key=md5 (rand (0,32000));
$ctr = 0;
$tmp = ';
for ($i =0; $i <strlen ($txt); $i + +) {
$ctr = $ctr ==strlen ($encrypt _key) 0: $ctr;
$tmp. = $encrypt _key[$ctr]. ($txt [$i]^ $encrypt _key[$ctr + +]);
}
Return Base64_encode (Self::__key ($tmp, $this->crypt_key));
}
Public function Decrypt ($txt) {
$txt =self::__key (Base64_decode ($txt), $this->crypt_key);
$tmp = ';
for ($i =0; $i <strlen ($txt); $i + +) {
$MD 5= $txt [$i];
$tmp. = $txt [+ + $i]^ $MD 5;
}
return $tmp;
}
Private Function __key ($txt, $encrypt _key) {
$encrypt _key=md5 ($encrypt _key);
$ctr = 0;
$tmp = ';
for ($i =0; $i <strlen ($txt); $i + +) {
$ctr = $ctr ==strlen ($encrypt _key) 0: $ctr;
$tmp. = $txt [$i]^ $encrypt _key[$ctr + +];
}
return $tmp;
}
Public Function __destruct () {
$this->crypt_key=null;
}
}
This class uses the method:
Copy Code code as follows:
$SC =new syscrypt (' http://www.jb51.net ');
$text = ' yhm.1234@163.com ';
$test 1= $sc->encrypt ($text);
Echo ' original: ', $text;
echo ' <br/> ';
Echo ' ciphertext: ', $test 1;
echo "<br/>";
Echo ' Decrypt: ', $sc->decrypt ($test 1);
The output is similar to the results:
Original: yhm.1234@163.com
Redaction: bs8dbfu6aiocnfflvgzqmgrgbduoylezbxoazgo0bjk=
Decryption: yhm.1234@163.com