|
@@ -185,16 +185,16 @@ class Crypt {
|
|
|
$temp = (($right >> 8 & $masks[8]) ^ $left) & 0x00ff00ff; $left ^= $temp; $right ^= ($temp << 8);
|
|
$temp = (($right >> 8 & $masks[8]) ^ $left) & 0x00ff00ff; $left ^= $temp; $right ^= ($temp << 8);
|
|
|
$temp = (($left >> 1 & $masks[1]) ^ $right) & 0x55555555; $right ^= $temp; $left ^= ($temp << 1);
|
|
$temp = (($left >> 1 & $masks[1]) ^ $right) & 0x55555555; $right ^= $temp; $left ^= ($temp << 1);
|
|
|
|
|
|
|
|
- $left = (($left << 1) | ($left >> 31 & $masks[31]));
|
|
|
|
|
- $right = (($right << 1) | ($right >> 31 & $masks[31]));
|
|
|
|
|
|
|
+ $left = (($left << 1) | ($left >> 31 & $masks[31]));
|
|
|
|
|
+ $right = (($right << 1) | ($right >> 31 & $masks[31]));
|
|
|
|
|
|
|
|
//do this either 1 or 3 times for each chunk of the message
|
|
//do this either 1 or 3 times for each chunk of the message
|
|
|
for ($j=0; $j<$iterations; $j+=3) {
|
|
for ($j=0; $j<$iterations; $j+=3) {
|
|
|
$endloop = $looping[$j+1];
|
|
$endloop = $looping[$j+1];
|
|
|
$loopinc = $looping[$j+2];
|
|
$loopinc = $looping[$j+2];
|
|
|
- //now go through and perform the encryption or decryption
|
|
|
|
|
|
|
+ //now go through and perform the encryption or decryption
|
|
|
for ($i=$looping[$j]; $i!=$endloop; $i+=$loopinc) { //for efficiency
|
|
for ($i=$looping[$j]; $i!=$endloop; $i+=$loopinc) { //for efficiency
|
|
|
- $right1 = $right ^ $keys[$i];
|
|
|
|
|
|
|
+ $right1 = $right ^ $keys[$i];
|
|
|
$right2 = (($right >> 4 & $masks[4]) | ($right << 28)) ^ $keys[$i+1];
|
|
$right2 = (($right >> 4 & $masks[4]) | ($right << 28)) ^ $keys[$i+1];
|
|
|
//the result is attained by passing these bytes through the S selection functions
|
|
//the result is attained by passing these bytes through the S selection functions
|
|
|
$temp = $left;
|
|
$temp = $left;
|
|
@@ -208,8 +208,8 @@ class Crypt {
|
|
|
} //for either 1 or 3 iterations
|
|
} //for either 1 or 3 iterations
|
|
|
|
|
|
|
|
//move then each one bit to the right
|
|
//move then each one bit to the right
|
|
|
- $left = (($left >> 1 & $masks[1]) | ($left << 31));
|
|
|
|
|
- $right = (($right >> 1 & $masks[1]) | ($right << 31));
|
|
|
|
|
|
|
+ $left = (($left >> 1 & $masks[1]) | ($left << 31));
|
|
|
|
|
+ $right = (($right >> 1 & $masks[1]) | ($right << 31));
|
|
|
|
|
|
|
|
//now perform IP-1, which is IP in the opposite direction
|
|
//now perform IP-1, which is IP in the opposite direction
|
|
|
$temp = (($left >> 1 & $masks[1]) ^ $right) & 0x55555555; $right ^= $temp; $left ^= ($temp << 1);
|
|
$temp = (($left >> 1 & $masks[1]) ^ $right) & 0x55555555; $right ^= $temp; $left ^= ($temp << 1);
|
|
@@ -296,7 +296,7 @@ class Crypt {
|
|
|
|
|
|
|
|
//now apply PC-2, in such a way that E is easier when encrypting or decrypting
|
|
//now apply PC-2, in such a way that E is easier when encrypting or decrypting
|
|
|
//this conversion will look like PC-2 except only the last 6 bits of each byte are used
|
|
//this conversion will look like PC-2 except only the last 6 bits of each byte are used
|
|
|
- //rather than 48 consecutive bits and the order of lines will be according to
|
|
|
|
|
|
|
+ //rather than 48 consecutive bits and the order of lines will be according to
|
|
|
//how the S selection functions will be applied: S2, S4, S6, S8, S1, S3, S5, S7
|
|
//how the S selection functions will be applied: S2, S4, S6, S8, S1, S3, S5, S7
|
|
|
$lefttemp = $pc2bytes0[$left >> 28 & $masks[28]] | $pc2bytes1[($left >> 24 & $masks[24]) & 0xf]
|
|
$lefttemp = $pc2bytes0[$left >> 28 & $masks[28]] | $pc2bytes1[($left >> 24 & $masks[24]) & 0xf]
|
|
|
| $pc2bytes2[($left >> 20 & $masks[20]) & 0xf] | $pc2bytes3[($left >> 16 & $masks[16]) & 0xf]
|
|
| $pc2bytes2[($left >> 20 & $masks[20]) & 0xf] | $pc2bytes3[($left >> 16 & $masks[16]) & 0xf]
|
|
@@ -306,7 +306,7 @@ class Crypt {
|
|
|
| $pc2bytes9[($right >> 20 & $masks[20]) & 0xf] | $pc2bytes10[($right >> 16 & $masks[16]) & 0xf]
|
|
| $pc2bytes9[($right >> 20 & $masks[20]) & 0xf] | $pc2bytes10[($right >> 16 & $masks[16]) & 0xf]
|
|
|
| $pc2bytes11[($right >> 12 & $masks[12]) & 0xf] | $pc2bytes12[($right >> 8 & $masks[8]) & 0xf]
|
|
| $pc2bytes11[($right >> 12 & $masks[12]) & 0xf] | $pc2bytes12[($right >> 8 & $masks[8]) & 0xf]
|
|
|
| $pc2bytes13[($right >> 4 & $masks[4]) & 0xf];
|
|
| $pc2bytes13[($right >> 4 & $masks[4]) & 0xf];
|
|
|
- $temp = (($righttemp >> 16 & $masks[16]) ^ $lefttemp) & 0x0000ffff;
|
|
|
|
|
|
|
+ $temp = (($righttemp >> 16 & $masks[16]) ^ $lefttemp) & 0x0000ffff;
|
|
|
$keys[$n++] = $lefttemp ^ $temp; $keys[$n++] = $righttemp ^ ($temp << 16);
|
|
$keys[$n++] = $lefttemp ^ $temp; $keys[$n++] = $righttemp ^ ($temp << 16);
|
|
|
}
|
|
}
|
|
|
} //for each iterations
|
|
} //for each iterations
|