On Fri, 2004-01-09 at 06:02, [EMAIL PROTECTED] wrote:
> I am using crypto library to do some calculations. I need to calculate the sqare
> root of a 1024 bit number and round it to nearest integer. The BN_mod_sqrt()
> function would only calculate the sqare root if the input BigNum passed to it
> is a perfect square. Is the any easy work around to do this ??

        I'm guessing you are not wokring in a ring (you do not necessarily want
to use a BN_mod_* function). You could probably implement the Newton
iteration algorithm (http://mathworld.wolfram.com/NewtonsIteration.html)
To compute x = sqrt(n) iterate (until it converges):

        x[i+1] = (x[i]+n/x[i])/2

Nota:
- You shouldn't use this when doing modular calculus you won't get the
real roots.
- In integer, it will round by truncation.

Sincerely,
-- 
Mathias Brossard <[EMAIL PROTECTED]>

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to