openGPMP
Open Source Mathematics Package
prime_test.hpp
Go to the documentation of this file.
1 /*************************************************************************
2  *
3  * Project
4  * _____ _____ __ __ _____
5  * / ____| __ \| \/ | __ \
6  * ___ _ __ ___ _ __ | | __| |__) | \ / | |__) |
7  * / _ \| '_ \ / _ \ '_ \| | |_ | ___/| |\/| | ___/
8  *| (_) | |_) | __/ | | | |__| | | | | | | |
9  * \___/| .__/ \___|_| |_|\_____|_| |_| |_|_|
10  * | |
11  * |_|
12  *
13  * Copyright (C) Akiel Aries, <akiel@akiel.org>, et al.
14  *
15  * This software is licensed as described in the file LICENSE, which
16  * you should have received as part of this distribution. The terms
17  * among other details are referenced in the official documentation
18  * seen here : https://akielaries.github.io/openGPMP/ along with
19  * important files seen in this project.
20  *
21  * You may opt to use, copy, modify, merge, publish, distribute
22  * and/or sell copies of the Software, and permit persons to whom
23  * the Software is furnished to do so, under the terms of the
24  * LICENSE file. As this is an Open Source effort, all implementations
25  * must be of the same methodology.
26  *
27  *
28  *
29  * This software is distributed on an AS IS basis, WITHOUT
30  * WARRANTY OF ANY KIND, either express or implied.
31  *
32  ************************************************************************/
33 
39 #ifndef PRIMES_TEST_HPP
40 #define PRIMES_TEST_HPP
41 
42 #include <cstdint>
43 #include <stdio.h>
44 #include <vector>
45 
46 namespace gpmp {
51  public:
59  bool is_prime(uint64_t n);
60 
71  bool compute_miller_rabin(uint64_t d, uint64_t n);
72 
83  bool miller_rabin_prime(uint64_t n, uint64_t iters);
84 
97  void miller_rabin(uint64_t iters, uint64_t min_val, uint64_t max_val);
98 
99  bool witness(uint64_t n, uint64_t d, uint64_t a, uint64_t s);
100 
101  /* Agrawal–Kayal–Saxena primality deterministic algorithm */
102  bool AKS(uint64_t n);
103 
104  /* Lucas Primality Test */
105  // uint64_t lucas(uint64_t n);
106 
107  /* algorithms finding a prime number */
108  uint64_t jacobian_number(uint64_t a, uint64_t n);
109 
110  /* determine if var_p is composite or probably prime */
111  bool solovoy_strassen(uint64_t p, uint64_t iters);
112 
113  /* modulo + power of input */
114  uint64_t mod_mul(uint64_t a, uint64_t b, uint64_t m);
115 
116  uint64_t mod_pow(uint64_t a, uint64_t b, uint64_t m);
117 
118  // uint64_t mod_pow(uint64_t base, uint64_t exponent, uint64_t mod);
119  /* satifies congruence relation:b^n - 1 = b (mod n) */
120  bool carmichael_num(uint64_t n);
121 
122  /* finds the prime numbers up to a limit */
123  // void sieve_of_eratosthenes(uint64_t n);
124 
125  /* Eulers Totient Function */
126  uint64_t ETF(uint64_t n);
127 };
128 
129 } // namespace gpmp
130 
131 #endif
bool miller_rabin_prime(uint64_t n, uint64_t iters)
Modified primes algorithm.
Definition: prime_test.cpp:183
uint64_t jacobian_number(uint64_t a, uint64_t n)
Definition: prime_test.cpp:275
uint64_t mod_mul(uint64_t a, uint64_t b, uint64_t m)
Definition: prime_test.cpp:59
uint64_t ETF(uint64_t n)
Definition: prime_test.cpp:408
bool carmichael_num(uint64_t n)
Definition: prime_test.cpp:349
bool witness(uint64_t n, uint64_t d, uint64_t a, uint64_t s)
Definition: prime_test.cpp:166
void miller_rabin(uint64_t iters, uint64_t min_val, uint64_t max_val)
Miller-Rabin driver, prints values that satisfy conditions.
Definition: prime_test.cpp:207
uint64_t mod_pow(uint64_t a, uint64_t b, uint64_t m)
Definition: prime_test.cpp:72
bool is_prime(uint64_t n)
Determine if an integer is prime.
Definition: prime_test.cpp:102
bool compute_miller_rabin(uint64_t d, uint64_t n)
Algorithm determining liklihood a number is prime.
Definition: prime_test.cpp:119
bool solovoy_strassen(uint64_t p, uint64_t iters)
Definition: prime_test.cpp:325
bool AKS(uint64_t n)
Definition: prime_test.cpp:226
The source C++ openGPMP namespace.