|
楼主 |
发表于 2009-2-11 15:46
|
显示全部楼层
图像解密!!!!!!!!!!!!!!!!!谢谢了
就是用matlab加密成图片,然后在载入生成的加密图片进行解密,无法得到原来的明文
我将259*256的lona.bmp进行加密,对其进行4*4分块,通过混沌序列的0,1来判断像素位置置换与否
加密程序:
[t,x]=ode45(@odel,[0 10],[0.145;0.123;0.011]);
C=x(1:701,3);
C=C/10; C=mod(C,1);
for p=1:700;
F3(1)=C(1);
F3(p+1)=F3(p)+C(p+1);
end
Q3=F3(701)/700;
for c=1:700;
if C(c)>Q3
C1(c,:)=0;
else C1(c,:)=1;
end
C1=uint8(C1);
end
I=imread('LONA.bmp');
I=rgb2gray(I);
imshow(I);
Z=mat2cell(I,4*ones(1,64),4*ones(1,64));
for r=1:64;s=1:64;
if C1(r,:)==1
V=Z(r,s);
Z(r,s)=Z(s,r);
Z(s,r)=V;
end
end
for r=1:64;s=1:64;
if C1(r+51,:)==1
V=Z(r,s);
Z(r,s)=Z(s,r);
Z(s,r)=V;
end
end
for r=1:64;s=1:64;
if C1(r+81,:)==1
V=Z(r,s);
Z(r,s)=Z(s,r);
Z(s,r)=V;
end
end
for r=1:64;s=1:64;
if C1(r+101,:)==1
V=Z(r,s);
Z(r,s)=Z(s,r);
Z(s,r)=V;
end
end
for r=1:64;s=1:64;
if C1(r+256,:)==1
V=Z(r,s);
Z(r,s)=Z(s,r);
Z(s,r)=V;
end
end
I=cell2mat(Z);
figure,imshow(I);
将加密后的图片保存为un.pgm
解密程序:
[t,x]=ode45(@odel,[0 10],[0.145;0.123;0.011]);
C=x(1:701,3);
C=C/10; C=mod(C,1);
for p=1:700;
F3(1)=C(1);
F3(p+1)=F3(p)+C(p+1);
end
Q3=F3(701)/700;
for c=1:700;
if C(c)>Q3
C1(c,:)=0;
else C1(c,:)=1;
end
C1=uint8(C1);
end
I=imread('un.pgm');
imshow(I);
Z=mat2cell(I,4*ones(1,64),4*ones(1,64));
for r=1:64;s=1:64;
if C1(r,:)==1
V=Z(r,s);
Z(r,s)=Z(s,r);
Z(s,r)=V;
end
end
for r=1:64;s=1:64;
if C1(r+51,:)==1
V=Z(r,s);
Z(r,s)=Z(s,r);
Z(s,r)=V;
end
end
for r=1:64;s=1:64;
if C1(r+81,:)==1
V=Z(r,s);
Z(r,s)=Z(s,r);
Z(s,r)=V;
end
end
for r=1:64;s=1:64;
if C1(r+101,:)==1
V=Z(r,s);
Z(r,s)=Z(s,r);
Z(s,r)=V;
end
end
for r=1:64;s=1:64;
if C1(r+256,:)==1
V=Z(r,s);
Z(r,s)=Z(s,r);
Z(s,r)=V;
end
end
I=cell2mat(Z);
figure,imshow(I); |
|