1

我正在使用PySEAL库,它是Microsoft SEAL同态加密库的一个分支,用于在加密数据上实现机器学习算法。为此,我需要除数。在examples.py源代码中有执行加法、减法和乘法的示例,但不执行除法。是否可以使用 PySEAL 库进行除法?如果没有,有没有什么办法可以解决这个问题,比如使用这个库中的其他算术运算来划分两个数字?

4

1 回答 1

0

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 示例example_weighted_average中的函数。

于 2019-07-17T18:25:34.073 回答