matlab paillier加密_基于Paillier的同态加密域可逆信息隐藏

Abstract:

Based on the homomorphism and probability characteristics of Paillier cryptosystem, a reversible data hiding in homomorphic encrypted domain based on Paillier is proposed. First, the original image is divided into blocks. The pixel groups randomly selected by the image owner have one reference pixel and eight target pixels. Least significant bits (LSBs) of reference pixel and all bits of target pixel are self-embedded into other parts of the image by a method of RDH. In order to avoid overflow when embedding data, LSBs of the reference pixel are reset to zero before encryption. The encrypted reference pixel replaces the target pixels surrounding it, thereby constructing mirror central ciphertext. In a set of mirroring central ciphertext, the data hider embeds data in the LSBs of the target pixels by homomorphic addition, while the reference pixel remains unchanged. The receiver can directly extract the extra information by modular m

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Paillier加密是一种公钥加密方案,可以用于保护敏感数据的隐私。下面是Matlab实现Paillier加密解密的示例代码: ``` % Paillier加密解密 clc; clear; % 生成公私钥对 p = 61; % 随机选取两个质数p和q q = 53; n = p * q; % 计算n lambda = lcm(p-1, q-1); % 计算lambda g = n + 1; % 随机选取g mu = mod(invmod(lambda, n), n); % 计算mu public_key = [n, g]; % 公钥 private_key = mu; % 私钥 % 加密 m = 123; % 需要加密的明文 r = randi([1, n-1]); % 随机选择r c = mod(expmod(g, m, n^2) * expmod(r, n, n^2), n^2); % 计算密文 % 解密 L = expmod(c, lambda, n^2); % 计算L L = (L - 1) / n; % 计算L' m_dec = mod(L * mu, n); % 计算明文 % 输出结果 fprintf('公钥: (%d, %d)\n', public_key(1), public_key(2)); fprintf('私钥: %d\n', private_key); fprintf('明文: %d\n', m); fprintf('密文: %d\n', c); fprintf('解密明文: %d\n', m_dec); % 定义invmod函数 function y = invmod(x, m) a = x; b = m; u = 1; v = 0; while b ~= 0 q = floor(a / b); t = a - q * b; a = b; b = t; s = u - q * v; u = v; v = s; end if u < 0 u = u + m; end y = u; end % 定义expmod函数 function y = expmod(x, e, m) if e == 0 y = 1; elseif mod(e, 2) == 0 y = expmod(mod(x^2, m), e/2, m); else y = mod(x * expmod(x, e-1, m), m); end end ``` 在上面的代码中,我们使用了Matlab内置的mod函数和expmod函数来实现Paillier加密解密过程。需要注意的是,在生成公私钥对时,我们需要随机选择两个质数p和q,并且计算出n和lambda。在加密时,我们需要随机选择一个r,并计算出密文c。在解密时,我们需要计算出L和L',并使用私钥mu来计算明文m。最终,我们可以输出公私钥对、明文、密文和解密明文等结果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值