Programming Assignment: Hiding Text in Images

    Instructions:
  1. You are about to write Java programs to hide text in images. Use the three classes (Pixel, Image, and ImageProc) in the previous image process programming assignment and add two methods in class Image: hideMessage and RevealMessage. For this assignment, you don't have to keep other processing methods such as grayscale, invert, etc. Sample programs and test data are in the OneDrive Share Drive: (csc2340\programmingAssignments\hideTextMessageInImages)

  2. There are many ways to hide a text message in an image. In this assignment, your program will hide the characters of a text message into the color pixels of an image. As we know, each character (in the ASCII character set) is encoded by an integer coding value with a range of 0 to 255. For example, character 'A' has a coding value of 65, and 'B' has 66, so on. In a color image, each pixel is represented by three color components, red, green and blue with numerical values from 0 to 255. We will break a character coding value into three single digits, and then replace the last digits of the three color component values of a pixel with those three coding digits. Since we just modify the last digits of the color components, the image with a concealed text doesn't look noticeably different from the original one. This is useful when sending secret messages through images. The following is a specific example on hiding a character in a pixel.

    We want to hide character 'w' (coding value of 119) into a pixel with RGB (232, 90, 178). Break the coding value into three digits: 1, 1, and 9.
    Then replace the last digits of the RGB color values. So, the modified pixel with RGB (231, 91, 179). 
    
  3. The "hideMessage" method in class Image will hide a text message into an image. The number of characters in the text message should be less than the number of pixels in the image. The text message could be stored in a text file. Your program reads the text message from the file. Input: a PNG image file and a text file containing a text message. Output: a PNG image file with a hidden text message. Make sure to use PNG images to test your program. JPG images don't work for this assignment, because JPG uses a lossy compression algorithm that discards some of the image information in order to reduce the size of the file, whereas PNG uses a lossless algorithm that keeps all the information. Use "png" as the format in ImageIO.write method as below:
      //Create a real output image file with pixel values from the Image object 
      public static void write(int [][] arr, String outputFile)
      {
        // ....
    	
        //Convert the BufferedImage image to a real image file such as jpg
        try{
          imgFile = new File(outputFile);
          ImageIO.write(img, "png", imgFile);
        }catch(IOException e){
          System.out.println(e);
        }  
      }
    
  4. The "revealMessage" method in class Image will reveal the text message concealed in an image using the opposite process. Input: a PNG image file with a hidden text message. Output: the hidden text message.
  5. Use histograms to compare the original image with the one with a concealed message. The difference should not be noticeable. Online histogram tool
  6. Think about how to add security protection for the message in case someone knows your hiding algorithm. For example, adding passcode before the message to be concealed or encrypting the message and then hiding into an image, etc. The following is the specific design:
    The first 10 pixels store a password, then next three store the length of a message to be concealed, then followed by the message.
    
    In the revealMessage method, check password first, get the length of the message, and then extract the text message.
  7. Bonus. Create a histogram for an image. You may create an Java BufferedImage object and add the histogram on it, and then convert into a JPEG file. Sample histogram