arb/dlog/modpe.c

42 lines
1 KiB
C
Raw Permalink Normal View History

2016-09-06 15:43:12 +02:00
/*
2016-03-07 09:55:19 +01:00
Copyright (C) 2016 Pascal Molin
2016-09-06 15:43:12 +02:00
This file is part of Arb.
Arb is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version. See <http://www.gnu.org/licenses/>.
*/
2016-03-07 09:55:19 +01:00
#include "dlog.h"
ulong
dlog_modpe(const dlog_modpe_t t, ulong b)
{
ulong x;
if (t->p == 2)
return dlog_mod2e(t, b);
2016-03-29 12:52:26 +01:00
2016-03-07 09:55:19 +01:00
x = dlog_precomp(t->modp, b % t->p);
2016-03-29 12:52:26 +01:00
2016-03-25 15:11:14 +01:00
if (t->e > 1)
{
ulong b1, y;
#if 0
b1 = nmod_mul(b, nmod_pow_ui(t->inva, x, t->pe), t->pe);
y = dlog_1modpe(t->modpe.rec, b1, t->p, t->e, t->pe);
2016-03-25 15:11:14 +01:00
y = y % t->pe1;
x = x + (t->p - 1) * y;
#else
b1 = nmod_pow_ui(b, t->p - 1, t->pe);
y = dlog_1modpe(t->modpe, b1, t->p, t->e, t->pe);
y = y % t->pe1;
2016-03-25 15:11:14 +01:00
x = n_submod(x, y % (t->p - 1), t->p - 1);
x = y + t->pe1 * x;
#endif
}
2016-03-29 12:52:26 +01:00
2016-03-07 09:55:19 +01:00
return x;
}