docs: function powMod_(x, y, n) {
    var k1, k2, kn, np;
    if (s7.length!=n.length)
      s7=dup(n);
  
    //for even modulus, use a simple square-and-multiply algorithm,
    //rather than using the more complex Montgomery algorithm.
    if ((n[0]&1)==0) {
      copy_(s7, x);
      copyInt_(x, 1);
      while (!equalsInt(y, 0)) {
        if (y[0]&1)
          multMod_(x, s7, n);
        divInt_(y, 2);
        squareMod_(s7, n);
      }
      return;
    }
  
    //calculate np from n for the Montgomery multiplications
    copyInt_(s7, 0);
    for (kn=n.length; kn>0 && !n[kn-1]; kn--);
    np=radix-inverseModInt(modInt(n, radix), radix);
    s7[kn]=1;
    multMod_(x, s7, n);   // x = x * 2**(kn*bp) mod n
  
    if (s3.length!=x.length)
      s3=dup(x);
    else
      copy_(s3, x);
  
    for (k1=y.length-1; k1>0 & !y[k1]; k1--);  //k1=first nonzero element of y
    if (y[k1]==0) {  //anything to the 0th power is 1
      copyInt_(x, 1);
      return;
    }
    for (k2=1<<(bpe-1); k2 && !(y[k1] & k2); k2>>=1);  //k2=position of first 1 bit in y[k1]
    for (;;) {
      if (!(k2>>=1)) {  //look at next bit of y
        k1--;
        if (k1<0) {
          mont_(x, one, n, np);
          return;
        }
        k2=1<<(bpe-1);
      }
      mont_(x, x, n, np);
  
      if (k2 & y[k1]) //if next bit is a 1
        mont_(x, s3, n, np);
    }
  }