aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-18 13:06:17 +0000
committerlloyd <[email protected]>2008-09-18 13:06:17 +0000
commit8f404a0dc095ad0ab87eabac3f95f56adea71ce1 (patch)
treee84b166e6466f8e26522f7c9cd1bf4859fb2dd8e /doc
parent643112a56d34c4f83def34fb3fc4fd9dbf2ffc1a (diff)
Add a test app for random_prime in examples
Diffstat (limited to 'doc')
-rw-r--r--doc/examples/make_prime.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/doc/examples/make_prime.cpp b/doc/examples/make_prime.cpp
new file mode 100644
index 000000000..ab84e1cdc
--- /dev/null
+++ b/doc/examples/make_prime.cpp
@@ -0,0 +1,69 @@
+#include <botan/numthry.h>
+
+using namespace Botan;
+
+#include <set>
+#include <iostream>
+#include <iterator>
+#include <map>
+
+int main()
+ {
+ RandomNumberGenerator* rng = RandomNumberGenerator::make_rng();
+
+ std::set<BigInt> primes;
+
+ std::map<int, int> bit_count;
+
+ int not_new = 0;
+
+ while(primes.size() < 10000)
+ {
+ u32bit start_cnt = primes.size();
+
+ u32bit bits = 18;
+
+ if(rng->next_byte() % 128 == 0)
+ bits -= rng->next_byte() % (bits-2);
+
+ bit_count[bits]++;
+
+ //std::cout << "random_prime(" << bits << ")\n";
+
+ BigInt p = random_prime(*rng, bits);
+
+ if(p.bits() != bits)
+ {
+ std::cout << "Asked for " << bits << " got " << p
+ << " " << p.bits() << " bits\n";
+ return 1;
+ }
+
+ primes.insert(random_prime(*rng, bits));
+
+ if(primes.size() != start_cnt)
+ std::cout << primes.size() << "\n";
+ else
+ not_new++;
+
+ //std::cout << "miss: " << not_new << "\n";
+
+ if(not_new % 100000 == 0)
+ {
+ for(std::map<int, int>::iterator i = bit_count.begin(); i != bit_count.end(); ++i)
+ std::cout << "bit_count[" << i->first << "] = "
+ << i->second << "\n";
+ std::copy(primes.begin(), primes.end(),
+ std::ostream_iterator<BigInt>(std::cout, " "));
+ }
+ }
+
+ std::cout << "Generated all? primes\n";
+ /*
+ for(u32bit j = 0; j != PRIME_TABLE_SIZE; ++j)
+ {
+ if(primes.count(PRIMES[j]) != 1)
+ std::cout << "Missing " << PRIMES[j] << "\n";
+ }
+ */
+ }