RSA同态加密验证

from Crypto.Util.number import * import random

生成RSA密钥对

p = getPrime(512) q = getPrime(512) n = p * q phi = (p - 1) * (q - 1) e = 65537 d = inverse(e, phi)

加密函数

def encrypt(m): return pow(m, e, n)

解密函数

def decrypt(c): return pow(c, d, n)

生成随机数a和b

a = random.randint(1, n-1) b = random.randint(1, n-1)

计算c = a * b

c = a * b

加密a、b和c

ea = encrypt(a) eb = encrypt(b) ec = encrypt(c)

验证乘法同态

if decrypt(ec) == decrypt(ea) * decrypt(eb): print('乘法同态验证成功!') else: print('乘法同态验证失败!')

RSA同态加密验证:Python代码实现与验证

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

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