bristolcrypto / HEAT

BSD 2-Clause "Simplified" License
26 stars 7 forks source link

How to use flt2plyEncode and ply2fltDecode #8

Open radwasherif opened 6 years ago

radwasherif commented 6 years ago

Can you produce a tutorial on how to use these functions with HElib. Whenever I try to use them I get this error: test_x: PAlgebra.cpp:464: void PAlgebraModDerived::embedInSlots(PAlgebraModDerived::RX&, const std::vector&, const MappingData&) const [with type = PA_GF2; PAlgebraModDerived::RX = NTL::GF2X; typename type::RX = NTL::GF2X]: Assertion `deg(alphas[i]) < mappingData.degG' failed. Aborted (core dumped)

This is a snippet from my code:

   //Scheme initialized up here

   vector <ZZX> ptxt1;
   vector <ZZX> ptxt2; 

   for(int i = 0; i < nslots; i++) {
    double x = 5.3442234;
    double dum; 
    long dumL; 
    ZZX z; 
    flt2plyEncode(z, dumL, dum, x, 52, -1, 3, m, 0); 
    ptxt1.push_back(z);

    ZZX z2; 
    double y = 4.5554; 
    flt2plyEncode(z2, dumL, dum, y, 52, -1, 3, m, 0);
    ptxt2.push_back(z2);  

   }
   Ctxt ctxt1(publicKey); 
   ea.encrypt(ctxt1, publicKey, ptxt1); 

   Ctxt ctxt2(publicKey); 
   ea.encrypt(ctxt2, publicKey, ptxt2);

   ctxt1 += (ctxt2); 

   vector <ZZX> res; 
   ea.decrypt(ctxt1, secretKey, res);
   double xr, dumL ;  
   ply2fltDecode(xr, res[0], dumL, 3, m, m, 0); 
   cout << xr << endl; 
svivekv commented 6 years ago

Sorry for a late reply! We are preparing a small document essentially by compiling the comments in the API code. Regarding the bug, note that the fixed point encode and decode routines are not yet meant to work with slots. Currently, encryptFixedpt() and decryptFixedpt() routines provide interface only to the primitive publicKey.Encrypt() and publicKey.Decrypt() routines, respectively.