RSA and convergents

87 Views Asked by At

I'm trying to do a function in PARI that computes a^(c*q_t) mod n; where c and n are such big numbers, and q_t is the denominator of a convergent of n/c. This is for RSA purposes. I'd just like to improve this function, so that computer would do it by itself, I mean it would find the q_t by itself and discover also the a itself. So, it would need two more parameters. I have no idea how to do this. This is my function:

expmod(a,e,m)={
  local(x,y,s,d); x=a; y=1; s=e;
  while(s,d=s%2;s=(s-d)/2;
  if(d,y=(y*x)%m); x=(x*x)%m);
  return(y)}
1

There are 1 best solutions below

0
On

PARI has a built in type Mod(a,m) that keeps track of the modulus through exponents.

lift(Mod(a,m)^e)