Java Code for Image Stenography || Take two images and merge them.

February 22, 2019
Steganography 

The art and science of hiding information by embedding messages within other, seemingly harmless messages. Steganography works by replacing bits of useless or unused data in regular computer files (such as graphics, sound, text, HTML, or even floppy disks ) with bits of different, invisible information.

Image steganography refers to hiding information i.e. text, images or audio files in another image or video files. The current project aims to use steganography for animage with another image using spatial domain technique. This hidden information can be retrieved only through proper decoding technique.

Input Images



Ouput Image


Extracted images from Output Image





Code
import java.awt.*;
import java.awt.image.BufferedImage;

import java.io.*;

import javax.imageio.ImageIO;
import javax.swing.JFrame;

class Pixel {
   BufferedImage image;
   BufferedImage image2;
   BufferedImage bi = new BufferedImage(500,500,BufferedImage.TYPE_INT_ARGB);
   
   File f = null; 
   int width;
   int height;
   
   public Pixel() {
      try {
         File input = new File("C:\\Users\\Muneeb\\Desktop\\ComputerSecurityProject\\ExperimentationSection\\12.jpg");
         File input2 = new File("C:\\Users\\Muneeb\\Desktop\\ComputerSecurityProject\\ExperimentationSection\\500.jpg");
         image = ImageIO.read(input);
         image2 = ImageIO.read(input2);
        
         
         width = image.getWidth();
         height = image.getHeight();
         //As the width and the height of the both images is same we can use the same For both of the things.
         
         int count = 0;
         
         for(int i=0; i<height; i++) {
         
            for(int j=0; j<width; j++) {
            
               count++;
               
               Color c = new Color(image.getRGB(j, i));
               Color c2 = new Color(image2.getRGB(j, i));
               int a = converttoBinary(c.getAlpha(),c2.getAlpha());  
                int r = converttoBinary(c.getRed(),c2.getRed());   
                int g = converttoBinary(c.getGreen(),c2.getGreen());  
                int b = converttoBinary(c.getBlue(),c2.getBlue());   
  
                int p = (a<<24) | (r<<16) | (g<<8) | b; //pixel 
  
                bi.setRGB(j, i, p); 
               
               
               System.out.println("S.No: " + count + " Red: " + c.getRed() +"  Green: " + c.getGreen() + " Blue: " + c.getBlue());
            }
         }
             f = new File("C:\\Users\\Muneeb\\Desktop\\ComputerSecurityProject\\ExperimentationSection\\Out.jpg"); 
            ImageIO.write(bi, "jpg", f); 
          
         
      } catch (Exception e) {}
       
   }
   public int converttoBinary(int c,int c2)
   {
       int v1 = c & 0xF0;
       int v2 = c2 & 0xF0; 
       //To combine we have to mask the values of the image using the AND mask.
       v2= v2>>4;
       
       
       
               
   return v1+v2;
   }
   
   public void getThetwoImages() throws IOException
   {
   BufferedImage get;
   BufferedImage bi1 = new BufferedImage(500,500,BufferedImage.TYPE_INT_ARGB);
   BufferedImage bi2 = new BufferedImage(500,500,BufferedImage.TYPE_INT_ARGB);
   File f1 = null; 
   File f2 = null; 
   
   File input = new File("C:\\Users\\Muneeb\\Desktop\\ComputerSecurityProject\\ExperimentationSection\\Out.jpg");
   
         get = ImageIO.read(input);
         
         
         width = get.getWidth();
         height = get.getHeight();
         //As the width and the height of the both images is same we can use the same For both of the things.
         
          
         for(int i=0; i<height; i++) {
         
            for(int j=0; j<width; j++) {
            
                
               Color c = new Color(get.getRGB(j, i));
               int p1=getimage1(c.getAlpha(),c.getRed(),c.getGreen(),c.getBlue());  
               int p2=getimage2(c.getAlpha(),c.getRed(),c.getGreen(),c.getBlue());  
                bi1.setRGB(j, i, p1); 
                bi2.setRGB(j, i, p2); 
                 System.out.println("S.No: " +   " Red: " + c.getRed() +"  Green: " + c.getGreen() + " Blue: " + c.getBlue());
             }
         }
            f1 = new File("C:\\Users\\Muneeb\\Desktop\\ComputerSecurityProject\\ExperimentationSection\\Image1.jpg"); 
            ImageIO.write(bi1, "jpg", f1); 
            f2 = new File("C:\\Users\\Muneeb\\Desktop\\ComputerSecurityProject\\ExperimentationSection\\Image2.jpg"); 
            ImageIO.write(bi2, "jpg", f2); 
        
       
   }
   public int getimage1(int a,int r,int g,int b)
   {
    a= a & 0xF0;
    r= r & 0xF0;
   g= g & 0xF0;
   b= b & 0xF0;
      int p = (a<<24) | (r<<16) | (g<<8) | b; //pixel 
  
   return p;
   }
   public int getimage2(int a,int r,int g,int b)
   {
   
   a= a & 0x0F;
   r= r & 0x0F;
   g= g & 0x0F;
   b= b & 0x0F;
   
   a=a<<4;
   r=r<<4;
   g=g<<4;
   b=b<<4;
   
      int p = (a<<24) | (r<<16) | (g<<8) | b; //pixel 
  
   return p;
   }
   static public void main(String args[]) throws Exception {
      Pixel obj = new Pixel();
      obj.getThetwoImages();
   }
   

}


No comments:

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();
Powered by Blogger.