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 <stdlib.h>
|
|
|
|
#include "dlog.h"
|
|
|
|
|
|
|
|
ulong
|
|
|
|
dlog_bsgs(const dlog_bsgs_t t, ulong b)
|
|
|
|
{
|
|
|
|
ulong i;
|
|
|
|
apow_t c, * x;
|
|
|
|
|
|
|
|
c.ak = b;
|
2016-03-15 15:39:26 +01:00
|
|
|
for (i = 0; i < t->g; i++)
|
2016-03-07 09:55:19 +01:00
|
|
|
{
|
|
|
|
x = bsearch(&c, t->table, t->m, sizeof(apow_t),
|
|
|
|
(int(*)(const void*,const void*))apow_cmp);
|
|
|
|
if (x != NULL)
|
|
|
|
return i * t->m + x->k;
|
2016-03-14 11:14:54 +01:00
|
|
|
c.ak = nmod_mul(c.ak, t->am, t->mod);
|
2016-03-07 09:55:19 +01:00
|
|
|
}
|
2016-03-29 12:52:26 +01:00
|
|
|
flint_printf("Exception (dlog_bsgs). discrete log not found.\n");
|
2016-03-15 15:39:26 +01:00
|
|
|
flint_printf(" table size %wu, cosize %wu mod %wu. %wu not found (a^-m=%wu)\n",
|
|
|
|
t->m, t->g, t->mod.n, b, t->am);
|
2017-02-28 16:50:03 +01:00
|
|
|
flint_abort();
|
2017-06-18 17:06:17 +02:00
|
|
|
return 0; /* dummy return because flint_abort() is not declared noreturn */
|
2016-03-07 09:55:19 +01:00
|
|
|
}
|