-rw-r--r-- 726 cryptattacktester-20231020/bruteforce2_cost.cpp raw
#include <cassert>
#include "index_cost.h"
#include "bit_vector_cost.h"
#include "bruteforce2_cost.h"
using namespace std;
bigint bruteforce2_cost(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 cost = 0;
for (bigint v = 0;v <= w;++v) {
bigint binkv = binomial(k,v);
iters -= binkv;
for (bigint u = 1;u <= v;++u)
cost += binomial(k-v+u,u)*(n-k); // adding vectors
cost += binkv*bit_vector_hamming_weight_isnot_cost(n-k,w-v);
cost += binkv*(n+v+2*(n-k));
assert(iters >= 0);
if (iters == 0) break;
}
assert(iters == 0);
return cost;
}