Skip to content

Instantly share code, notes, and snippets.

@pathaine

pathaine/p6.cpp Secret

Last active Oct 14, 2019
Embed
What would you like to do?
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