michael@0: /* michael@0: * exptmod.c michael@0: * michael@0: * Command line tool to perform modular exponentiation on arbitrary michael@0: * precision integers. michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include "mpi.h" michael@0: michael@0: int main(int argc, char *argv[]) michael@0: { michael@0: mp_int a, b, m; michael@0: mp_err res; michael@0: char *str; michael@0: int len, rval = 0; michael@0: michael@0: if(argc < 3) { michael@0: fprintf(stderr, "Usage: %s \n", argv[0]); michael@0: return 1; michael@0: } michael@0: michael@0: mp_init(&a); mp_init(&b); mp_init(&m); michael@0: mp_read_radix(&a, argv[1], 10); michael@0: mp_read_radix(&b, argv[2], 10); michael@0: mp_read_radix(&m, argv[3], 10); michael@0: michael@0: if((res = mp_exptmod(&a, &b, &m, &a)) != MP_OKAY) { michael@0: fprintf(stderr, "%s: error: %s\n", argv[0], mp_strerror(res)); michael@0: rval = 1; michael@0: } else { michael@0: len = mp_radix_size(&a, 10); michael@0: str = calloc(len, sizeof(char)); michael@0: mp_toradix(&a, str, 10); michael@0: michael@0: printf("%s\n", str); michael@0: michael@0: free(str); michael@0: } michael@0: michael@0: mp_clear(&a); mp_clear(&b); mp_clear(&m); michael@0: michael@0: return rval; michael@0: }