clc;
clear;
close all;
warning off;
addpath(genpath(pwd));
subplot(2,3,1);
pic1=imread('lena.jpg.');
pic2=rgb2gray(pic1);
imshow(pic2)
title('original image');
subplot(2,3,4)
imhist(pic2)
title('Histogram of Original Image')
[m n]=size(pic2);
k1=pic2;
x=double(k1);
a=-1;
b=188;
p=6563;
K=20;
k=8;
d=EllipticCurvePointsModp3Mod4(a, b, p);
l=1;
aphn=primitiveroot(p);
stage1=multell([d(1),d(2)],aphn,a,b,p);
stage2=multell([d(1),d(2)],k,a,b,p);
for i=1:m
for j=1:n
m1=x(i,j);
%m=200;
c=EllipticCurvePlaintextRepModp(m1,a,b,p,K);
stage2=stage2;
stage3=addell([c(1),c(2)],multell([stage1(1),stage1(2)],k,a,b,p),a,b,p);
ciphertext(l)=stage2(1);
ciphertext(l+1)=stage2(2);
ciphertext(l+2)=stage3(1);
ciphertext(l+3)=stage3(2);
l=l+4;
end
end
l=1;
for i=1:m
for j=1:n
img(i,j)=ciphertext(l);
l=l+1;
end
end
fimg=img/20;
subplot(2,3,2)
imshow(uint8(fimg))
title('ECC Encrypted Image')
subplot(2,3,5)
imhist(uint8(fimg))
title('Histogram of Encrypted Image')
l1=1;
final=m*n*4;
fin=m*n;
for l=1:4:final
decrpt1=multell([ciphertext(l),ciphertext(l+1)],aphn,a,b,p);
decrpt2=addell([ciphertext(l+2),ciphertext(l+3)],[decrpt1(1),-decrpt1(2)],a,b,p);
pix=round(decrpt2(1)/K);
p1(l1)=pix;
l1=l1+1;
end
l2=1;
xnew=0;
for i=1:m
for j=1:n
xnew(i,j)=p1(l2);
l2=l2+1;
end
if l2==fin+1
break
end
end
subplot(2,3,3)
imshow(uint8(xnew))
title('Decrypted Image')
subplot(2,3,6)
imhist(uint8(xnew))
title('Histogram of Decrypted Image')
sum=0;
for i=1:m
for j=1:n
error=(x(i,j)-xnew(i,j))^2;
sum=sum+error;
end
end
sum1=sum/(m*n)
psnr=10*log(255^2/sum1)