首页  >  文章  >  后端开发  >  PHP初记|xxtea类

PHP初记|xxtea类

WBOY
WBOY原创
2016-06-13 13:20:051415浏览

PHP小记|xxtea类

xxtea可逆加密算法PHP实现:

?

Class Xxtea {
	public function encrypt($s, $key) {
		return base64_encode(self :: xxtea_encrypt($s, $key));
	}
	public function decrypt($e, $key) {
		return self :: xxtea_decrypt(base64_decode($e), $key);
	}
	private function long2str($v, $w) {
		$len = count($v);
		$n = ($len -1)  $n))
				return false;
			$n = $m;
		}
		$s = array ();
		for ($i = 0; $i = 2147483648)
			$n -= 4294967296;
		while ($n > 2 & 3;
			for ($p = 0; $p > 5 & 0x07ffffff) ^ $y > 3 & 0x1fffffff) ^ $z > 5 & 0x07ffffff) ^ $y > 3 & 0x1fffffff) ^ $z > 2 & 3;
			for ($p = $n; $p > 0; $p--) {
				$z = $v[$p -1];
				$mx = self :: int32((($z >> 5 & 0x07ffffff) ^ $y > 3 & 0x1fffffff) ^ $z > 5 & 0x07ffffff) ^ $y > 3 & 0x1fffffff) ^ $z 
<p>?</p>
<p>使用方法:</p>
<p><strong>加密:</strong></p>
<p><strong>Xxtea::encrypt(明文字符串, 密钥字符串);</strong></p>
<p><strong>解密:</strong></p>
<p><strong>Xxtea::decrypt(密文字符串, 密钥字符串);</strong></p>
<p>?</p>
 <div class="clear">
                 
              
              
        
            </div>
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn