Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /*
2 * Simple test driver for MPI library
3 *
4 * Test 7: Random and divisibility tests
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <ctype.h>
14 #include <limits.h>
15 #include <time.h>
17 #define MP_IOFUNC 1
18 #include "mpi.h"
20 #include "mpprime.h"
22 int main(int argc, char *argv[])
23 {
24 mp_digit num;
25 mp_int a, b;
27 srand(time(NULL));
29 if(argc < 3) {
30 fprintf(stderr, "Usage: %s <a> <b>\n", argv[0]);
31 return 1;
32 }
34 printf("Test 7: Random & divisibility tests\n\n");
36 mp_init(&a);
37 mp_init(&b);
39 mp_read_radix(&a, argv[1], 10);
40 mp_read_radix(&b, argv[2], 10);
42 printf("a = "); mp_print(&a, stdout); fputc('\n', stdout);
43 printf("b = "); mp_print(&b, stdout); fputc('\n', stdout);
45 if(mpp_divis(&a, &b) == MP_YES)
46 printf("a is divisible by b\n");
47 else
48 printf("a is not divisible by b\n");
50 if(mpp_divis(&b, &a) == MP_YES)
51 printf("b is divisible by a\n");
52 else
53 printf("b is not divisible by a\n");
55 printf("\nb = mpp_random()\n");
56 mpp_random(&b);
57 printf("b = "); mp_print(&b, stdout); fputc('\n', stdout);
58 mpp_random(&b);
59 printf("b = "); mp_print(&b, stdout); fputc('\n', stdout);
60 mpp_random(&b);
61 printf("b = "); mp_print(&b, stdout); fputc('\n', stdout);
63 printf("\nTesting a for divisibility by first 170 primes\n");
64 num = 170;
65 if(mpp_divis_primes(&a, &num) == MP_YES)
66 printf("It is divisible by at least one of them\n");
67 else
68 printf("It is not divisible by any of them\n");
70 mp_clear(&b);
71 mp_clear(&a);
73 return 0;
74 }