-rw-r--r-- 1007 cryptattacktester-20231020/decoding.cpp raw
#include <cassert>
#include "decoding.h"
using namespace std;
vector<bool> decoding_serialize(const vector<vector<bool>> &pk,const vector<bool> &s,const vector<bigint> ¶ms)
{
bigint n = params.at(0);
bigint k = params.at(1);
vector<bool> result;
assert(pk.size() == n-k);
for (auto pkj : pk) {
assert(pkj.size() == k);
result.insert(result.end(),pkj.begin(),pkj.end());
}
assert(s.size() == n-k);
result.insert(result.end(),s.begin(),s.end());
return result;
}
pair<vector<vector<bit>>,vector<bit>> decoding_deserialize(const vector<bit> &bits,const vector<bigint> ¶ms)
{
bigint n = params.at(0);
bigint k = params.at(1);
bigint pos = 0;
vector<vector<bit>> pk;
for (bigint j = 0;j < n-k;++j) {
vector<bit> pkj;
for (bigint i = 0;i < k;++i)
pkj.push_back(bits.at(pos++));
pk.push_back(pkj);
}
vector<bit> s;
for (bigint j = 0;j < n-k;++j)
s.push_back(bits.at(pos++));
assert(pos == bits.size());
return make_pair(pk,s);
}