aboutsummaryrefslogtreecommitdiffstats
path: root/src/cli/is_prime.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli/is_prime.cpp')
-rw-r--r--src/cli/is_prime.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/cli/is_prime.cpp b/src/cli/is_prime.cpp
new file mode 100644
index 000000000..71fec730b
--- /dev/null
+++ b/src/cli/is_prime.cpp
@@ -0,0 +1,50 @@
+/*
+* (C) 2014,2015 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#include "apps.h"
+
+#if defined(BOTAN_HAS_NUMBERTHEORY)
+
+#include <botan/numthry.h>
+
+namespace {
+
+int is_prime(const std::vector<std::string> &args)
+ {
+ if(args.size() != 2 && args.size() != 3)
+ {
+ std::cerr << "Usage: " << args[0] << " n <prob>" << std::endl;
+ return 2;
+ }
+
+ BigInt n(args[1]);
+
+ size_t prob = 56;
+
+ if(args.size() == 3)
+ prob = to_u32bit(args[2]);
+
+ AutoSeeded_RNG rng;
+
+ const bool prime = is_prime(n, rng, prob);
+
+ if(prime)
+ {
+ std::cout << n << " is prime" << std::endl;
+ return 0;
+ }
+ else
+ {
+ std::cout << n << " is not prime" << std::endl;
+ return 1;
+ }
+ }
+
+REGISTER_APP(is_prime);
+
+}
+
+#endif // BOTAN_HAS_NUMBERTHEORY