/* reduce this mod m */ public virtual void Mod(BIG m1) { int k = 0; BIG r = new BIG(0); BIG m = new BIG(m1); Norm(); if (Comp(this, m) < 0) { return; } do { m.FShl(1); k++; } while (Comp(this, m) >= 0); while (k > 0) { m.FShr(1); r.Copy(this); r.Sub(m); r.Norm(); CMove(r, (int)(1 - ((r.w[NLEN - 1] >> (CHUNK - 1)) & 1))); k--; } }
/* convert from byte array to BIG */ public static BIG FromByteArray(sbyte[] b, int n) { BIG m = new BIG(0); for (int i = 0; i < MODBYTES; i++) { m.FShl(8); m.w[0] += (int)b[i + n] & 0xff; //m.inc((int)b[i]&0xff); } return(m); }
/* divide this by m */ public virtual void Div(BIG m1) { int d, k = 0; Norm(); BIG e = new BIG(1); BIG m = new BIG(m1); BIG b = new BIG(this); BIG r = new BIG(0); Zero(); while (Comp(b, m) >= 0) { e.FShl(1); m.FShl(1); k++; } while (k > 0) { m.FShr(1); e.FShr(1); r.Copy(b); r.Sub(m); r.Norm(); d = (int)(1 - ((r.w[NLEN - 1] >> (CHUNK - 1)) & 1)); b.CMove(r, d); r.Copy(this); r.Add(e); r.Norm(); CMove(r, d); k--; } }