-rw-r--r-- 570 cryptattacktester-20231020/bruteforce2_prob.cpp raw
#include <cassert>
#include "bruteforce2_prob.h"
using namespace std;
bigfloat bruteforce2_prob(const vector<bigint> ¶ms,const vector<bigint> &attackparams)
{
bigint n = params.at(0);
bigint k = params.at(1);
bigint w = params.at(2);
bigint iters = attackparams.at(0);
bigint successes = 0;
for (bigint v = 0;v <= w;++v) {
bigint binkv = binomial(k,v);
iters -= binkv;
successes += binkv*binomial(n-k,w-v);
assert(iters >= 0);
if (iters == 0) break;
}
assert(iters == 0);
return bigfloat(successes)/bigfloat(binomial(n,w));
}