我需要你的帮助,如何在嵌入和插入时插入密码密钥在matlab中提取过程(隐写术)?
它可以制作差异功能并在其他.m文件上调用吗?
如果有任何建议点/推荐网站,请告知我们。
这是我在隐写术中嵌入/提取过程的代码函数。
function[capa,opfile,full,file]= proses_embedd(P1,Q)
P=imread(P1);
[Pm,Pn]=size(P);
I=P;
fid=fopen(Q,'rt');
[X1,co]=fread(fid,'*char');
r=1;
for q=1:co
L(q)=uint8(X1(q));
end;
for q=1:co
W(r:r+7)=dec2bin(L(q),8);
r=r+8;
end;
file=r-1;
x=0;
for i=1:Pm
if x>=(r-1)
break;
end;
for j=1:2:Pn-1
if x>=(r-1)
break;
end;
p11=double(I(i,j));
p21=double(I(i,j+1));
d0=(p11-p21);
if abs(d0)<8
w0=8;
l0=0;
elseif abs(d0)<16&&abs(d0)>7
w0=8;
l0=8;
elseif abs(d0)>15&&abs(d0)<32
w0=16;
l0=16;
elseif abs(d0)>31&&abs(d0)<64
w0=32;
l0=32;
elseif abs(d0)>63&&abs(d0)<128
w0=64;
l0=64;
elseif abs(d0)>127&&abs(d0)<256
w0=128;
l0=128;
else
w0=0;
end;
if(w0>0)
t0=floor(log2(w0));
else
t0=0;
end;
if(t0>0)
if(x<(r-1) && x+t0>(r-1))
b0=bin2dec(W(x+1:(r-1)));
d00=l0+b0;
m0=abs(d00-abs(d0));
if((p11>=p21)&&(d00>abs(d0)))
p00=p11+ceil(m0/2);
p01=p21-floor(m0/2);
end;
if((p11<p21)&&(d00>abs(d0)))
p00=p11-floor(m0/2);
p01=p21+ceil(m0/2);
end;
if((p11>=p21)&&(d00<=abs(d0)))
p00=p11-ceil(m0/2);
p01=p21+floor(m0/2);
end;
if((p11<p21)&&(d00<=abs(d0)))
p00=p11+ceil(m0/2);
p01=p21-floor(m0/2);
end;
block=1;
x=r-1;
end;
if(x+t0)<=(r-1)
b0=bin2dec(W(x+1:x+t0));
d00=l0+b0;
m0=abs(d00-abs(d0));
if((p11>=p21)&&(d00>abs(d0)))
p00=p11+ceil(m0/2);
p01=p21-floor(m0/2);
end;
if((p11<p21)&&(d00>abs(d0)))
p00=p11-floor(m0/2);
p01=p21+ceil(m0/2);
end;
if((p11>=p21)&&(d00<=abs(d0)))
p00=p11-ceil(m0/2);
p01=p21+floor(m0/2);
end;
if((p11<p21)&&(d00<=abs(d0)))
p00=p11+ceil(m0/2);
p01=p21-floor(m0/2);
end;
block=1;
x=x+t0;
end;
end;
if block==1
p0=p00;
p1=p01;
I(i,j)=p0;
I(i,j+1)=p1;
end;
end;
end;
if((i==Pm)&&(j>=Pn-20))
full=0;
else
full=1;
end;
capa=x;
capacity=dec2bin(capa,20);
s=1;
i=Pm;
j=Pn-20;
while(s<21)
temp1=dec2bin(I(i,j),8);
temp1(8)=capacity(s);
I(i,j)=bin2dec(temp1);
s=s+1;
j=j+1;
end;
answer = inputdlg('output image name');
answer1=strcat(answer,'.bmp');
imwrite(I,char(answer1),'bmp');
opfile=char(answer1);
以下是提取过程代码:
function [namapesan,lokasi,fid]=proses_ekstrak(P1)
I=imread(P1);
[Pm,Pn]=size(I);
s=1;
i=Pm;
j=Pn-20;
while(s<21)
temp1=dec2bin(I(i,j),8);
bits(s)=temp1(8);
s=s+1;
j=j+1;
end;
quan=bin2dec(bits);
r=quan;
ans=quan/8;
x=0;
for i=1:Pm
if x>=(r)
break;
end;
for j=1:2:Pn-1
if x>=(r)
break;
end;
p11=double(I(i,j));
p21=double(I(i,j+1));
d0=(p11-p21);
if abs(d0)<8
w0=8;
l0=0;
elseif abs(d0)<16&&abs(d0)>7
w0=8;
l0=8;
elseif abs(d0)>15&&abs(d0)<32
w0=16;
l0=16;
elseif abs(d0)>31&&abs(d0)<64
w0=32;
l0=32;
elseif abs(d0)>63&&abs(d0)<128
w0=64;
l0=64;
elseif abs(d0)>127&&abs(d0)<256
w0=128;
l0=128;
else
w0=0;
end;
if(w0>0)
t0=floor(log2(w0));
else
t0=0;
end;
if(x<r && x+t0>r)
dec1=abs(d0)-l0;
t0=r-x;
w= dec2bin(dec1,t0);
binary(x+1:x+t0)=w(1:t0);
x=x+t0;
end;
if(x+t0<=r)
dec1=abs(d0)-l0;
binary(x+1:x+t0)=dec2bin(dec1,t0);
x=x+t0;
end;
end;
end;
x=0;
o=1;
while(o<=(quan/8))
W(o)= bin2dec(binary(x+1:x+8));
x=x+8;
o=o+1;
end;
if(quan<=5000)
disp(char(W));
end;
[namapesan, lokasi]=uiputfile('*.txt','Save Message');
fid = fopen(char(namapesan),'w');
fprintf(fid,'%s',char(W));
fclose(fid);