mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-12-27 03:42:40 +00:00
Updated fix for php.pear.net bug # 18015
toBits() on an object for which setPrecision(8) has been called should always return 8 bits. As such we'll just iterate backwards instead of forward.
This commit is contained in:
parent
5de5d45bd5
commit
0f95ddc692
@ -605,11 +605,11 @@ class Math_BigInteger {
|
|||||||
{
|
{
|
||||||
$hex = $this->toHex($twos_compliment);
|
$hex = $this->toHex($twos_compliment);
|
||||||
$bits = '';
|
$bits = '';
|
||||||
for ($i = 0, $end = strlen($hex) & 0xFFFFFFF8; $i < $end; $i+=8) {
|
for ($i = strlen($hex) - 8, $start = strlen($hex) & 7; $i >= $start; $i-=8) {
|
||||||
$bits.= str_pad(decbin(hexdec(substr($hex, $i, 8))), 32, '0', STR_PAD_LEFT);
|
$bits = str_pad(decbin(hexdec(substr($hex, $i, 8))), 32, '0', STR_PAD_LEFT) . $bits;
|
||||||
}
|
}
|
||||||
if ($end != strlen($hex)) { // hexdec('') == 0
|
if ($start) { // hexdec('') == 0
|
||||||
$bits.= str_pad(decbin(hexdec(substr($hex, $end))), strlen($hex) & 7, '0', STR_PAD_LEFT);
|
$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');
|
return $this->precision > 0 ? substr($bits, -$this->precision) : ltrim($bits, '0');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user