#include # include # include # include # include # include #include using namespace std; typedef long long int Lint; // 64 bits typedef double Ldouble; struct security { int num_shares; int num_required; }; struct shareStruct { int x; Lint y; }; bool isPrime(Lint n) { int flag = 0; for (int i = 2; i <= n / i; ++i) { if (n % i == 0) { flag = 1; break; } } if (flag == 0) return true; else return false; } Lint genRandInt(int n) { // Returns a random number // between 2**(n-1)+1 and 2**n-1 //long max = (long)powl(2, n) - 1; //long min = (long)powl(2, n - 1) + 1; long max = (long)pow(2, n) - 1; long min = (long)pow(2, n - 1) + 1; Lint result = min + (rand() % ( max - min + 1 ) ); return result; } Lint genPrime() { Lint prime = 10; while (isPrime(prime) == false) { int complexity = 50; prime = genRandInt(complexity); } return prime; } int* encodeSecret(int* poly, const int secret, const int num_required) { poly[num_required-1] = secret; return poly; } Lint getPolyY(const int* poly, int poly_len, int poly_x, const Lint prime) { Lint total = 0; Lint poly_y = 0; for (int i=0; i