FHE multiplication

When i am trying to multiply ciphertext with constant(plaintext). i am getting the below error.

auto ciphertext_shifted_left = cryptoContext->GetScheme()->MultByInteger(ciphertext,constant);

terminate called after throwing an instance of ‘lbcrypto::OpenFHEException’
what(): /home/pi2/openfhe-development/src/pke/include/schemebase/base-leveledshe.h:l.439:MultByInteger(): MultByInteger is not implemented for this scheme
Aborted.

How to fix this.

Which scheme are you using? This method is only supported by CKKS AFAIK.

I am using BFV scheme. Is there any other way to implement this in BFV scheme

Say you want to multiply an encrypted vector of length n by a constant integer a.
In BFV, you can create a plaintext object that encodes a vector of length n of values a, and then multiply your encrypted vector with this plaintext.

Here is a sample code.

std::vector<int64_t> v(n, a); // n-vec of a's
Plaintext pt = cryptoContext->MakePackedPlaintext(v); // encoding

auto out_ct = cryptoContext->EvalMult(in_ct, pt); // homomorphic multiplication by a constant plaintext (cheap operation in BFV)

To complement Caesar’s answer, you can also write your own method for ciphertext-constant multiplication in BFV, along the lines below:

Ciphertext<DCRTPoly> MultByInteger(const ConstCiphertext<DCRTPoly>& ciphertext, const int64_t constant) {
    auto result      = ciphertext->Clone();
    for (auto& c : result->GetElements())
        c *= constant;
    return result;
}

Hi this works fine.
Is there any option to do bitwise shift operation in ciphertext if our constant is multiple of 2. then we can directly do leftshift operation in ciphertext. will this operation be cheaper than multiplication

I am not aware of an equivalent homomorphic arithmetic shift in BFV similar to the conventional arithmetic shift you described. Anyway, the computational complexity of the solution above is relatively small especially compared with ciphertext-ciphertext multiplication.