简单的同态加密包含加法同态和乘法同态,加法同态算法最经典的是Paillier算法,乘法同态算法最经典的是RSA算法。以下是RSA算法同态验证说明:

设: a * b = c (基础等式)

其中:加密函数e(),解密函数d() [encrypt:加密;decrypt:解密]

乘法同态特为:e(a) * e(b) = e(c)

c = d(e(c)) = d(e(a) * e(b))

验证c 是否等于a * b,生成验证代码内容:

plaintext = 10
plaintext2 = 5

# 加密
encrypted_plaintext = encrypt(plaintext)
encrypted_plaintext2 = encrypt(plaintext2)

# 乘法同态
encrypted_result = encrypted_plaintext * encrypted_plaintext2

# 解密
decrypted_result = decrypt(encrypted_result)

# 验证结果是否正确
if decrypted_result == plaintext * plaintext2:
    print('同态验证通过')
else:
    print('同态验证失败')
RSA同态加密算法详解及验证代码

原文地址: https://www.cveoy.top/t/topic/owmu 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录