From c2c3e9420d5114388757e38ee4f567ebf61dcda9 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 2 Sep 2012 11:06:53 -0500 Subject: [PATCH] Negative numbers should be prepended with a 0 --- phpseclib/Math/BigInteger.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/phpseclib/Math/BigInteger.php b/phpseclib/Math/BigInteger.php index df6d96a2..13420762 100644 --- a/phpseclib/Math/BigInteger.php +++ b/phpseclib/Math/BigInteger.php @@ -611,7 +611,13 @@ class Math_BigInteger { if ($start) { // hexdec('') == 0 $bits = str_pad(decbin(hexdec(substr($hex, 0, $start))), 8, '0', STR_PAD_LEFT) . $bits; } - return $this->precision > 0 ? substr($bits, -$this->precision) : ltrim($bits, '0'); + $result = $this->precision > 0 ? substr($bits, -$this->precision) : ltrim($bits, '0'); + + if ($twos_compliment && $this->compare(new Math_BigInteger()) > 0 && $this->precision <= 0) { + return '0' . $result; + } + + return $result; } /**