Skip to content

Instantly share code, notes, and snippets.

@pathaine

pathaine/p6.cpp Secret

Last active October 14, 2019 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pathaine/2c24101799686286a91ab8a6fcfcc71b to your computer and use it in GitHub Desktop.
Save pathaine/2c24101799686286a91ab8a6fcfcc71b to your computer and use it in GitHub Desktop.
vector<uint64_t> v1 = { 0, 4, 6, 2, 5 };
vector<uint64_t> v2 = { 1, 6, 3, 5, 2 };
// Convert the vectors into plaintext representation
Plaintext PT1 = cc->MakePackedPlaintext(v1);
Plaintext PT2 = cc->MakePackedPlaintext(v2);
Ciphertext<DCRTPoly> CT1;
Ciphertext<DCRTPoly> CT2;
// Convert the plaintext representations into a ciphertexts by encrypted them using the public key
CT1 = cc->Encrypt(kp.publicKey, PT1);
CT2 = cc->Encrypt(kp.publicKey, PT2);
// Evaluate the component-wise multiplication of the two ciphertexts
// product should be equal to { 0, 24, 18, 10, 10 }
//Thank you to Christian Grigis for pointing out the typo in the original file which incorrectly stated that the result should be { 1, 24, 18, 10, 10 }
Ciphertext<DCRTPoly> product = cc->EvalMult(CT1, CT2);
// Evaluate the component-wise sum of the two ciphertexts
// sum should be equal to { 1, 10, 9, 7, 7 }
Ciphertext<DCRTPoly> sum = cc->EvalAdd(CT1, CT2);
// Evaluate the inner product of the ciphertexts -- note that batchSize should be a power of 2
Ciphertext<DCRTPoly> innerProduct = cc->EvalInnerProduct(CT1, CT2, batchSize);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment