/**
* base conversion
* \param output bignum output
* \param input bignum input
* \param length length of input bignum
* \param ibase input base, must between 2..256
* \param obase output base, must between 2..256
* \return length of bignum in output
* \warning contents of ``input'' will be changed during conversion
*/
int
bconv(unsigned char *output, unsigned char *input, int length, int ibase, int obase)
{
unsigned int rc, divisor;
unsigned char *p, c;
p = output;
while (length > 0)
{
while (input[0] == 0 && length > 0 && ++input)
--length;
if (length)
{
divisor = 0;
for (rc = 0; rc < length; ++rc)
{
divisor *= ibase;
divisor += input[rc];
input[rc] = divisor / obase;
divisor %= obase;
}
*p++ = divisor;
}
}
rc = p - output;
while (--p > output)
{
c = *p;
*p = *output;
*output = c;
++output;
}
return rc;
}
阅读(1092) | 评论(0) | 转发(0) |