libbrandt/smc.c

45 lines
1.3 KiB
C
Raw Normal View History

2016-06-01 01:08:43 +02:00
/* This file is part of libbrandt.
* Copyright (C) 2016 GNUnet e.V.
*
* libbrandt is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* libbrandt is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* libbrandt. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file smc.c
* @brief Implementation of the smc primitives.
*/
#include <pari/pari.h>
GEN
smc_hextodec(char *s) /* int */
{
long i, tmp;
GEN ret = gen_0; /* int */
GEN v = gtovecsmall(strtoGENstr(s)); /* vecsmall */
for (i = 1; i < lg(v); ++i)
{
if ((v[i] >= '0') && (v[i] <= '9'))
tmp = v[i] - '0';
else if ((v[i] >= 'a') && (v[i] <= 'f'))
tmp = v[i] + 10 - 'a';
else if ((v[i] >= 'A') && (v[i] <= 'F'))
tmp = v[i] + 10 - 'A';
else
pari_err(e_MISC, "invalid input format");
ret = addis(shifti(ret, 4), tmp);
}
return ret;
}