diff --git a/bin/ciphertext.o b/bin/ciphertext.o index 53e2c279b2ccdaff6da70a2d7f9352b09e9d4e99..3dfc07a20ecfae7016cfddd6cfaaf91905c010c1 100644 Binary files a/bin/ciphertext.o and b/bin/ciphertext.o differ diff --git a/bin/ckks.o b/bin/ckks.o index eea74b8fe3a4d9aabe4ec020ca887b674612099a..a9db71f2c10d6a4cb920d45aa5c634611f8d0cf5 100644 Binary files a/bin/ckks.o and b/bin/ckks.o differ diff --git a/bin/encoder.o b/bin/encoder.o index bb082c90422ecb58de966ffdb42466f0808f5e8e..ef7f57bf2f19eb83b8f800e61d192892fa7a4f53 100644 Binary files a/bin/encoder.o and b/bin/encoder.o differ diff --git a/bin/evalkey.o b/bin/evalkey.o index 074e988607447c5f791d73b2cc816999c28e98ab..11ee60d8cd8461b178700bb1bec57d0f8b23cf57 100644 Binary files a/bin/evalkey.o and b/bin/evalkey.o differ diff --git a/bin/polynomial.o b/bin/polynomial.o index 98458cd5468e8305bf6916295bfc62c8605de048..6de4feeb93bd8e693e882095f2f9081a86dc29ac 100644 Binary files a/bin/polynomial.o and b/bin/polynomial.o differ diff --git a/run b/run index b1c3c0ea847007b73cfc044827f9e4f452b6ead7..33d2612199897b9cc421709da90bbe9a19ce84c9 100755 Binary files a/run and b/run differ diff --git a/src/ciphertext.cpp b/src/ciphertext.cpp index e1bf748641f2467193a3ea526409ee80c4b3ab5a..490cc3d58b3371875a9ded50dba8fef184e7a90b 100644 --- a/src/ciphertext.cpp +++ b/src/ciphertext.cpp @@ -2,11 +2,13 @@ #include <cmath> #include <random> #include "ciphertext.h" +#include <iostream> +using namespace std; Ciphertext::Ciphertext(Polynomial _c0, Polynomial _c1){ - c0 = Polynomial(4, _c0.coeffs); - c1 = Polynomial(4, _c1.coeffs); + c0 = Polynomial(_c0.degree, _c0.coeffs); + c1 = Polynomial(_c1.degree, _c1.coeffs); } Ciphertext Ciphertext:: operator + (Ciphertext const &obj){ diff --git a/src/ckks.cpp b/src/ckks.cpp index 8530b2b2c4a75660cfd94ef7d5bbc425c7bcb05e..e57c21c276115b4622361bb31ed8917dd497d0d6 100644 --- a/src/ckks.cpp +++ b/src/ckks.cpp @@ -73,38 +73,21 @@ Ciphertext CKKS::mult(Ciphertext ct1, Ciphertext ct2){ Polynomial d2 = ((ct1.c0 * ct2.c1) + (ct2.c0 * ct1.c1)).modCoeff(ql); Polynomial d3 = (ct1.c1 * ct2.c1).modCoeff(ql); - // Relin + // Relin --> Still weird Polynomial d3_0 = (d3 * evk.b).scaleRoundCoeff(1.0/1000.0); Polynomial d3_1 = (d3 * evk.a).scaleRoundCoeff(1.0/1000.0); Polynomial outC0 = d1.modCoeff(ql) + d3_0.modCoeff(ql); - // cout << "d0': " ; - // outC0.printPol(); - Polynomial outC1 = d2.modCoeff(ql) + d3_1.modCoeff(ql); - // cout << "d1'*s: "; - // (outC1*sk.s).printPol(); - - Polynomial test = outC0 + (outC1 * sk.s); - cout << "d0' + d1'*s: "; - (test.modCoeff(ql)).printPol(); - cout << endl; - - Polynomial test2 = d1 + (d2*sk.s) + (d3 * sk.s*sk.s); - cout << "d0 + d1*s + d2*s^2: "; - (test2.modCoeff(ql)).printPol(); // Rescale ql = (double)ql / (double)pl[level-1]; + Polynomial c0 = outC0.scaleRoundCoeff(1.0/(double)pl[level-1]); + Polynomial c1 = outC1.scaleRoundCoeff(1.0/(double)pl[level-1]); - outC0.scaleRoundCoeff(1.0/(double)pl[level-1]); - outC0.modCoeff(ql); - - outC1.scaleRoundCoeff(1.0/(double)pl[level-1]); - outC1.modCoeff(ql); - level -= 1; - Ciphertext out(outC0, outC1); + cout << "marker" << endl; + Ciphertext out(c0.modCoeff(ql), c1.modCoeff(ql)); return out; } \ No newline at end of file diff --git a/src/encoder.cpp b/src/encoder.cpp index 41308ebf268d099b8f8a60e9a3f2133913d6c061..f7a4f961f71c237ac2e296e3e57e22a1db5140ff 100644 --- a/src/encoder.cpp +++ b/src/encoder.cpp @@ -83,7 +83,7 @@ dcomparr Encoder::sigma(Polynomial pol){ } }else{ int R = 2; - dcomplex tempVandermonde[10][10]; + dcomplex tempVandermonde[100][100]; while (R < pol.degree){ R <<=2; diff --git a/src/encoder.h b/src/encoder.h index 44235897222a02d319ce939445892fb22757a5e8..7daa3a03e8b7de30afa6c49ae8d3eabe6e5ae91c 100644 --- a/src/encoder.h +++ b/src/encoder.h @@ -12,7 +12,7 @@ typedef Eigen::Matrix<dcomplex, 4, 4> Matrix4dc; typedef Eigen::Matrix<dcomplex, 4, 1> Matrix1dc; struct dcomparr { - dcomplex arr[10]; + dcomplex arr[100]; }; struct coeffarr { diff --git a/src/evalkey.cpp b/src/evalkey.cpp index ab390c58c8c634932541f781e6db39481a9a1c3f..a71b07bf9f5d6d5819abe126810ccb1fe5f5b2bf 100644 --- a/src/evalkey.cpp +++ b/src/evalkey.cpp @@ -9,7 +9,7 @@ using namespace std; EvalKey::EvalKey(Polynomial _s, int q){ a = Polynomial(4); b = Polynomial(4); - p = 10000; + p = 1000; s = _s; cout << q << endl; generateA(4, 4); diff --git a/src/polynomial.cpp b/src/polynomial.cpp index 1e0520f78a99ed79db179c7c27580e7e56127564..090b5f1f3101b508847eb4b8d38efa4567692775 100644 --- a/src/polynomial.cpp +++ b/src/polynomial.cpp @@ -69,9 +69,11 @@ Polynomial Polynomial::dot (Polynomial const &obj){ Polynomial Polynomial::operator + (Polynomial const &obj){ int deg = max(obj.degree, degree); double coeff[deg]; + for (int i = 0; i<deg; i++){ coeff[i] = 0; } + for(int i=0; i<deg; i++){ coeff[i] = coeffs[i] + obj.coeffs[i]; } @@ -99,7 +101,14 @@ Polynomial Polynomial::operator * (Polynomial const &obj){ void Polynomial::printPol(){ for(int i=0; i<degree; i++){ - cout << coeffs[i] << "x^" << i << "+ "; + cout << coeffs[i]; + if(i != 0){ + cout << " x^" << i; + } + + if (i != degree-1){ + cout << " + "; + } } cout << endl; } \ No newline at end of file diff --git a/test.cpp b/test.cpp index 56f1a4ea38f9f9ecd3e4ad9d48602cf299ab10b7..bea18461eba5c3cb754010535a3b7029afb4ff7e 100644 --- a/test.cpp +++ b/test.cpp @@ -13,11 +13,6 @@ int main(){ dcomplex a2 = 2.0 - 1.0 *J; dcomparr input = {a1, a2}; Polynomial pt = enc.encode(input); - - for(int i=0; i<4; i++){ - cout << pt.coeffs[i] << " "; - } - cout << endl; int q0 = 67; int pl[6] = {61, 67, 71, 73, 79, 59}; @@ -30,37 +25,39 @@ int main(){ SecKey sk = SecKey(); PubKey pk(sk.s, ql); EvalKey evk(sk.s, ql); + + Polynomial pt2 = pt * pt; + pt2.printPol(); CKKS ckks(4, pk, evk, sk); Ciphertext ct = ckks.encrypt(pt); Ciphertext ctadd = ckks.mult(ct, ct); - // for(int i=0; i<8; i++){ - // cout << ctadd.c0.coeffs[i] << " "; - // } - // cout << endl; + + Polynomial ptOut = ckks.decrypt(ctadd); + //problem dcomparr output = enc.decode(ptOut); + cout << "test" << endl; + + cout << endl; + + cout << "Experiment" << endl; + cout << "polynomial: "; + ptOut.printPol(); for(int i=0; i<4; i++){ - cout << output.arr[i]/64.0 << " "; + cout << output.arr[i] << " "; } cout << endl; - Polynomial pt2 = pt * pt; - pt2.printPol(); + cout << "Control" << endl; + cout << "polynomial: "; + (pt2.scaleCoeff(1.0/61.0)).printPol(); dcomparr out = enc.decode(pt2); for(int i=0; i<4; i++){ cout << out.arr[i]/64.0 << " "; } cout << endl; - // double test[] = {25600.0, 28800.0, 59300.0, 43200.0, 33700.0, 14400.0, 2025.0}; - // Polynomial mult(8, test); - // dcomparr out = enc.decode(mult); - // for(int i=0; i<4; i++){ - // cout << out.arr[i]/64.0 << " "; - // } - // cout << endl; - return 0; } \ No newline at end of file diff --git a/test.o b/test.o index af375def8b45afb52458808a0dac5ec9c9cb6c85..5b27ef5b001a4ae14d9d78a528189aa90779265f 100644 Binary files a/test.o and b/test.o differ