Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Repeated squaring of polinomial mod r

Status
Not open for further replies.

bbone

Programmer
Joined
Aug 18, 2003
Messages
10
Location
SI
Hi all!

Can somebody please give me any ideas on how to write a function that will compute p(x)^n mod(x^r - 1, n), where n is a large number by using repeated squaring algorithm?
 
I forgot to mention, that I need this only for this kind of polinomials: p(x) = x - a. So I have to compute
(x - a)^n mod (x^r - 1). r < n
 
in would be something like this:

int yourFunc(int x, int a, int n, int r)
{
if(r < n)
((int)pow((x - a), n)) % ((int)pow(x, r) - 1);
}

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
> how to write a function that will compute p(x)^n mod(x^r - 1, n)
I'm guessing that this is for cryptography or something.

If this is so, you will need complete accuracy. The standard integer types do not have the range, and the floating point types are not accurate.

For accuracy with very large numbers, you need a 'BIGNUM' library. Here is one -
--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top