I am using PySEAL library, which is a fork of Microsoft SEAL homomorphic encryption library to implement Machine Learning algorithms on encrypted data. For this I would need to divide numbers. In the examples.py source code there are examples to perform addition, subtractions and multiplications, but not division. Is it possible to do divisions using PySEAL library? And if not, Is there any way around it like some trick to divide two numbers using other arithmetic operations in this library?
SEAL doesn't support division between ciphertexts. However, if you are looking to divide ciphertext by plaintext, you can use multiplication by inverse as shown below:
from seal import *
# context is a SEALContext object
# encoder is a FractionalEncoder object
# encryptor is an Encryptor object
# evaluator is an Evaluator object
# decryptor is a Decryptor object
# Encrypt a float
cipher = Ciphertext()
encryptor.encrypt(encoder.encode(7.0), cipher)
# Divide that float by 10
div_by_ten = encoder.encode(0.1)
evaluator.multiply_plain(cipher, div_by_ten)
# Decrypt result
plain = Plaintext()
decryptor.decrypt(cipher, plain)
result = encoder.decode(plain)
print(result)
>> 0.6999999999999996
See example_weighted_average
function in PySEAL Python examples.