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
|
|
|
|
2016-03-14 11:14:54 +01:00
|
|
|
#include "dlog.h"
|
2016-03-07 09:55:19 +01:00
|
|
|
|
2016-03-29 12:09:21 +01:00
|
|
|
/* for odd prime p, assume b1 = 1 mod p */
|
2016-03-07 09:55:19 +01:00
|
|
|
ulong
|
2016-09-09 11:13:20 +02:00
|
|
|
dlog_1modpe_1modp(ulong b1, ulong p, ulong e, ulong inv1p, nmod_t pe)
|
2016-03-07 09:55:19 +01:00
|
|
|
{
|
2016-03-25 15:11:14 +01:00
|
|
|
int f;
|
|
|
|
ulong x, xf, pf, pf1;
|
|
|
|
pf1 = 1;
|
|
|
|
pf = p;
|
|
|
|
x = 0;
|
|
|
|
for (f = 1; f < e; f++)
|
2016-03-29 12:52:26 +01:00
|
|
|
{
|
2016-03-25 15:11:14 +01:00
|
|
|
if (b1 % pf != 1)
|
2016-03-29 12:09:21 +01:00
|
|
|
{
|
|
|
|
flint_printf("ERROR dlog_1modpe_1modp: %wu %% %wu != 1 mod %wu\n\n",
|
|
|
|
b1, pf, pe.n);
|
2017-02-28 16:50:03 +01:00
|
|
|
flint_abort();
|
2016-03-29 12:09:21 +01:00
|
|
|
}
|
2016-03-25 15:11:14 +01:00
|
|
|
xf = (b1 - 1) / pf;
|
|
|
|
xf = (xf % p) * pf1;
|
|
|
|
x += xf;
|
|
|
|
b1 = nmod_mul(b1, nmod_pow_ui(inv1p, xf, pe), pe);
|
|
|
|
pf1 = pf;
|
|
|
|
pf *= p;
|
|
|
|
}
|
|
|
|
return x;
|
2016-03-07 09:55:19 +01:00
|
|
|
}
|