clcclearclose all
randoma=input('请输入用户指令:','s')%
P=randoma
%P=str2num(P)
if (P=='*****')
tu=uigetfile()
I=imread(tu)
imshow(tu)hold on
%imshow('tu')
[M,N,P]=size(I)
rand('state',0)
% randoma=input('请输入用户指令:')%
% P=randoma
% if (P==3.14)
T=96
R=rand(M,N)*pi*2
xlswrite('R.xls',R)
%kk=xlsread('jjm.xls')%32 43 55 63
a1=input('请输入a1:')
a2=input('请输入a2:')
a3=input('请输入a3:')
a4=input('请输入a4:')
kk=[a1,a2,a3,a4]
xlswrite('kk.xls',kk)
%%
I=double(I)
Ie=encrypt(I,R,kk)
figure
imshow(Ie,[])
%%
%%加密图像 其中调用了encrypt函数
%function Ie=encrypt(I,R,kk)
%Ir=I(:,:,1)Ig=I(:,:,2)Ib=I(:,:,3)
% [Xr,Xg,Xb]=Tmatrix(Ir,Ig,Ib,R)
% I1r=blkart2a(Xr,kk)I1g=blkart2a(Xg,kk)I1b=blkart2a(Xb,kk)
% I0r=dct2(I1r)I0g=dct2(I1g)I0b=dct2(I1b)
% [X1r,X1g,X1b]=Tmatrix(I0r,I0g,I0b,R)
% I2r=blkart2a(X1r,kk)I2g=blkart2a(X1g,kk)I2b=blkart2a(X1b,kk)
% I3r=idct2(I2r)I3g=idct2(I2g)I3b=idct2(I2b)
% Ie(:,:,1)=I3rIe(:,:,2)=I3gIe(:,:,3)=I3b
% [Xr,Xg,Xb]=Tmatrix(Ir,Ig,Ib,R)
% Xr=Ir.*cos(R)+Ig.*sin(R).^2-Ib.*sin(R).*cos(R)
% Xg=-Ir.*sin(R)+Ig.*sin(R).*cos(R)-Ib.*cos(R).^2
% Xb=Ig.*cos(R)+Ib.*sin(R)
a1=input('请输入a1:')
a2=input('请输入a2:')
a3=input('请输入a3:')
a4=input('请输入a4:')
kk=[a1,a2,a3,a4]
R=uigetfile()
R=xlsread('R.xls')
%%
Ii=decrypt(Ie,R,kk)
Ii=Ii-min(Ii(:))Ii=Ii/max(Ii(:))
h = waitbar(0,'Please wait...')
steps = 600
for step = 1:steps
%figureimshow(Ii,[])
waitbar(step / steps)
end
close(h)
figureimshow(Ii,[])
h = waitbar(1,'完成解密','color','')
steps = 1
for step = 1:steps
h = waitbar(1,'finish!','color','')
end
close(h)
warning off
end
%%
%%解密图像,调用decrypt函数
% function J=decrypt(Ie,R,kk)
% T=96% period of Arnold transform
% J2r=Ie(:,:,1)J2g=Ie(:,:,2)J2b=Ie(:,:,3)
% J2r=dct2(J2r)J2g=dct2(J2g)J2b=dct2(J2b)
% Y1r=blkart2a(J2r,T-kk)Y1g=blkart2a(J2g,T-kk)Y1b=blkart2a(J2b,T-kk)
% [J0r,J0g,J0b]=iTmatrix(Y1r,Y1g,Y1b,R)
% J1r=idct2(J0r)J1g=idct2(J0g)J1b=idct2(J0b)
% Yr=blkart2a(J1r,T-kk)Yg=blkart2a(J1g,T-kk)Yb=blkart2a(J1b,T-kk)
% [Jr,Jg,Jb]=iTmatrix(Yr,Yg,Yb,R)
% J(:,:,1)=JrJ(:,:,2)=JgJ(:,:,3)=Jb
基于Arnold变换的图像7a686964616fe4b893e5b19e31333264636332加密: 记住把注释掉的程序单独写个M文件,放在同一路径下clcclearclose all
randoma=input('请输入用户指令:','s')%
P=randoma
%P=str2num(P)
if (P=='*****')
tu=uigetfile()
I=imread(tu)
imshow(tu)hold on
%imshow('tu')
[M,N,P]=size(I)
rand('state',0)
% randoma=input('请输入用户指令:')%
% P=randoma
% if (P==3.14)
T=96
R=rand(M,N)*pi*2
xlswrite('R.xls',R)
%kk=xlsread('jjm.xls')%32 43 55 63
a1=input('请输入a1:')
a2=input('请输入a2:')
a3=input('请输入a3:')
a4=input('请输入a4:')
kk=[a1,a2,a3,a4]
xlswrite('kk.xls',kk)
%%
I=double(I)
Ie=encrypt(I,R,kk)
figure
imshow(Ie,[])
%%
%%加密图像 其中调用了encrypt函数
%function Ie=encrypt(I,R,kk)
%Ir=I(:,:,1)Ig=I(:,:,2)Ib=I(:,:,3)
% [Xr,Xg,Xb]=Tmatrix(Ir,Ig,Ib,R)
% I1r=blkart2a(Xr,kk)I1g=blkart2a(Xg,kk)I1b=blkart2a(Xb,kk)
% I0r=dct2(I1r)I0g=dct2(I1g)I0b=dct2(I1b)
% [X1r,X1g,X1b]=Tmatrix(I0r,I0g,I0b,R)
% I2r=blkart2a(X1r,kk)I2g=blkart2a(X1g,kk)I2b=blkart2a(X1b,kk)
% I3r=idct2(I2r)I3g=idct2(I2g)I3b=idct2(I2b)
% Ie(:,:,1)=I3rIe(:,:,2)=I3gIe(:,:,3)=I3b
% [Xr,Xg,Xb]=Tmatrix(Ir,Ig,Ib,R)
% Xr=Ir.*cos(R)+Ig.*sin(R).^2-Ib.*sin(R).*cos(R)
% Xg=-Ir.*sin(R)+Ig.*sin(R).*cos(R)-Ib.*cos(R).^2
% Xb=Ig.*cos(R)+Ib.*sin(R)
a1=input('请输入a1:')
a2=input('请输入a2:')
a3=input('请输入a3:')
a4=input('请输入a4:')
kk=[a1,a2,a3,a4]
R=uigetfile()
R=xlsread('R.xls')
%%
Ii=decrypt(Ie,R,kk)
Ii=Ii-min(Ii(:))Ii=Ii/max(Ii(:))
h = waitbar(0,'Please wait...')
steps = 600
for step = 1:steps
%figureimshow(Ii,[])
waitbar(step / steps)
end
close(h)
figureimshow(Ii,[])
h = waitbar(1,'完成解密','color','')
steps = 1
for step = 1:steps
h = waitbar(1,'finish!','color','')
end
close(h)
warning off
end
%%
%%解密图像,调用decrypt函数
% function J=decrypt(Ie,R,kk)
% T=96% period of Arnold transform
% J2r=Ie(:,:,1)J2g=Ie(:,:,2)J2b=Ie(:,:,3)
% J2r=dct2(J2r)J2g=dct2(J2g)J2b=dct2(J2b)
% Y1r=blkart2a(J2r,T-kk)Y1g=blkart2a(J2g,T-kk)Y1b=blkart2a(J2b,T-kk)
% [J0r,J0g,J0b]=iTmatrix(Y1r,Y1g,Y1b,R)
% J1r=idct2(J0r)J1g=idct2(J0g)J1b=idct2(J0b)
% Yr=blkart2a(J1r,T-kk)Yg=blkart2a(J1g,T-kk)Yb=blkart2a(J1b,T-kk)
% [Jr,Jg,Jb]=iTmatrix(Yr,Yg,Yb,R)
% J(:,:,1)=JrJ(:,:,2)=JgJ(:,:,3)=Jb
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)