Why did I use Paillier encryption to get the wrong decryption value?

I'm using Paillier encryption to do image processing. I got the public key and private key according to the formula. I used powermod () to model large integers, but got the wrong decryption value. I don't know where the error occurred.
clear all;clc;
p = 13;
q = 11;
n = p * q;
nsquare = n^2;
lamuda = lcm(p - 1,q - 1);
Znsquare = [1:n^2 - 1];
Znsquare_gcd = gcd(Znsquare,nsquare);
Znsquare_index = find(Znsquare_gcd == 1);
Z_nsquare = Znsquare(Znsquare_index);
Zn = [0:n - 1];
Zn_gcd = gcd(Zn,n);
Zn_index = find(Zn_gcd == 1);
Z_n = Zn(Zn_index);
g = 8;
% b = gcd((powermod(g,lamuda,nsquare) - 1)/n,n);
r = 5;
m = 50;
c1 = powermod(g,m,nsquare);
c2 = powermod(r,n,nsquare);
c = powermod(c1*c2,1,nsquare);
L1 = (powermod(c,lambda,nsquare) - 1)/n;
L2 = (powermod(g,lambda,nsquare) - 1)/n;
m1 = powermod(L1/L2,1,n);
As an exercise, I choose to use q = 11 and P = 13, and take g = 8, g satisfies GCD (L (g ^ lambda mod n ^ 2), N) = 1.The decryption value M1 is sometimes correct and sometimes wrong. I don't know where the error occurred, and I find that sometimes the result of L1/L2 is not an integer.How should I modify my program? Thank you.

Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Release

R2017a

Asked:

on 27 Sep 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!