I keep getting an error starting from line public static boolean hide. Can someone please help I am using eclipse.

import java.util.*;
import java.io.File;
import java.io.*;
import java.io.BufferedReader;
import java.awt.*;
import java.lang.String;

public class Steganography {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
 
 
		
		public static boolean hide(String textFnm, String imFnm)
		{
		// read in the message
		String inputText = readTextFile(textFnm);
		if ((inputText == null) || (inputText.length() == 0))
		return false;
		byte[] stego = buildStego(inputText);
		// access the image's data as a byte array
		BufferedImage im = loadImage(imFnm);
		if (im == null)
		return false;
		byte imBytes[] = accessBytes(im);
		if (!singleHide(imBytes, stego)) // im is modified with the stego
		return false;
		// store the modified image in <fnm>Msg.png
		String fnm = getFileName(imFnm);
		return writeImageToFile( fnm + "Msg.png", im);
		} // end of hide()
		
		// global
		private static final int DATA_SIZE = 8;
		// number of image bytes required to store one stego byte
		private static byte[] buildStego(String inputText)
		{
		// convert data to byte arrays
		byte[] msgBytes = inputText.getBytes();
		byte[] lenBs = intToBytes(msgBytes.length);
		int totalLen = lenBs.length + msgBytes.length;
		byte[] stego = new byte[totalLen]; // for holding resulting stego
		// combine the two fields into one byte array
		System.arraycopy(lenBs, 0, stego, 0, lenBs.length);
		// length of binary message
		System.arraycopy(msgBytes, 0, stego, lenBs.length,msgBytes.length);
		// binary message
		return stego;
		} // end of buildStego()
		
		// global
		private static final int MAX_INT_LEN = 4;
		private static byte[] intToBytes(int i)
		{
		// map the parts of the integer to a byte array
		byte[] integerBs = new byte[MAX_INT_LEN];
		integerBs[0] = (byte) ((i >>> 24) & 0xFF);
		integerBs[1] = (byte) ((i >>> 16) & 0xFF);
		integerBs[2] = (byte) ((i >>> 8) & 0xFF);
		integerBs[3] = (byte) (i & 0xFF);
		return integerBs;
		} // end of intToBytes()
		
		private static byte[] accessBytes(BufferedImage image)
		{
		WritableRaster raster = image.getRaster();
		DataBufferByte buffer = (DataBufferByte) raster.getDataBuffer();
		return buffer.getData();
		} // end of accessBytes()
		
		private static boolean singleHide(byte[] imBytes, byte[] stego)
		{
		int imLen = imBytes.length;
		System.out.println("Byte length of image: " + imLen);
		int totalLen = stego.length;
		System.out.println("Total byte length of message: " + totalLen);
		// check that the stego will fit into the image
		/* multiply stego length by number of image bytes
		required to store one stego byte */
		if ((totalLen*DATA_SIZE) > imLen) {
		System.out.println("Image not big enough for message");
		return false;
		}
		hideStego(imBytes, stego, 0); // hide at start of image
		return true;
		} // end of singleHide()
		
		private static void hideStego(byte[] imBytes, byte[] stego,
				int offset)
				{
				for (int i = 0; i < stego.length; i++) { // loop through stego
				int byteVal = stego[i];
				for(int j=7; j >= 0; j--) { // loop through 8 bits of stego byte
				int bitVal = (byteVal >>> j) & 1;
				// change last bit of image byte to be the stego bit
				imBytes[offset] = (byte)((imBytes[offset] & 0xFE) | bitVal);
				offset++;
				}
				}
				} // end of hideStego()
		
		{
			// get the image's data as a byte array
			BufferedImage im = loadImage(imFnm);
			if (im == null)
			return false;
			byte[] imBytes = accessBytes(im);
			System.out.println("Byte length of image: " + imBytes.length);
			// get msg length at the start of the image
			int msgLen = getMsgLength(imBytes, 0);
			if (msgLen == -1)
			return false;
			System.out.println("Byte length of message: " + msgLen);
			// get message located after the length info in the image
			String msg = getMessage(imBytes, msgLen, MAX_INT_LEN*DATA_SIZE);
			if (msg != null) { // save message in a text file
			String fnm = getFileName(imFnm);
			return writeStringToFile(fnm + ".txt", msg);
			}
			else {
			System.out.println("No message found");
			return false;
			}
			} // end of reveal()
		private static int getMsgLength(byte[] imBytes, int offset)
		{
		byte[] lenBytes = extractHiddenBytes(imBytes, MAX_INT_LEN, offset);
		// get the binary message length as a byte array
		if (lenBytes == null)
		return -1;
		// convert the byte array into an integer
		int msgLen = ((lenBytes[0] & 0xff) << 24) |
		((lenBytes[1] & 0xff) << 16) |
		((lenBytes[2] & 0xff) << 8) |
		(lenBytes[3] & 0xff);
		if ((msgLen <= 0) || (msgLen > imBytes.length)) {
			System.out.println("Incorrect message length");
			return -1;
			}
			return msgLen;
			} // end of getMsgLength()
		
		private static byte[] extractHiddenBytes(byte[] imBytes,
				int size, int offset)
				{
				int finalPosn = offset + (size*DATA_SIZE);
				if (finalPosn > imBytes.length) {
				System.out.println("End of image reached");
				return null;
				}
				byte[] hiddenBytes = new byte[size];
				for (int j = 0; j < size; j++) { // loop through hidden bytes
				for (int i=0; i < DATA_SIZE; i++) {
				// make one hidden byte from DATA_SIZE image bytes
				hiddenBytes[j] = (byte) ((hiddenBytes[j] << 1) |
				(imBytes[offset] & 1));
				/* shift existing bits left;
				store LSB of image byte on the right */
				offset++;
				}
				}
				return hiddenBytes;
				} // end of extractHiddenBytes()
		
		private static String getMessage(byte[] imBytes, int msgLen, int
		offset)
		{
		byte[] msgBytes = extractHiddenBytes(imBytes, msgLen, offset);
		// the message is msgLen bytes long
		if (msgBytes == null)
		return null;
		String msg = new String(msgBytes);
		// check the message is all characters
		if (isPrintable(msg))
		return msg;
		else
		return null;
		} // end of getMessage()
		
		
		
		
	}

}

Edited 6 Years Ago by peter_budo: Please do not use CODE SNIPPED option to post question. Use FORUM THREAD!

You can't declare a method inside another method, and that one is being declared inside of main (as is the entire class, seemingly).

Edited 6 Years Ago by masijade: n/a

This article has been dead for over six months. Start a new discussion instead.