Skip to content

Commit

Permalink
removed noise during decoding for packed, coefpacked, and string enco…
Browse files Browse the repository at this point in the history
…ding methods (#881)

Co-authored-by: Yuriy Polyakov <ypolyakod@dualitytech.com>
  • Loading branch information
yspolyakov and Yuriy Polyakov authored Oct 22, 2024
1 parent 1d37679 commit 15b94b5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/pke/lib/encoding/coefpackedencoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,13 @@ bool CoefPackedEncoding::Decode() {
NativeInteger scfInv = scalingFactorInt.ModInverse(mod);
NativePoly temp = encodedNativeVector.Times(scfInv).Mod(mod);
fillVec(temp, mod, this->value);
// clears the values containing information about the noise
encodedNativeVector.SetValuesToZero();
}
else {
fillVec(this->encodedVector, mod, this->value);
// clears the values containing information about the noise
this->encodedVector.SetValuesToZero();
}

return true;
Expand Down
6 changes: 6 additions & 0 deletions src/pke/lib/encoding/packedencoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,24 @@ bool PackedEncoding::Decode() {
firstElement = firstElement.Times(scfInv);
firstElement = firstElement.Mod(ptm);
fillVec(firstElement, ptm, this->value);
// clears the values containing information about the noise
this->GetElement<NativePoly>().SetValuesToZero();
}
else {
NativePoly firstElement = this->GetElement<DCRTPoly>().GetElementAtIndex(0);
this->Unpack(&firstElement, ptm);
firstElement = firstElement.Times(scfInv);
firstElement = firstElement.Mod(ptm);
fillVec(firstElement, ptm, this->value);
// clears the values containing information about the noise
this->GetElement<DCRTPoly>().SetValuesToZero();
}
}
else {
this->Unpack(&this->GetElement<Poly>(), ptm);
fillVec(this->encodedVector, ptm, this->value);
// clears the values containing information about the noise
this->GetElement<Poly>().SetValuesToZero();
}

return true;
Expand Down
10 changes: 8 additions & 2 deletions src/pke/lib/encoding/stringencoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,16 @@ static void fillPlaintext(const P& poly, std::string& str, const PlaintextModulu
bool StringEncoding::Decode() {
auto mod = this->encodingParams->GetPlaintextModulus();

if (this->typeFlag == IsNativePoly)
if (this->typeFlag == IsNativePoly) {
fillPlaintext(this->encodedNativeVector, this->ptx, mod);
else
// clears the values containing information about the noise
this->encodedNativeVector.SetValuesToZero();
}
else {
fillPlaintext(this->encodedVector, this->ptx, mod);
// clears the values containing information about the noise
this->encodedVector.SetValuesToZero();
}

return true;
}
Expand Down

0 comments on commit 15b94b5

Please sign in to comment.