예제 #1
0
GaloisFieldDict GaloisFieldDict::gf_random(const unsigned long &n_val,
                                           gmp_randstate_t &state) const
{
    std::vector<integer_class> v(n_val + 1);
    for (int i = 0; i < n_val; ++i) {
        integer_class temp;
        mp_urandomm(temp, state, modulo_);
        v[i] = temp;
    }
    v[n_val] = 1_z;
    return GaloisFieldDict::from_vec(v, modulo_);
}
예제 #2
0
파일: ntheory.cpp 프로젝트: ivme/symengine
int factor_pollard_rho_method(const Ptr<RCP<const Integer>> &f,
                              const Integer &n, unsigned retries)
{
    int ret_val = 0;
    integer_class rop, nm1, nm4, a, s;
    gmp_randstate_t state;

    gmp_randinit_default(state);
    gmp_randseed_ui(state, retries);
    nm1 = n.as_integer_class() - 1;
    nm4 = n.as_integer_class() - 4;

    for (unsigned i = 0; i < retries and ret_val == 0; ++i) {
        mp_urandomm(a, state, nm1);
        mp_urandomm(s, state, nm4);
        s = s + 1;
        ret_val = _factor_pollard_rho_method(rop, n.as_integer_class(), a, s);
    }

    if (ret_val != 0)
        *f = integer(std::move(rop));
    gmp_randclear(state);
    return ret_val;
}
예제 #3
0
파일: ntheory.cpp 프로젝트: ivme/symengine
int factor_pollard_pm1_method(const Ptr<RCP<const Integer>> &f,
                              const Integer &n, unsigned B, unsigned retries)
{
    int ret_val = 0;
    integer_class rop, nm4, c;
    gmp_randstate_t state;

    gmp_randinit_default(state);
    gmp_randseed_ui(state, retries);
    nm4 = n.as_integer_class() - 4;

    for (unsigned i = 0; i < retries and ret_val == 0; ++i) {
        mp_urandomm(c, state, nm4);
        c = c + 2;
        ret_val = _factor_pollard_pm1_method(rop, n.as_integer_class(), c, B);
    }

    if (ret_val != 0)
        *f = integer(std::move(rop));
    gmp_randclear(state);
    return ret_val;
}