#include "decoding.h" #include "bruteforce.h" using namespace std; vector bruteforce( const vector &bits, const vector ¶ms, const vector &attackparams ) { bigint n = params.at(0); bigint k = params.at(1); bigint w = params.at(2); bigint iters = attackparams.at(0); auto inputs = decoding_deserialize(bits,params); auto pk = inputs.first; auto ct = inputs.second; vector> H; for (bigint i = 0;i < n-k;++i) { vector Hi; for (bigint j = 0;j < n-k;++j) Hi.push_back(bit(i == j)); Hi.insert(Hi.end(),pk.at(i).begin(),pk.at(i).end()); H.push_back(Hi); } vector result(n); vector positions; for (bigint j = 0;j < w;++j) positions.push_back(j); for (bigint iter = 0;iter < iters;++iter) { vector Hguess(n-k); for (bigint i = 0;i < n-k;++i) for (bigint j = 0;j < w;++j) Hguess.at(i) ^= H.at(i).at(positions.at(j)); bit mismatch; for (bigint j = 0;j < n-k;++j) mismatch |= Hguess[j]^ct[j]; for (bigint j = 0;j < n;++j) result.at(j) &= mismatch; for (bigint j = 0;j < w;++j) result.at(positions.at(j)) = result.at(positions.at(j)).orn(mismatch); for (bigint j = w-1;j >= 0;--j) { positions.at(j) += 1; if (positions.at(j) <= n-w+j) { while (++j < w) positions.at(j) = positions.at(j-1)+1; break; } } } return result; }