1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
Copyright (C) 2015 Jonathan Bober
Copyright (C) 2016 Fredrik Johansson
Copyright (C) 2016 Pascal Molin
This file is part of FLINT.
FLINT 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 3 of the License, or
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/
#include "dlog.h"
#include "dirichlet.h"
/* assume m is invertible */
void
dirichlet_char_log(dirichlet_char_t x, const dirichlet_group_t G, ulong m)
{
slong k;
/* even part */
if (G->neven >= 1)
{
x->log[0] = (m % 4 == 3);
if (G->neven == 2)
{
ulong m2 = (x->log[0]) ? -m % G->q_even : m % G->q_even;
if (G->P[1].dlog == NULL)
x->log[1] = dlog_mod2e_1mod4(m2, G->P[1].e,
nmod_inv(5, G->P[1].pe), G->P[1].pe);
else
x->log[1] = dlog_precomp(G->P[1].dlog, m2);
}
}
/* odd part */
for (k = G->neven; k < G->num; k++)
{
dirichlet_prime_group_struct P = G->P[k];
if (P.dlog == NULL)
{
x->log[k] = dlog_once(m % P.pe.n, P.g, P.pe, P.phi.n);
}
else
{
x->log[k] = dlog_precomp(P.dlog, m % P.pe.n);
}
}
/* keep value m */
x->n = m;
}