diff options
author | lloyd <[email protected]> | 2014-11-03 22:16:51 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-11-03 22:16:51 +0000 |
commit | bcd83686c3daed38974d1f9b533c07d35c5a7476 (patch) | |
tree | 3203d6f30423ebf3b7b5b3d4aa2b9ecc9ce5ba5e /src/cmd/is_prime.cpp | |
parent | d623823e7e0d2754343ab498f48976e91180d24f (diff) |
Various small fixes and cleanups, new is_prime util
Diffstat (limited to 'src/cmd/is_prime.cpp')
-rw-r--r-- | src/cmd/is_prime.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/cmd/is_prime.cpp b/src/cmd/is_prime.cpp new file mode 100644 index 000000000..658401690 --- /dev/null +++ b/src/cmd/is_prime.cpp @@ -0,0 +1,33 @@ +#include "apps.h" +#include <botan/numthry.h> + +int is_prime_main(int argc, char* argv[]) + { + if(argc != 2 && argc != 3) + { + std::cerr << "Usage: " << argv[0] << " n <prob>\n"; + return 2; + } + + BigInt n(argv[1]); + + size_t prob = 56; + + if(argc == 3) + prob = to_u32bit(argv[2]); + + AutoSeeded_RNG rng; + + const bool prime = is_prime(n, rng, prob); + + if(prime) + { + std::cout << n << " is prime\n"; + return 0; + } + else + { + std::cout << n << " is not prime\n"; + return 1; + } + } |