2 Replies - 221 Views - Last Post: 05 April 2013 - 02:03 PM Rate Topic: -----

#1 @rookie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-March 13

Audio stegnography

Posted 04 April 2013 - 03:30 PM

Hi, i am working on my final year project 1)hiding text in a image
2)image in a image
3)text in a audio file (WAVE)
i have successfully completed 1) and 2) and have attached the source code if anybody may need it.
i am having trouble in the 3rd one i.e hiding data in a audio file.

For this i have create a AudioInputStream using the audio file and then read it's byte data in a byte array.after editing when i try to convert it back to AudioInputStream i get UnsupportedAudioFileException . i suppose this happens because header info is not copied in the byte array. please help me out and please don't mind my lazy coding :P

i have attached all the files.
please help me in the audio stegnography
AudioInputStream audioInputStream = 
		    AudioSystem.getAudioInputStream(fileIn);
  // Set an arbitrary buffer size of 1024 frames.
		  int numBytes = 1024 * bytesPerFrame; 
		  byte[] audioBytes = new byte[numBytes];

		    	audioInputStream.read(audioBytes);
                  //then i edit the audio bytes stored in audioBytes

InputStream bais = new ByteArrayInputStream(audioBytes);
		    AudioInputStream ais = null;
			  

			try {
				ais = AudioSystem.getAudioInputStream(bais); // i m getting error here!
				AudioSystem.write(ais, Type.WAVE, new File("C:\\Users\\Rahul\\Desktop\\pro\\Don't Stay_restored.wav")); 
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

Attached File(s)


This post has been edited by Atli: 04 April 2013 - 04:03 PM
Reason for edit:: Use [code] tags when posting code.


Is This A Good Question/Topic? 0
  • +

Replies To: Audio stegnography

#2 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2555
  • View blog
  • Posts: 10,658
  • Joined: 20-September 08

Re: Audio stegnography

Posted 05 April 2013 - 05:59 AM

Quote

. i suppose this happens because header info is not copied in the byte array.

.. or perhaps that you have 'stegged' into the header and corrupted it? Either way, i suggest you do some experiments - as i'm guessing too ;)
Was This Post Helpful? 1
  • +
  • -

#3 @rookie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-March 13

Re: Audio stegnography

Posted 05 April 2013 - 02:03 PM

i did some research , and still many things are not clear. i'm guessing the 1st 44 bytes are the header bytes(since the file is of WAVE format) or the header is not copied at all.

but i tried something else and the previous problem doesnot trouble me anymore!
Since the byte array holds the reference to the audioinputstream data so creating a new audioinputstream out of the byte array , i think is not necessary at all , i can directly create a file out of the edited audioinputstream, and it works fine.

but the Problem now is ....
at the time of decoding again i have to read the data from the newly created audio file in a byte array. And i'm not able to locate the bytes where i have hidden data.
Can anybody tell me what exactly happens when we read data into a byte array from a audioinputstream , i mean what actually gets read into the byte array?
File fileIn = new File("C:\\Users\\Rahul\\Desktop\\pro\\Don't Stay.wav");
		
		  AudioInputStream audioInputStream = 
		    AudioSystem.getAudioInputStream(fileIn);
		 int avail= audioInputStream.available();
		 System.out.println("bytes available " +avail);
		 System.out.println(audioInputStream.markSupported());
		  int bytesPerFrame = 
		    audioInputStream.getFormat().getFrameSize();
		  // Set an arbitrary buffer size of 1024 frames.
		  int numBytes = 1024 * bytesPerFrame; 
		  byte[] audioBytes = new byte[numBytes];
                    audioInputStream.read(audioBytes);
		    	byte btext[]=Stego_text("good morning!");
				byte bcoded[]=steg.encoding(audioBytes,btext,0);

                    byte[] stg= a.decode_text(audioBytes);
		    String obtain= new String(stg);
		    System.out.println(">>>"+ obtain);


try {

				AudioSystem.write(audioInputStream, Type.WAVE, new File("C:\\Users\\Rahul\\Desktop\\pro\\Don't Stay_restored.wav"));
			} catch (Exception e) {
				
				e.printStackTrace();
			}
			byte[] audioBytesNew = new byte[numBytes];
		    audioInputStream.read(audioBytesNew);
		    byte[] stg1= a.decode_text(audioBytesNew);
		    String obtain1= new String(stg1);
		    System.out.println(">>>"+ obtain1);



if i decode the byte array just after editing , then it works fine and displays the hidden message, but after again creating a byte array and reading into it audioinputsream data and then decoding that byte array .. it does not work. i wonder WHY? please help me.
these functions i have used.


public byte[] Stego_text(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(

public byte[] decode_text(byte[] audio_byte_data) 
	{
		
		// get msg length at the start of the image
		int msgLen = getMsgLength(audio_byte_data, 0);
		
		if (msgLen == -1)
			System.out.println("false");
		System.out.println("Byte length of messsssssssage: " + msgLen);

				        byte[] str = new byte[msgLen]; // create a new array to hold string using the length found out
				        int array_incr=32;
				        //loop through each byte of text
				        for(int b=0; b<msgLen; ++b )
				        {
				            
							//loop through each bit within a byte of text
				            for(int i=0; i<8; ++i, ++array_incr)
				            {
				                //assign bit: [(new byte value) << 1] OR [(text byte) AND 1]
				                str[b] = (byte)((str[b] << 1) | (audio_byte_data[array_incr] & 1));
				                String y = new String(str);  
				              System.out.println("String "+ y);
				            }
				        }
				        return str;

	}

	private 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()
	
	public 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()



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1