getHighestBit() is the most time-consuming (total) function while rsa-encrypting/decrypting.
I found there is much time potential in it, this code reduces the total-decryption time 35%, maybe there are also better strategies.
[code]
int BigInteger::getHighestBit() const throw()
{
/* //old
for (int i = highestBit + 1; --i >= 0;)
if ((values [bitToIndex (i)] & bitToMask (i)) != 0)
return i;
*/
for (int i = bitToIndex (highestBit + 1) ; i>=0 ; i-- ) //why highestBit + 1? why not highestBit
{
uint32 val=values[i];
if (val>0) //assuming that all bits > highestBit are zero
{
int s=0;
while (val>>=1)
{
s++;
}
return s+i*32;
}
}
return -1;
}[/code]