function modulus(inputEmbed,inputText,outputEmbed)
fid = fopen(inputText,'r');
em = fread(fid);
len = length(em);
in = [];
in=[in dec2bin(len,20)];
for i=1:len %character convert to binary
in=[in dec2bin(em(i),7)];
end
a = imread(inputEmbed); %get cover image
[r,c]=size(a);
final=double(a);
next=0;
capacity=0; %bit space that can be embedded
for x=0:1:r-1 %traverse through all the pixel value on
for y=0:2:c-1 %the image by 2 consecutive pair non overlaping pixel
g=a(1+x,1+y:2+y);
g=double(g);
d=g(1,2)-g(1,1); %d=difference between 2 pixel
lb=[0 8 16 32 64 128]; %lowerbound
ub=[7 15 31 63 127 255]; %upperbound
dap=abs(d);
for i=1:1:6 %test the R boundary
if(dap >= lb(i)&& dap <= ub(i))
n=ub(i)-lb(i)+1; %quantization width of range
t=log2(n); %maximum bit can be embedded between 2 pixel
capacity=capacity+t;
nt=2^t;
FREM =mod((g(1,1)+g(1,2)),nt);
if(next>length(in))
m=0;
m1=0;
elseif(next+t>length(in))
if(1+next>=length(in))
k=zeros(1,t);
else
k=in(1+next:length(in));
end
diff =next+t-length(in);
k1=zeros(1,t);
if(diff>0)
for j=1:next+t-length(in)
k1(j)=k(j);
end
end
k=k1;
next=next+t;
%k=int2str(k);
k=bin2dec(char(k));
if(1+next>length(in))
m=0;
m1=0;
else
m=abs(FREM-k);
m1=2^t-abs(FREM-k);
end
else
k=in(1+next:t+next);
next=next+t;
k=bin2dec(char(k));
m=abs(FREM-k);
m1=2^t-abs(FREM-k);
end
end
end
if(FREM>k && m<=((2^t)/2) && g(1,1)>=g(1,2))
P0=[g(1,1)-ceil(m/2) g(1,2)-floor(m/2)];
elseif (FREM>k && m<=((2^t)/2) && g(1,1)<g(1,2))
P0=[g(1,1)-ceil(m/2) g(1,2)-floor(m/2)];
elseif (FREM>k && m>((2^t)/2) && g(1,1)>=g(1,2))
P0=[g(1,1)+ceil(m1/2) g(1,2)+floor(m1/2)];
elseif (FREM>k && m>((2^t)/2) && g(1,1)<g(1,2))
P0=[g(1,1)+ceil(m1/2) g(1,2)+floor(m1/2)];
elseif (FREM<=k && m<=((2^t)/2) && g(1,1)>=g(1,2))
P0=[g(1,1)+ceil(m/2) g(1,2)+floor(m/2)];
elseif (FREM<=k && m<=((2^t)/2) && g(1,1)<g(1,2))
P0=[g(1,1)+ceil(m/2) g(1,2)+floor(m/2)];
elseif (FREM<=k && m>((2^t)/2) && g(1,1)>=g(1,2))
P0=[g(1,1)-ceil(m1/2) g(1,2)-floor(m1/2)];
elseif (FREM<=k && m>((2^t)/2) && g(1,1)<g(1,2))
P0=[g(1,1)-ceil(m1/2) g(1,2)-floor(m1/2)];
end
if((g(1,1)==0 || g(1,2)==0)&&(P0(1)<0 || P0(2)<0))
P1=[P0(1)+((2^t)/2) P0(2)+((2^t)/2)];
final(1+x,1+y)=P1(1,1); %replace new pixel value into final
final(1+x,2+y)=P1(1,2);
elseif((g(1,1)==255 || g(1,2)==255)&&(P0(1)>255 || P0(2)>255))
P1=[P0(1)-((2^t)/2) P0(2)-((2^t)/2)];
final(1+x,1+y)=P1(1,1); %replace new pixel value into final
final(1+x,2+y)=P1(1,2);
elseif(dap>128)
if(P0(1)<0 && P0(2)>=0)
P1=[0 P0(1)+P0(2)];
final(1+x,1+y)=P1(1,1); %replace new pixel value into final
final(1+x,2+y)=P1(1,2);
elseif(P0(1)>=0 && P0(2)<0)
P1=[P0(1)+P0(2) 0];
final(1+x,1+y)=P1(1,1); %replace new pixel value into final
final(1+x,2+y)=P1(1,2);
elseif(P0(1)>255 && P0(2)>=0)
P1=[255 P0(2)+(P0(1)-255)];
final(1+x,1+y)=P1(1,1); %replace new pixel value into final
final(1+x,2+y)=P1(1,2);
elseif(P0(1)>=0 && P0(2)>255)
P1=[P0(1)+(P0(2)-255) 255];
final(1+x,1+y)=P1(1,1); %replace new pixel value into final
final(1+x,2+y)=P1(1,2);
end
else
final(1+x,1+y)=P0(1,1); %replace new pixel value into final
final(1+x,2+y)=P0(1,2);
end
end
end
if(next>length(in))
disp('Embedded Successfully...Writing to output image');
try
imwrite(uint8(final),outputEmbed); %construct new image using final pixel values
catch
disp('Unable to write into output image file');
disp('Execution Unsuccessful...Exiting');
fclose('all');
exit;
end
end