Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In simple Java code Steganography is the technique of hiding secret messages/inf

ID: 3779542 • Letter: I

Question

In simple Java code Steganography is the technique of hiding secret messages/information within other non-secret data/information. One popular way of steganography is hiding text within images. Each image is a collection of pixels, where each pixel is typically represented by 3 values (RGB). Each of R. G, and B is a value between 0 and 2S5 and thus can be represented by 8 bits. The color of the pixel depends on these values. However, if the least significant bit (last bit from the right) is changed for each of R. G. B then the resulting change in pixel color may not be noticeable. Using this fact, we can convert a text message to bits and embed them one by one in R, G, B values of the pixel. That is. each R. G. B value's last bit actually carries one bit of the secret message. This is one way to create a covert (secret) channel to pass information. Upon receipt of the image, the receiver can extract the last bit from each R. G, B and combine them to reveal the secret message. In this group assignment you are required to write a Java program that can embed and extract simple text message into a chosen JPEG image. The program should also allow to extract the message from the image. In particular, the program should do the following: Prompts user to enter a choice of JPEG image to hide a text message. Prompts user to enter the text message that is to be hidden. Create a modified image after hiding the text message (as explained above) and save the image as a new (PEG picture. Display the hidden message when a JPEG image is supplied. [For testing purpose, the user may choose to use a different image file that already has a message hidden into it]

Explanation / Answer

import java.awt.Component;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.util.Scanner;

public class Steganography extends Component {

public static void main(String[] foo) {
new JavaWalkBufferedImageTest1();
   Scanner user_input = new Scanner(System.in);
   System.out.println("Hidden Message");
   String hiddenmsg;
   hiddenmsg=user_input.next();
   byte[] bytes = hiddenmsg.getBytes();
   StringBuilder binary = new StringBuilder();
   for (byte b : bytes)
   {
       int val = b;
       for (int i = 0; i < 8; i++)
       {
           binary.append((val & 128) == 0 ? 0 : 1);
           val <<= 1;
       }
   }
   System.out.println("'" + hiddenmsg + "' to binary: " + binary);
}
  
public void printPixelARGB(int pixel) {
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel) & 0xff;
   String strBinaryNumber1 = Integer.toBinaryString(red);
   String strBinaryNumber2 = Integer.toBinaryString(green);
   String strBinaryNumber3 = Integer.toBinaryString(blue);
System.out.println("RGB (Decimal Format):" + red + ", " + green + ", " + blue);
   System.out.println("RGB (Binary Format):"+strBinaryNumber1+","+strBinaryNumber2+","+strBinaryNumber3);
   System.out.println("Last bit of RGB:" +strBinaryNumber1.substring(strBinaryNumber1.length()-1) + "," + strBinaryNumber2.substring(strBinaryNumber2.length()-1) + "," +strBinaryNumber3.substring(strBinaryNumber3.length()-1));
}
  
  

private void marchThroughImage(BufferedImage image) {
int w = image.getWidth();
int h = image.getHeight();

for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
int pixel = image.getRGB(j, i);
printPixelARGB(pixel);
System.out.println("");
}
}
}

public Steganography() {
try {
// get the BufferedImage, using the ImageIO class
   System.out.println("Enter the name of the image");
   Scanner input = new Scanner(System.in);
   String imagename;
   imagename=input.next();
BufferedImage image =
ImageIO.read(this.getClass().getResource(imagename+".jpg"));
marchThroughImage(image);
} catch (IOException e) {
System.err.println(e.getMessage());
}
}}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote