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


Saturday 12 May 2018

LSB replacement STEGANOGRAPHY code

msg=[2,0,1,3];
msg_length=length(msg);
msg_product=msg_length*8;
loc_msg=1;
count_msgbit=1;

carrier_image=imread('G:/anshita software/octave/images used/woman.jpg');
im_value=carrier_image;
#im_value=15*ones(35);

if (msg_product<=255)
  for index=1:1:msg_product
 
    # binary conversion of image
    a_image=im_value(1,index,1);
    b_imageVector=dec2bin(a_image);
    c_image=str2double(b_imageVector);
    binary_image=c_image;
    lsb_image=bitget(c_image,1);
 
    # binary conversion of message
    if (count_msgbit>8)
      count_msgbit=1;
      loc_msg++;
    end
    a_msg=msg(1,loc_msg);
    b_msgVector=dec2bin(a_msg);
    c_msg=str2double(b_msgVector);
    msg_bit=bitget(c_msg,count_msgbit);
    c=count_msgbit++;
 
    #assigning msg values to image lsb
    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_type
     dec_imageValue=bin2dec(num2str(new_binaryimage));
     dummy=dec_imageValue
     index
     im_value(1,index,1)=dummy;
   
   
   
   
 
    end
end

image(im_value)

Steganography is the way to secretly embed message into image.
I have written an OCTAVE code to embed a message to image. This type of steganography is called LSB replacement steganography.
last bit of each pixel is replaced by message bit.
Images are in the form of RGB. But i am taking a 2 d matrix just as an example.


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...