michael@0: /* michael@0: * Simple test driver for MPI library michael@0: * michael@0: * Test 8: Probabilistic primality tester 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: #include michael@0: #include michael@0: #include michael@0: michael@0: #define MP_IOFUNC 1 michael@0: #include "mpi.h" michael@0: michael@0: #include "mpprime.h" michael@0: michael@0: int main(int argc, char *argv[]) michael@0: { michael@0: int ix; michael@0: mp_digit num; michael@0: mp_int a; michael@0: michael@0: srand(time(NULL)); michael@0: michael@0: if(argc < 2) { michael@0: fprintf(stderr, "Usage: %s \n", argv[0]); michael@0: return 1; michael@0: } michael@0: michael@0: printf("Test 8: Probabilistic primality testing\n\n"); michael@0: michael@0: mp_init(&a); michael@0: michael@0: mp_read_radix(&a, argv[1], 10); michael@0: michael@0: printf("a = "); mp_print(&a, stdout); fputc('\n', stdout); michael@0: michael@0: printf("\nChecking for divisibility by small primes ... \n"); michael@0: num = 170; michael@0: if(mpp_divis_primes(&a, &num) == MP_YES) { michael@0: printf("it is not prime\n"); michael@0: goto CLEANUP; michael@0: } michael@0: printf("Passed that test (not divisible by any small primes).\n"); michael@0: michael@0: for(ix = 0; ix < 10; ix++) { michael@0: printf("\nPerforming Rabin-Miller test, iteration %d\n", ix + 1); michael@0: michael@0: if(mpp_pprime(&a, 5) == MP_NO) { michael@0: printf("it is not prime\n"); michael@0: goto CLEANUP; michael@0: } michael@0: } michael@0: printf("All tests passed; a is probably prime\n"); michael@0: michael@0: CLEANUP: michael@0: mp_clear(&a); michael@0: michael@0: return 0; michael@0: }