diff options
author | Keith Isdale <keith.isdale@nokia.com> | 2010-07-26 14:56:53 +1000 |
---|---|---|
committer | Keith Isdale <keith.isdale@nokia.com> | 2010-07-26 14:56:53 +1000 |
commit | 9f034793bcfc51c2b7c1dd14db806f7258f9a9eb (patch) | |
tree | 63bd0f50ce5b77828ad8205eafd7b9412810499e /botan/doc/examples/make_prime.cpp | |
parent | 619d92cfef29e653bfdf852e83888e50cfc4348f (diff) | |
parent | 65271649dbc90f3af1184ad1b23bdb64c0c07d07 (diff) |
Merge branch 'master' of git://git-nokia.trolltech.com.au/qtsoftware/research/qtuitest
Diffstat (limited to 'botan/doc/examples/make_prime.cpp')
-rw-r--r-- | botan/doc/examples/make_prime.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/botan/doc/examples/make_prime.cpp b/botan/doc/examples/make_prime.cpp new file mode 100644 index 0000000..0c90b2b --- /dev/null +++ b/botan/doc/examples/make_prime.cpp @@ -0,0 +1,73 @@ +#include <botan/numthry.h> +#include <botan/auto_rng.h> +#include <botan/botan.h> + +using namespace Botan; + +#include <set> +#include <iostream> +#include <iterator> +#include <map> + +int main() + { + Botan::LibraryInitializer init; + AutoSeeded_RNG 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"; + } + */ + } |