function barrettmu(a) { this.modulus = bicopy(a); this.k = bihighindex(this.modulus) + 1; var b = new bigint; b.digits[2 * this.k] = 1; this.mu = bidivide(b, this.modulus); this.bkplus1 = new bigint; this.bkplus1.digits[this.k + 1] = 1; this.modulo = barrettmu_modulo; this.multiplymod = barrettmu_multiplymod; this.powmod = barrettmu_powmod } function barrettmu_modulo(a) { var b = bidividebyradixpower(a, this.k - 1); var c = bimultiply(b, this.mu); var d = bidividebyradixpower(c, this.k + 1); var e = bimodulobyradixpower(a, this.k + 1); var f = bimultiply(d, this.modulus); var g = bimodulobyradixpower(f, this.k + 1); var h = bisubtract(e, g); if (h.isneg) h = biadd(h, this.bkplus1); var i = bicompare(h, this.modulus) >= 0; while (i) { h = bisubtract(h, this.modulus); i = bicompare(h, this.modulus) >= 0 } return h } function barrettmu_multiplymod(a, b) { var c = bimultiply(a, b); return this.modulo(c) } function barrettmu_powmod(a, b) { var c = new bigint; c.digits[0] = 1; var d = a; var e = b; while (true) { if (0 != (1 & e.digits[0])) c = this.multiplymod(c, d); e = bishiftright(e, 1); if (0 == e.digits[0] && 0 == bihighindex(e)) break; d = this.multiplymod(d, d) } return c }