security/nss/lib/freebl/mpi/utils/basecvt.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /*
     2  *  basecvt.c
     3  *
     4  *  Convert integer values specified on the command line from one input
     5  *  base to another.  Accepts input and output bases between 2 and 36
     6  *  inclusive.
     7  *
     8  * This Source Code Form is subject to the terms of the Mozilla Public
     9  * License, v. 2.0. If a copy of the MPL was not distributed with this
    10  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    12 #include <stdio.h>
    13 #include <stdlib.h>
    14 #include <string.h>
    16 #include "mpi.h"
    18 #define IBASE     10
    19 #define OBASE     16
    20 #define USAGE     "Usage: %s ibase obase [value]\n"
    21 #define MAXBASE   64
    22 #define MINBASE   2
    24 int main(int argc, char *argv[])
    25 {
    26   int    ix, ibase = IBASE, obase = OBASE;
    27   mp_int val;
    29   ix = 1;
    30   if(ix < argc) {
    31     ibase = atoi(argv[ix++]);
    33     if(ibase < MINBASE || ibase > MAXBASE) {
    34       fprintf(stderr, "%s: input radix must be between %d and %d inclusive\n",
    35 	      argv[0], MINBASE, MAXBASE);
    36       return 1;
    37     }
    38   }
    39   if(ix < argc) {
    40     obase = atoi(argv[ix++]);
    42     if(obase < MINBASE || obase > MAXBASE) {
    43       fprintf(stderr, "%s: output radix must be between %d and %d inclusive\n",
    44 	      argv[0], MINBASE, MAXBASE);
    45       return 1;
    46     }
    47   }
    49   mp_init(&val);
    50   while(ix < argc) {
    51     char  *out;
    52     int    outlen;
    54     mp_read_radix(&val, argv[ix++], ibase);
    56     outlen = mp_radix_size(&val, obase);
    57     out = calloc(outlen, sizeof(char));
    58     mp_toradix(&val, out, obase);
    60     printf("%s\n", out);
    61     free(out);
    62   }
    64   mp_clear(&val);
    66   return 0;
    67 }

mercurial