Merge branch '1.0' into 2.0

This commit is contained in:
terrafrost 2018-01-22 07:22:29 -06:00
commit 364e05babf
2 changed files with 14 additions and 2 deletions

View File

@ -2868,8 +2868,7 @@ class BigInteger
switch (MATH_BIGINTEGER_MODE) { switch (MATH_BIGINTEGER_MODE) {
case self::MODE_GMP: case self::MODE_GMP:
$temp = new static(); $temp = new static();
$temp->value = gmp_xor($this->value, $x->value); $temp->value = gmp_xor(gmp_abs($this->value), gmp_abs($x->value));
return $this->_normalize($temp); return $this->_normalize($temp);
case self::MODE_BCMATH: case self::MODE_BCMATH:
$left = $this->toBytes(); $left = $this->toBytes();
@ -2885,6 +2884,7 @@ class BigInteger
$length = max(count($this->value), count($x->value)); $length = max(count($this->value), count($x->value));
$result = $this->copy(); $result = $this->copy();
$result->is_negative = false;
$result->value = array_pad($result->value, $length, 0); $result->value = array_pad($result->value, $length, 0);
$x->value = array_pad($x->value, $length, 0); $x->value = array_pad($x->value, $length, 0);

View File

@ -209,6 +209,18 @@ abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase
$z = $this->getInstance('BC98BC98BC98BC98BC98BC98', 16); $z = $this->getInstance('BC98BC98BC98BC98BC98BC98', 16);
$this->assertSame($z->toHex(), $x->bitwise_XOR($y)->toHex()); $this->assertSame($z->toHex(), $x->bitwise_XOR($y)->toHex());
// @group github1245
$a = $this->getInstance(1);
$b = $this->getInstance(-2);
$c = $a->bitwise_xor($b);
$this->assertSame("$c", '3');
$a = $this->getInstance('-6725760161961546982');
$b = $this->getInstance(51);
$c = $a->bitwise_xor($b);
$this->assertSame("$c", '6725760161961546965');
} }
public function testBitwiseNOT() public function testBitwiseNOT()