diff --git a/phpseclib/Math/BigInteger.php b/phpseclib/Math/BigInteger.php index 8752a835..c175ce4e 100644 --- a/phpseclib/Math/BigInteger.php +++ b/phpseclib/Math/BigInteger.php @@ -67,7 +67,7 @@ * @author Jim Wigginton * @copyright MMVI Jim Wigginton * @license http://www.gnu.org/licenses/lgpl.txt - * @version $Id: BigInteger.php,v 1.33 2010-03-22 22:32:03 terrafrost Exp $ + * @version $Id: BigInteger.php,v 1.33 2010/03/22 22:32:03 terrafrost Exp $ * @link http://pear.php.net/package/Math_BigInteger */ @@ -596,9 +596,10 @@ class Math_BigInteger { { $hex = $this->toHex($twos_compliment); $bits = ''; - for ($i = 0; $i < strlen($hex); $i+=8) { + for ($i = 0, $end = strlen($hex) & 0xFFFFFFF8; $i < $end; $i+=8) { $bits.= str_pad(decbin(hexdec(substr($hex, $i, 8))), 32, '0', STR_PAD_LEFT); } + $bits.= str_pad(decbin(hexdec(substr($hex, $end))), strlen($hex) & 7, '0', STR_PAD_LEFT); return $this->precision > 0 ? substr($bits, -$this->precision) : ltrim($bits, '0'); }