Hi everyone, I do steganography on matlab based pixel value differencing method. The embedd/extract process run properly.
But in case I need to add password key as the protection, here is my sample code, need your advice for password key on steganography matlab. thanks
But in case I need to add password key as the protection, here is my sample code, need your advice for password key on steganography matlab. thanks
Rich (BB code):
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);
Attachments
-
40.5 KB Views: 10
Last edited: