Wednesday 30 May 2018

Lsb matching octave code for steganography

msg=[1,2,3,4];
msg_length=length(msg);
msg_product=msg_length*8;
msg_bitloc=1;
msg_count=1;

carrier_image=imread('D:/anshita/octave/images used/woman.jpg');
im_value=carrier_image;

if(msg_product<=255)

  for index=1:1:(msg_product)
  if (msg_count<=msg_length)
  display('loop starts')
    if ((im_value(1,index,1)==0)||(im_value(1,index,1)==255))
      index++;
      index_value=index
    else
      index_value=index
      #finding lsb of image
      a_image=im_value(1,index,1);
      b_imageString=dec2bin(a_image);
      c_image=str2double(b_imageString);
      binary_image=c_image;
      lsb_image=bitget(binary_image,1);
   
      #converting msg to binary
      if(msg_bitloc>8)
      msg_count = msg_count+1
      msg_bitloc=1
      else
      msg_bitloc=msg_bitloc
      msg_count=msg_count
      end
      a_msg=msg(1,msg_count)
      b_msgString=dec2bin(a_msg);
      c_msg=str2double(b_msgString);
      binary_msg=c_msg;
      msg_bit=bitget(binary_msg,msg_bitloc)
      msg_bitloc++;
   
      #matching message bit to lsb of image
      if (lsb_image==msg_bit)
        lsb_image=msg_bit;
          if (lsb_image == 0)
          new_binaryimage=bitset(binary_image,1,0)
          else
          new_binaryimage=bitset(binary_image,1,1)
          end
        #assigning values to image matrix
        new_decimalimage=bin2dec(num2str(new_binaryimage))
        im_value(1,index,1)=new_decimalimage;
      else
          # decreasing and increasing pixel value
          generate_value=round(rand(1))
       
          # increasing pixel value by 1
          if(generate_value==1)
            str_binaryImage=num2str(c_image);
            dec_image=bin2dec(str_binaryImage)
            increased_value=dec_image+1
            im_value(1,index,1)=increased_value;
            new_decimalimage=increased_value
          end
       
          # decreasing pixel value by 1
          if(generate_value==0)
            str_binaryImage=num2str(c_image);
            dec_image=bin2dec(str_binaryImage)
            decreased_value=dec_image-1
            im_value(1,index,1)=decreased_value;
            new_decimalimage=decreased_value
          end
          
      end 
     
   
      
    end
  end
  end
end
display('loop end')
image(im_value);

Lsb matching Steganography:

In lsb matching steganography RGB image or decimal form(0-255) of image is first converted to binary and last bit of it is matched with message bit. This matching is done until all message bits are matched. If the message bit = last bit of image then:
last bit of image pixel= message bit
otherwise ; a random number is generated either '0' or '1'.
if Random value '0' generates then pixel value is decreased by one
if Random value '1' generates then pixel value is increased by one


No comments:

Post a Comment

Program to solve 4 variable equation(octave code)

function [x,y,z,alpha]=eq4variable( aaaa1,bbbb1,dddd1,eeee1,cccc1,aaaa2,bbbb2,dddd2,eeee2,cccc2,aaaa3,bbbb3,dddd3,eeee3,cccc3,aaaa4,bbbb4,d...