(self, scalar)
return PaillierEncryptedNumber(self.public_key, ciphertext, exponent)
return Multiply by an scalar(such as int, float)
return Multiply by an scalar(such as int, float)
return Multiply by an scalar ( such as int float )
def __mul__(self, scalar):
        """return Multiply by an scalar(such as int, float)
        """
        if isinstance(scalar, FixedPointNumber):
            scalar = scalar.decode()
        encode = FixedPointNumber.encode(scalar, self.public_key.n, self.public_key.max_int)
        plaintext = encode.encoding

        if plaintext < 0 or plaintext >= self.public_key.n:
            raise ValueError("Scalar out of bounds: %i" % plaintext)

        if plaintext >= self.public_key.n - self.public_key.max_int:
            # Very large plaintext, play a sneaky trick using inverses
            neg_c = gmpy_math.invert(self.ciphertext(False), self.public_key.nsquare)
            neg_scalar = self.public_key.n - plaintext
            ciphertext = gmpy_math.powmod(neg_c, neg_scalar, self.public_key.nsquare)
        else:
            ciphertext = gmpy_math.powmod(self.ciphertext(False), plaintext, self.public_key.nsquare)

        exponent = self.exponent + encode.exponent

        return PaillierEncryptedNumber(self.public_key, ciphertext, exponent)
def __mul__ ( self , scalar ) : if isinstance ( scalar , FixedPointNumber ) : scalar = scalar . decode ( ) encode = FixedPointNumber . encode ( scalar , self . public_key . n , self . public_key . max_int ) plaintext = encode . encoding if plaintext < 0 or plaintext >= self . public_key . n : raise ValueError ( "Scalar out of bounds: %i" % plaintext ) if plaintext >= self . public_key . n - self . public_key . max_int : # Very large plaintext, play a sneaky trick using inverses neg_c = gmpy_math . invert ( self . ciphertext ( False ) , self . public_key . nsquare ) neg_scalar = self . public_key . n - plaintext ciphertext = gmpy_math . powmod ( neg_c , neg_scalar , self . public_key . nsquare ) else : ciphertext = gmpy_math . powmod ( self . ciphertext ( False ) , plaintext , self . public_key . nsquare ) exponent = self . exponent + encode . exponent return PaillierEncryptedNumber ( self . public_key , ciphertext , exponent )