Esempio n. 1
0
    public BF_BInteger Mul(BF_BInteger BI1)
    {
        BF_BInteger res = Zero();

        BF_BInteger[] mul_cache = new BF_BInteger[BYTE_COUNT * 8];
        mul_cache[0] = this.Duplicate();
        for (int i = 1; i < BYTE_COUNT * 8 / 2; i++)
        {
            mul_cache[i] = mul_cache[i - 1].Add(mul_cache[i - 1]);
        }

        uint temp_byte    = 0;
        uint temp_bit     = 0;
        int  number_index = 0;

        for (int i = 0; i < BYTE_COUNT * 8 / 2; i++)
        {
            number_index = BYTE_COUNT - 1 - (i / 8);
            temp_byte    = (uint)(BI1.numbers[number_index]);
            temp_bit     = (uint)(temp_byte & (1 << (i % 8)));
            if (temp_bit != 0)
            {
                res = res.Add(mul_cache[i]);
            }
        }


        return(res);
    }
Esempio n. 2
0
    public BF_BInteger Div(BF_BInteger BI1)
    {
        BF_BInteger res = Zero();

        BF_BInteger[] mul_cache = new BF_BInteger[BYTE_COUNT * 8];
        mul_cache[0] = BI1.Duplicate();
        for (int i = 1; i < BYTE_COUNT * 8 / 2; i++)
        {
            mul_cache[i] = mul_cache[i - 1].Add(mul_cache[i - 1]);
        }
        BF_BInteger temp_div        = Zero();
        BF_BInteger temptest        = Zero();
        uint        temp_byte       = 0;
        uint        temp_bit        = 0;
        int         number_index    = 0;
        int         cache_bit_index = 0;
        int         bit_index       = 0;

        for (int i = 0; i < BYTE_COUNT * 8 / 2; i++)
        {
            cache_bit_index = BYTE_COUNT * 8 / 2 - 1 - i;
            temptest        = temp_div.Add(mul_cache[cache_bit_index]);
            if (temptest.Compare(this) <= 0)
            {
                temp_div     = temptest.Duplicate();
                bit_index    = BYTE_COUNT * 8 / 2 + i;
                number_index = bit_index / 8;
                temp_byte    = (uint)res.numbers[number_index];
                temp_byte    = (uint)(temp_byte | (0x80 >> (i % 8)));
                res.numbers[number_index] = (uint)temp_byte % 256;
            }
        }


        return(res);
    }