I'm sitting here with a rope around my neck and a big box of sleeping pills, wondering if it's time to just end it all.
But found out that a last appeal here at phpbuilder might save my neck π
Problem:
I've got a 3DES-encryption script written in php which cooperates with a Javascript to perform encryption routines to bring passwords safely from client to server.
There's a lot of bit-shifting involved, and it all works fine.
Sometimes...
It seems that different php-versions interprets this in different ways.
Examples:
On Linux/php 4.2.2
On SunOS 9/php 4.3.1
Same code on both sites, but different output when shifting bits.
Heres the code:
## This enhances php to accept zero fill shift right bitwise operator >>> ##
function zeroFill($a, $b) {
$z = hexdec(80000000);
if ($z & $a) {
$a >>= 1;
$a &= (~ $z);
$a |= 0x40000000;
$a >>= ($b-1);
} else {
$a >>= $b;
}
return $a;
}
## Just a test - this is what is exec'ed in the scripts on the links ##
$left = -890149274;
$right = -1236965530;
$temp = 53283;
echo "<br>right: ".$right."<br>";
echo "<br>left: ".$left."<br>";
echo "<br>Temp: ".$temp."<br>";
$temp = ((zeroFill($left, 2)) ^ $right) & 0x33333333; $right ^= $temp; $left ^= ($temp << 2);
echo "<br>right2: ".$right."<br>";
echo "<br>left2: ".$left."<br>";
echo "<br>Temp2: ".$temp."<br>";
The zeroFill-function is the only way I've found to extend php with this operand.
Anyone?:p
knutm