Test Xxtea algorithm, there is no PHP version of the Web can restore my string, too wonderful.
The original text = "You are my, sdfsdfsdfasd,error\4&:1234/?., \3&%$#@@";
Restored = You are mine, sdfsdfsdfasd,error&:1234/?., &%$#@@;
As long as you meet \3, you can't. There are individual \4,5,6,7,8,9, some can be restored, and some cannot.
All the PHP versions of the Web Xxtea algorithm basically tested, all the same problem, very strange. Do you have a master, pointing twos?
Class Xxtea {
Public function Encrypt ($s, $key) {
Return self:: Xxtea_encrypt ($s, $key);
}
Public function Decrypt ($e, $key) {
Return self:: Xxtea_decrypt ($e, $key);
}
Private Function Long2str ($v, $w) {
$len = count ($v);
$n = ($len-1) << 2;
if ($w) {
$m = $v [$len-1];
if (($m < $n-3) | | ($m > $n))
return false;
$n = $m;
}
$s = array ();
for ($i = 0; $i < $len; $i + +) {
$s [$i] = Pack ("V", $v [$i]);
}
if ($w) {
Return substr (Join (', $s), 0, $n);
} else {
return join (' ', $s);
}
}
Private Function Str2long ($s, $w) {
$v = Unpack ("v*", $s. Str_repeat ("n", (4-strlen ($s)% 4) & 3));
$v = Array_values ($v);
if ($w) {
$v [Count ($v)] = strlen ($s);
}
return $v;
}
Private function Int32 ($n) {
while ($n >= 2147483648)
$n-= 4294967296;
while ($n <=-2147483649)
$n + = 4294967296;
return (int) $n;
}
Private Function Xxtea_encrypt ($STR, $key) {
if ($str = = "") {
Return "";
}
$v = self:: Str2long ($str, true);
$k = self:: Str2long ($key, false);
if (count ($k) < 4) {
for ($i = count ($k); $i < 4; $i + +) {
$k [$i] = 0;
}
}
$n = count ($v)-1;
$z = $v [$n];
$y = $v [0];
$delta = 0X9E3779B9;
$q = Floor (6 +/($n + 1));
$sum = 0;
while (0 < $q-) {
$sum = self:: Int32 ($sum + $delta);
$e = $sum >> 2 & 3;
for ($p = 0; $p < $n; $p + +) {
$y = $v [$p +1];
$mx = self:: Int32 ((($z >> 5 & 0x07ffffff) ^ $y << 2) + (($y >> 3 & 0x1fffffff) ^ $z << 4 ) ^ Self:: Int32 (($sum ^ $y) + ($k [$p & 3 ^ $e] ^ $z));
$z = $v [$p] = self:: Int32 ($v [$p] + $mx);
}
$y = $v [0];
$mx = self:: Int32 ((($z >> 5 & 0x07ffffff) ^ $y << 2) + (($y >> 3 & 0x1fffffff) ^ $z << 4 ) ^ Self:: Int32 (($sum ^ $y) + ($k [$p & 3 ^ $e] ^ $z));
$z = $v [$n] = self:: Int32 ($v [$n] + $mx);
}
Return self:: Long2str ($v, false);