我们可以使用 Microsoft SEAL / PySEAL 库对加密数据进行除法运算吗

Can we perform division operation on encrypted data using Microsoft SEAL / PySEAL library

我正在使用 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 源代码,其中有执行加法、减法和乘法的示例,但没有执行除法的示例。是否可以使用 PySEAL 库进行除法?如果没有,是否有任何解决方法,例如使用此库中的其他算术运算将两个数字相除的技巧?

SEAL 不支持密文之间的划分。但是,如果您希望将密文除以明文,则可以使用逆乘法,如下所示:

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

参见 PySEAL Python examples 中的 example_weighted_average 函数。