Пример #1
0
/* reduces this DBIG mod a DBIG in place */

/*	public void mod(DBIG m)
 *      {
 *              int k=0;
 *              if (comp(this,m)<0) return;
 *
 *              do
 *              {
 *                      m.shl(1);
 *                      k++;
 *              }
 *              while (comp(this,m)>=0);
 *
 *              while (k>0)
 *              {
 *                      m.shr(1);
 *                      if (comp(this,m)>=0)
 *                      {
 *                              sub(m);
 *                              norm();
 *                      }
 *                      k--;
 *              }
 *              return;
 *
 *      }*/

/* return this/c */
    public virtual BIG div(BIG c)
    {
        int  k = 0;
        DBIG m = new DBIG(c);
        BIG  a = new BIG(0);
        BIG  e = new BIG(1);

        norm();

        while (comp(this, m) >= 0)
        {
            e.fshl(1);
            m.shl(1);
            k++;
        }

        while (k > 0)
        {
            m.shr(1);
            e.shr(1);
            if (comp(this, m) > 0)
            {
                a.add(e);
                a.norm();
                sub(m);
                norm();
            }
            k--;
        }
        return(a);
    }
Пример #2
0
/* divide this by m */
    public virtual void div(BIG m)
    {
        int k = 0;

        norm();
        BIG e = new BIG(1);
        BIG b = new BIG(this);

        zero();

        while (comp(b, m) >= 0)
        {
            e.fshl(1);
            m.fshl(1);
            k++;
        }

        while (k > 0)
        {
            m.fshr(1);
            e.fshr(1);
            if (comp(b, m) >= 0)
            {
                add(e);
                norm();
                b.sub(m);
                b.norm();
            }
            k--;
        }
    }
Пример #3
0
/* reduce this mod m */
    public virtual void mod(BIG m)
    {
        int k = 0;

        norm();
        if (comp(this, m) < 0)
        {
            return;
        }
        do
        {
            m.fshl(1);
            k++;
        } while (comp(this, m) >= 0);

        while (k > 0)
        {
            m.fshr(1);
            if (comp(this, m) >= 0)
            {
                sub(m);
                norm();
            }
            k--;
        }
    }
Пример #4
0
/* convert from byte array to BIG */
    public static BIG frombytearray(sbyte[] b, int n)
    {
        BIG m = new BIG(0);

        for (int i = 0; i < ROM.MODBYTES; i++)
        {
            m.fshl(8);
            m.w[0] += (int)b[i + n] & 0xff;
            //m.inc((int)b[i]&0xff);
        }
        return(m);
    }
Пример #5
0
/* this = -this mod Modulus */
    public void neg()
    {
        int  sb;
        long ov;
        BIG  m = new BIG(p);

        norm();

        ov = BIG.EXCESS(x);
        sb = 1;
        while (ov != 0)
        {
            sb++;
            ov >>= 1;
        }

        m.fshl(sb);
        x.rsub(m);

        if (BIG.EXCESS(x) >= ROM.FEXCESS)
        {
            reduce();
        }
    }