-rw-r--r-- 684 cryptattacktester-20230614/permutation.h raw
#ifndef permutation_h
#define permutation_h
#include <vector>
#include "bigint.h"
std::vector<bigint> permutation_gen(bigint);
class permutation {
std::vector<bigint> pi;
public:
permutation(bigint n) : pi(permutation_gen(n)) { }
permutation(bigint n,bigint plus)
{
plus %= n;
if (plus < 0) plus += n;
for (bigint i = 0; i < n; i++)
pi.push_back((i + plus) % n);
}
template<class T>
void permute(std::vector<T> &v,bigint offset=0)
{
std::vector<T> w = v;
for (bigint i = 0; i < pi.size(); i++)
w.at(i + offset) = v.at(pi.at(i) + offset);
for (bigint i = 0; i < v.size(); i++)
v.at(i) = w.at(i);
}
} ;
#endif