Audio steganography..

Page 1 of 1

11 Replies - 5607 Views - Last Post: 06 April 2010 - 02:21 PM Rate Topic: ***-- 2 Votes

#1 dr.cean  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-January 08

Audio steganography..

Posted 28 January 2008 - 12:36 PM

[Edited to remove a long piece of code that is re-posted 2 topics below whith, this time, the question that goes with it

This post has been edited by pbl: 28 March 2009 - 11:24 AM

Is This A Good Question/Topic? 0
  • +

Replies To: Audio steganography..

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Audio steganography..

Posted 28 January 2008 - 12:39 PM

Use :code: tags.

Do you have a question relating to the code or are you just posting it for our benefit?
Was This Post Helpful? 0
  • +
  • -

#3 marveric  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 6
  • Joined: 31-January 08

Re: Audio steganography..

Posted 31 January 2008 - 04:49 AM

Can u please tell me what methods did u use to develop this program?
Did u use Least significant bit(LSB) technique in this code? Plz give some explanations regarding this code like what algorithms u used for encryption decryption n key generation n methods u used for embedding?
Was This Post Helpful? 0
  • +
  • -

#4 priteshcontractor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 12-February 08

Re: Audio steganography..

Posted 11 March 2008 - 08:22 AM

i want to know what sort of method you actually use and wht algorithm for decryption and encryption is used in it can you please tell me
Was This Post Helpful? 0
  • +
  • -

#5 sirish49  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 31-December 08

Re: Audio steganography..

Posted 28 March 2009 - 07:22 AM

View Postdr.cean, on 28 Jan, 2008 - 11:36 AM, said:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import java.util.*;
import sun.audio.*;
import java.applet.*;
import java.math.*;

class mainframe extends JFrame implements ActionListener,Runnable
 {
  JLabel Lfilename,Lmessage,Ldesign,Ltitle;
  JButton Bplay,Bopen,Bsave,Bstop,Bencrypt,Bdecrypt,Bsend,Bclear;
  JTextArea Amessage;
  JTextField Tfilename;
  Icon Iplay,Iopen,Istop,Isave;
  String Ekey,Dkey,address,name;
  JFileChooser filechooser;
  File Ofilename,Sfilename,tempfilename;
  InetAddress ipaddress;
  int Copened,Cencrypt,Cdecrypt,Cplay,Cstop,Csave;
  InputStream ins;
  AudioStream as;
  Thread t;

  public mainframe()throws Exception
   {

	// frame

	super("Swathe 1.0 - Steganography Using Audio");
	Container con=getContentPane();
	con.setLayout(null);

	// Basic

	Copened=0;
	Cencrypt=0;
	Cdecrypt=0;
	Cplay=0;
	Csave=0;
	Cstop=0;

	t=new Thread(this);
	t.start();

	// Icons

	Iplay=new ImageIcon("c:\Icon\play.gif");
	Isave=new ImageIcon("c:\Icon\save.gif");
	Iopen=new ImageIcon("c:\Icon\open.gif");
	Istop=new ImageIcon("c:\Icon\stop1.gif");

	// file chooser

	filechooser=new JFileChooser();
	filechooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

	// comp

	Ltitle=new JLabel("Steganography Using Audio");
	Ldesign=new JLabel("Designed By : M.Dayananthan, D.Langesh,
M.Vanitha");
	Lfilename=new JLabel("File Name ");
	Lmessage=new JLabel("Message  ");
	Bplay=new JButton("",Iplay);
	Bopen=new JButton("",Iopen);
	Bsave=new JButton("",Isave);
	Bstop=new JButton("",Istop);
	Bclear=new JButton("Clear");
	Bencrypt=new JButton("Encoding");
	Bdecrypt=new JButton("Decoding");
	Bsend=new JButton("Send");
	Amessage=new JTextArea();
	Tfilename=new JTextField();

	// tool tips

	Tfilename.setToolTipText("Opened filename");
	Bplay.setToolTipText("play");
	Bopen.setToolTipText("open");
	Bsave.setToolTipText("save");
	Bstop.setToolTipText("stop");

	Tfilename.setEditable(false);

	// Bounds

	Ltitle.setBounds(300,30,250,25);
	Lfilename.setBounds(100,100,100,25);
	Tfilename.setBounds(100,125,230,25);
	Lmessage.setBounds(450,100,100,25);
	Amessage.setBounds(450,125,300,220);
	Bclear.setBounds(450,370,80,22);
	Bplay.setBounds(100,200,50,25);
	Bstop.setBounds(160,200,50,25);
	Bopen.setBounds(220,200,50,25);
	Bsave.setBounds(280,200,50,25);
	Bencrypt.setBounds(100,250,110,25);
	Bdecrypt.setBounds(220,250,110,25);
	Bsend.setBounds(160,300,110,25);
	Ldesign.setBounds(350,420,400,50);


	// add

	con.add(Ltitle);
	con.add(Ldesign);
	con.add(Lfilename);
	con.add(Tfilename);
	con.add(Lmessage);
	con.add(Amessage);
	con.add(Bclear);
	con.add(Bplay);
	con.add(Bopen);
	con.add(Bsave);
	con.add(Bstop);
	con.add(Bencrypt);
	con.add(Bdecrypt);
	con.add(Bsend);

	// actionListener

	Bclear.addActionListener(this);
	Bplay.addActionListener(this);
	Bopen.addActionListener(this);
	Bsave.addActionListener(this);
	Bstop.addActionListener(this);
	Bencrypt.addActionListener(this);
	Bdecrypt.addActionListener(this);
	Bsend.addActionListener(this);

   } // constr of mainframe

  public void run()
   {
	try
	 {
	  recv r=new recv();
	 }
	catch(Exception e)
	 {
	  System.out.println(e);
	 }
   }

  public void Audioencrypt(String message,File file,int key) throws
Exception
   {
	byte b[]=new byte[1];
	BigInteger Abi,Mbi;
	int k,k1;
	InputStream ins=new FileInputStream(file);
	OutputStream outs=new FileOutputStream(new File("d:\temp.wav"));
	for(int c=0;c<key;c++)
	 {
	  int ch=ins.read();
	  outs.write(ch);
	 }
	int len=message.length();
	byte mess[]=new byte[1];
	char chmess[]=new char[len+1];
	k=k1=0;
	for(int i=0;i<=len;i++)
	 {
	  message.getChars(0,len,chmess,0);
	  if(i==0)
	   {
		BigDecimal bd=new BigDecimal(len);
		BigInteger Blen=bd.toBigInteger();
		String Slen=Blen.toString(2);
		char Clen[]=new char[Blen.bitLength()];
		Slen.getChars(0,Blen.bitLength(),Clen,0);
		for(int j=0;j<=7;j++)
		 {
		  if(j==0)
		   {
			for(k=0;k<8-Blen.bitLength();k++)
			 {
			  int n=ins.read(B);
			  Abi=new BigInteger(B);
			  String Aby=Abi.toString(2);
			  int Alen=Abi.bitLength();
			  if(b[0]<0)
				Alen++;
			  char Ach[]=new char[Alen+1];
			  Aby.getChars(0,Alen,Ach,0);

		  if(b[0]==0)
		   {
		   }
		  else
		   {
			  if(Ach[Alen-1]=='1')
			   {
				if(Alen==Abi.bitLength())
		 {
				  BigInteger bi=new BigInteger("11111110",2);
				  BigInteger big=Abi.and(bi);
		  b=big.toByteArray();
		 }
 		else
		 {
						BigInteger bi=new BigInteger("-1",2);
					  BigInteger big=Abi.subtract(bi);
		  b=big.toByteArray();
		 }
			   }
		outs.write(B);
			 }
		   }  //for loop k
		 j=j+k-1;
		 } // if of j
			else
			 {
			  int n=ins.read(B);
			  Abi=new BigInteger(B);
			  String Aby=Abi.toString(2);
			  int Alen=Abi.bitLength();
				  if(b[0]<0)
				  Alen++;
			  char Ach[]=new char[Alen+1];
			  Aby.getChars(0,Alen,Ach,0);
			 if(b[0]==0)
			  {
				   Alen=1;
			  }
				if(Clen[j-k]=='0' && Ach[Alen-1]=='1')
				 {
					   if(Alen==Abi.bitLength())
						{
				 	 BigInteger bi=new BigInteger("11111110",2);
					 BigInteger big=Abi.and(bi);
			 b=big.toByteArray();
						}
					   else
						{
						BigInteger bi=new BigInteger("-1",2);
					  BigInteger big=Abi.subtract(bi);
			 b=big.toByteArray();
						}
			 		 }
				else if(Clen[j-k]=='1' && Ach[Alen-1]=='0')
				 {
					  if(Alen==Abi.bitLength())
			 {
					BigInteger bi=new BigInteger("1",2);
			BigInteger big=Abi.add(bi);
			b=big.toByteArray();
			 }
					  else
			 {
					BigInteger bi=new BigInteger("-1",2);
			BigInteger big=Abi.add(bi);
			b=big.toByteArray();
			 }

				 }
	   		   outs.write(B);
				 } // end else

			} // for loop j

		} // end of if

	  else
	   {
		String slen=String.valueOf(chmess[i-1]);
		byte blen[]=slen.getBytes();
		BigInteger Blen=new BigInteger(blen);
		String Slen=Blen.toString(2);
		char Clen[]=new char[Blen.bitLength()];
		Slen.getChars(0,Blen.bitLength(),Clen,0);
		for(int j=0;j<=7;j++)
		 {
		  if(j==0)
		   {
			for(k1=0;k1<8-Blen.bitLength();k1++)
			 {
			  int n=ins.read(B);
			  Abi=new BigInteger(B);
		  String Aby=Abi.toString(2);
			  int Alen=Abi.bitLength();
				  if(b[0]<0)
				  Alen++;
			  char Ach[]=new char[Alen+1];
			  Aby.getChars(0,Alen,Ach,0);
 		if(b[0]==0)
			   {

			   }
		  else
		   {
				  if(Ach[Alen-1]=='1')
				   {
						if(Alen==Abi.bitLength())
						 {
					  BigInteger bi=new BigInteger("11111110",2);
					  BigInteger big=Abi.and(bi);
			  b=big.toByteArray();
						 }
						else
						 {
						BigInteger bi=new BigInteger("-1",2);
					  BigInteger big=Abi.subtract(bi);
			  b=big.toByteArray();
						 }
				   }
		   }
		outs.write(B);

			  }  //for loop k

		j=j+k1-1;

			 } // if of j

		else
		 {
		  int n=ins.read(B);
		   Abi=new BigInteger(B);
			  String Aby=Abi.toString(2);
			  int Alen=Abi.bitLength();
				  if(b[0]<0)
				  Alen++;
			  char Ach[]=new char[Alen+1];
			  Aby.getChars(0,Alen,Ach,0);
			  if(b[0]==0)
			   {
			Alen=1;
			   }

				if(Clen[j-k1]=='0' && Ach[Alen-1]=='1')
				 {
			if(Alen==Abi.bitLength())
 			 {
						BigInteger bi=new BigInteger("11111110",2);
					  BigInteger big=Abi.and(bi);
			  b=big.toByteArray();
						 }
						else
 			 {
						BigInteger bi=new BigInteger("-1",2);
					  BigInteger big=Abi.subtract(bi);
			  b=big.toByteArray();
						 }
				 }
				else if(Clen[j-k1]=='1' && Ach[Alen-1]=='0')
				 {
			if(Alen==Abi.bitLength())
			 {
			   	  BigInteger bi=new BigInteger("1",2);
					  BigInteger big=Abi.add(bi);
			  b=big.toByteArray();
 			 }
			else
			 {
			   	  BigInteger bi=new BigInteger("-1",2);
					  BigInteger big=Abi.add(bi);
			  b=big.toByteArray();
 			 }
				 }
		outs.write(B);
		 } // end else

	   } // for loop j
	 } // end of else

   } // for loop i

  while(true)
   {
	int i=ins.read();
	if(i==-1) break;
	outs.write(i);
   }
	ins.close();
	outs.close();
   }

public void Audiodecrypt(File filename,int key)throws Exception
 {
  InputStream ins=new FileInputStream(filename);
  byte b[]=new byte[1];
  BigInteger bb1;
  char mess[]=new char[8];
  int c=0;
  for(int i=0;i<key;i++)
  {
   int n=ins.read();
  }
  for(int i=0;i<8;i++)
   {
	ins.read(B);
	bb1=new BigInteger(B);
	String str=bb1.toString(2);
	int len=bb1.bitLength();
	if(b[0]<0)
	 len++;
	char ch[]=new char[len+1];
	str.getChars(0,len,ch,0);
	if(b[0]==0)
	 mess[i]='0';
	else
	 mess[i]=ch[len-1];
   }
  String dd=new String(mess);
  BigInteger bb=new BigInteger(dd,2);
  String s=bb.toString(2);
 int l=bb.intValue();

char me[]=new char[l];
int count=0;

for(int m=0;m<l;m++)
 {
for(int i=0;i<8;i++)
   {
	ins.read(B);
	bb1=new BigInteger(B);
	String str=bb1.toString(2);
	int len=bb1.bitLength();
	if(b[0]<0)
	 len++;
	char ch[]=new char[len+1];
	str.getChars(0,len,ch,0);
	if(b[0]==0)
	 mess[i]='0';
	else
	 mess[i]=ch[len-1];
   }
  String dd1=new String(mess);
  BigInteger bb2=new BigInteger(dd1,2);
  String s1=bb2.toString(2);
 int l1=bb2.intValue();
 me[count]=(char)l1;
 count++;
 }

String message=new String(me);
Amessage.setText(message);
ins.close();

 }

  public void actionPerformed(ActionEvent ae)
   {

   try
	{

 // Action for encryption button

	if(ae.getSource()==Bencrypt)
	 {
	  if(Copened==1)
	   {
		Ekey=JOptionPane.showInputDialog("Enter The Key For 
Encryption");
//String type
		if(Ekey.trim().equals(""))
		 JOptionPane.showMessageDialog(this,"Enter the
Key","Error",JOptionPane.ERROR_MESSAGE);
		else
		 {
		  // encrypt the message
		  int key=Integer.parseInt(Ekey);
		  Audioencrypt(Amessage.getText(),Ofilename,key);
		  Cencrypt=1;
		 }
	   }
	  else
	   {
		JOptionPane.showMessageDialog(this,"File Not
Opened","Error",JOptionPane.ERROR_MESSAGE);
	   }
	 } // end of Bencrypt

// Action for Clear button

	else if(ae.getSource()==Bclear)
	 {
	  Amessage.setText("");
	 } // end of clear button

// Action for Decrypt button

	else if(ae.getSource()==Bdecrypt)
	 {
	  if(Copened==1)
	   {
		Dkey=JOptionPane.showInputDialog("Enter The Key For 
Decryption");
//String type
		if(Dkey.trim().equals(""))
		 JOptionPane.showMessageDialog(this,"Enter the
Key","Error",JOptionPane.ERROR_MESSAGE);
		else
		 {
		 // decrypt message
		  int key=Integer.parseInt(Dkey);
		 Audiodecrypt(Ofilename,key);
		 Cdecrypt=1;
		 }
	   }
	  else
	   JOptionPane.showMessageDialog(this,"File Not
Opened","Error",JOptionPane.ERROR_MESSAGE);
	 } // end of Decrypt button

// Action for Play button

	else if(ae.getSource()==Bplay)
	 {
	  if(Copened==1)
	   {

		 ins=new FileInputStream(Ofilename);
		 as=new AudioStream(ins);
		 AudioPlayer.player.start(as);
		 Cplay=1;
		 Cstop=0;

	   } // start playing

	  else
	   JOptionPane.showMessageDialog(this,"File Not
Opened","Error",JOptionPane.ERROR_MESSAGE);

	 } // end of play button



// Action for Stop button

	else if(ae.getSource()==Bstop)
	 {

	  if(Cplay==1)
	   {

		Cplay=0;
		Cstop=1;
		AudioPlayer.player.stop(as);

	   } // stop plaing

	  else

	   JOptionPane.showMessageDialog(this,"No Audio Is
playing","Error",JOptionPane.ERROR_MESSAGE);

	 } // end of stop button



// Action for open Button

	else if(ae.getSource()==Bopen)
	 {
	  int r=filechooser.showOpenDialog(this);
	  tempfilename=filechooser.getSelectedFile(); //File type
	  if(r==JFileChooser.CANCEL_OPTION)
	   JOptionPane.showMessageDialog(this,"File Not
Selected","Error",JOptionPane.ERROR_MESSAGE);
	  else
	   {
		name=tempfilename.getName();

		if(!(name.endsWith(".wav")))

		  JOptionPane.showMessageDialog(this,"Select Only
Wav","Error",JOptionPane.ERROR_MESSAGE);

		else
		  {
			Copened=1;
			Ofilename=tempfilename;
			Tfilename.setEditable(true);
			Tfilename.setText(name);
			Tfilename.setEditable(false);
		   }

		 }
	 }   // end of Open button

// Action for Save Button

	else if(ae.getSource()==Bsave)
	 {
	  if(Copened==1 && Cencrypt==1 || Cdecrypt==1)
	   {
		int r=filechooser.showSaveDialog(this);
		Sfilename=filechooser.getSelectedFile(); //File type
		InputStream in=new FileInputStream("d:\temp.wav");
		OutputStream out=new FileOutputStream(Sfilename);
		Ofilename=Sfilename;
	name=Sfilename.getName();
		Tfilename.setEditable(true);
		Tfilename.setText(name);
		Tfilename.setEditable(false);
		while(true)
		 {
		  int i=in.read();
		  if(i==-1) break;
		  out.write(i);
		 }
	   in.close();
	   out.close();
	   }
	  else
	   {
		String s;
		if(Copened==0)
		 s="File not Opened";
		else if(Cencrypt==0)
		 s="Not Encrypted";
		else
		 s="Not Decrypted";

JOptionPane.showMessageDialog(this,s,"Error",JOptionPane.ERROR_MESSAGE);
	   }
	 } // end of save button

// Action for send button

	else if(ae.getSource()==Bsend)
	 {
	  if(Copened==1 && Cencrypt==1)
	   {
		address=JOptionPane.showInputDialog("Enter The IPaddress");
		ipaddress=InetAddress.getByName(address);
		Socket socket=new Socket(ipaddress,6000);
		OutputStream out=socket.getOutputStream();
		InputStream in=new FileInputStream(Ofilename);
		while(true)
		 {
		  int i=in.read();
		  if(i==-1) break;
		  out.write(i);
		 }
		 in.close();
		 out.close();
	   }
	  else
	   {
		String s;
		if(Copened==1)
		  s="Encryption not done";
		else
		  s="Open the File first";

JOptionPane.showMessageDialog(this,s,"Error",JOptionPane.ERROR_MESSAGE);
	   }
	 }

	} // end try
	catch(Exception e)
	 {
	 //
JOptionPane.showMessageDialog(this,e,"Error",JOptionPane.ERROR_MESSAGE);
	 }

   } // end of actionperformed

 }//end of class


class recv extends JFrame implements Runnable
 {
   JFileChooser fc;
   ServerSocket ss;
   Socket s;
   InputStream ins;
   OutputStream out;
   byte b[];
   int len;

  public recv() throws Exception
	{

	  b=new byte[100];
	  fc=new JFileChooser();
	  fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
	  ss=new ServerSocket(6000);
	  torun();
	}
  public void torun() throws Exception
   {
	  while(true)
	   {
		s=ss.accept();
		ins=s.getInputStream();
		String str="Your have Receive An AudioFile.
Save them";

JOptionPane.showMessageDialog(this,str,"Information",JOptionPane.INFORMATI
ON_MESSAGE);
		int r=fc.showSaveDialog(this);
		File file=fc.getSelectedFile();
		out=new FileOutputStream(file);
		Thread t=new Thread(this);
		t.start();
	   }
	}
   public void run()
	{
	  try
		{
		 while(true)
		  {
		   int n=ins.read();
 	   if(n==-1) break;
		   out.write(n);
		  }
	   //  s.close();
		 ins.close();
		 out.close();
		}
	  catch(Exception e)
		{
		   System.out.println(e);
		}
	} // end of run
 } //end of class




public class techmeet1
 {
  public static void main(String arg[])throws Exception
   {
	mainframe frame=new mainframe();
	frame.setSize(800,600);
	frame.setVisible(true);


	frame.addWindowListener( new WindowAdapter()
	 {
	  public void windowClosing(WindowEvent we)
	   {
		System.exit(0);
	   }
	 });

   } // end of main

 } // end of class

Was This Post Helpful? 0
  • +
  • -

#6 nupur3110  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 11-May 09

Re: Audio steganography..

Posted 11 May 2009 - 09:00 AM

can you please correct the errors in the java code on audio and image steganography?is this code ibased on image steganography only or both audio and image steganography? can you tell me that for this code java swing is used or something else?


/*
*import list
*/
import java.io.File;

import java.awt.Point;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.awt.image.DataBufferByte;

import javax.imageio.ImageIO;
import javax.swing.JOptionPane;

/*
*Class Steganography
*/
public class Steganography
{
	
	/*
	 *Steganography Empty Constructor
	 */
	public Steganography()
	{
	}
	
	/*
	 *Encrypt an image with text, the output file will be of type .png
	 *@param path		 The path (folder) containing the image to modify
	 *@param original	The name of the image to modify
	 *@param ext1		  The extension type of the image to modify (jpg, png)
	 *@param stegan	  The output name of the file
	 *@param message  The text to hide in the image
	 *@param type	  integer representing either basic or advanced encoding
	 */
	public boolean encode(String path, String original, String ext1, String stegan, String message)
	{
		String			file_name	 = image_path(path,original,ext1);
		BufferedImage	 image_orig	= getImage(file_name);
		
		//user space is not necessary for Encrypting
		BufferedImage image = user_space(image_orig);
		image = add_text(image,message);
		
		return(setImage(image,new File(image_path(path,stegan,"png")),"png"));
	}
	
	/*
	 *Decrypt assumes the image being used is of type .png, extracts the hidden text from an image
	 *@param path   The path (folder) containing the image to extract the message from
	 *@param name The name of the image to extract the message from
	 *@param type integer representing either basic or advanced encoding
	 */
	public String decode(String path, String name)
	{
		byte[] decode;
		try
		{
			//user space is necessary for decrypting
			BufferedImage image  = user_space(getImage(image_path(path,name,"png")));
			decode = decode_text(get_byte_data(image));
			return(new String(decode));
		}
		catch(Exception e)
		{
			JOptionPane.showMessageDialog(null,
				"There is no hidden message in this image!","Error",
				JOptionPane.ERROR_MESSAGE);
			return "";
		}
	}
	
	/*
	 *Returns the complete path of a file, in the form: path\name.ext
	 *@param path   The path (folder) of the file
	 *@param name The name of the file
	 *@param ext	  The extension of the file
	 *@return A String representing the complete path of a file
	 */
	private String image_path(String path, String name, String ext)
	{
		return path + "/" + name + "." + ext;
	}
	
	/*
	 *Get method to return an image file
	 *@param f The complete path name of the image.
	 *@return A BufferedImage of the supplied file path
	 *@see	Steganography.image_path
	 */
	private BufferedImage getImage(String f)
	{
		BufferedImage	 image	= null;
		File		 file	 = new File(f);
		
		try
		{
			image = ImageIO.read(file);
		}
		catch(Exception ex)
		{
			JOptionPane.showMessageDialog(null,
				"Image could not be read!","Error",JOptionPane.ERROR_MESSAGE);
		}
		return image;
	}
	
	/*
	 *Set method to save an image file
	 *@param image The image file to save
	 *@param file	  File  to save the image to
	 *@param ext	  The extension and thus format of the file to be saved
	 *@return Returns true if the save is succesful
	 */
	private boolean setImage(BufferedImage image, File file, String ext)
	{
		try
		{
			file.delete(); //delete resources used by the File
			ImageIO.write(image,ext,file);
			return true;
		}
		catch(Exception e)
		{
			JOptionPane.showMessageDialog(null,
				"File could not be saved!","Error",JOptionPane.ERROR_MESSAGE);
			return false;
		}
	}
	
	/*
	 *Handles the addition of text into an image
	 *@param image The image to add hidden text to
	 *@param text	 The text to hide in the image
	 *@return Returns the image with the text embedded in it
	 */
	private BufferedImage add_text(BufferedImage image, String text)
	{
		//convert all items to byte arrays: image, message, message length
		byte img[]  = get_byte_data(image);
		byte msg[] = text.getBytes();
		byte len[]   = bit_conversion(msg.length);
		try
		{
			encode_text(img, len,  0); //0 first positiong
			encode_text(img, msg, 32); //4 bytes of space for length: 4bytes*8bit = 32 bits
		}
		catch(Exception e)
		{
			JOptionPane.showMessageDialog(null,
"Target File cannot hold message!", "Error",JOptionPane.ERROR_MESSAGE);
		}
		return image;
	}
	
	/*
	 *Creates a user space version of a Buffered Image, for editing and saving bytes
	 *@param image The image to put into user space, removes compression interferences
	 *@return The user space version of the supplied image
	 */
	private BufferedImage user_space(BufferedImage image)
	{
		//create new_img with the attributes of image
		BufferedImage new_img  = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
		Graphics2D	graphics = new_img.createGraphics();
		graphics.drawRenderedImage(image, null);
		graphics.dispose(); //release all allocated memory for this image
		return new_img;
	}
	
	/*
	 *Gets the byte array of an image
	 *@param image The image to get byte data from
	 *@return Returns the byte array of the image supplied
	 *@see Raster
	 *@see WritableRaster
	 *@see DataBufferByte
	 */
	private byte[] get_byte_data(BufferedImage image)
	{
		WritableRaster raster   = image.getRaster();
		DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer();
		return buffer.getData();
	}
	
	/*
	 *Gernerates proper byte format of an integer
	 *@param i The integer to convert
	 *@return Returns a byte[4] array converting the supplied integer into bytes
	 */
	private byte[] bit_conversion(int i)
	{
		//originally integers (ints) cast into bytes
		//byte byte7 = (byte)((i & 0xFF00000000000000L) >>> 56);
		//byte byte6 = (byte)((i & 0x00FF000000000000L) >>> 48);
		//byte byte5 = (byte)((i & 0x0000FF0000000000L) >>> 40);
		//byte byte4 = (byte)((i & 0x000000FF00000000L) >>> 32);
		
		//only using 4 bytes
		byte byte3 = (byte)((i & 0xFF000000) >>> 24); //0
		byte byte2 = (byte)((i & 0x00FF0000) >>> 16); //0
		byte byte1 = (byte)((i & 0x0000FF00) >>> 8 ); //0
		byte byte0 = (byte)((i & 0x000000FF)	   );
		//{0,0,0,byte0} is equivalent, since all shifts >=8 will be 0
		return(new byte[]{byte3,byte2,byte1,byte0});
	}
	
	/*
	 *Encode an array of bytes into another array of bytes at a supplied offset
	 *@param image	 Array of data representing an image
	 *@param addition Array of data to add to the supplied image data array
	 *@param offset	  The offset into the image array to add the addition data
	 *@return Returns data Array of merged image and addition data
	 */
	private byte[] encode_text(byte[] image, byte[] addition, int offset)
	{
		//check that the data + offset will fit in the image
		if(addition.length + offset > image.length)
		{
			throw new IllegalArgumentException("File not long enough!");
		}
		//loop through each addition byte
		for(int i=0; i<addition.length; ++i)
		{
			//loop through the 8 bits of each byte
			int add = addition[i];
			for(int bit=7; bit>=0; --bit, ++offset) //ensure the new offset value carries on through both loops
			{
				//assign an integer to b, shifted by bit spaces AND 1
				//a single bit of the current byte
				int b = (add >>> bit) & 1;
				//assign the bit by taking: [(previous byte value) AND 0xfe] OR bit to add
				//changes the last bit of the byte in the image to be the bit of addition
				image[offset] = (byte)((image[offset] & 0xFE) | b );
			}
		}
		return image;
	}
	
	/*
	 *Retrieves hidden text from an image
	 *@param image Array of data, representing an image
	 *@return Array of data which contains the hidden text
	 */
	private byte[] decode_text(byte[] image)
	{
		int length = 0;
		int offset  = 32;
		//loop through 32 bytes of data to determine text length
		for(int i=0; i<32; ++i) //i=24 will also work, as only the 4th byte contains real data
		{
			length = (length << 1) | (image[i] & 1);
		}
		
		byte[] result = new byte[length];
		
		//loop through each byte of text
		for(int b=0; b<result.length; ++b )
		{
			//loop through each bit within a byte of text
			for(int i=0; i<8; ++i, ++offset)
			{
				//assign bit: [(new byte value) << 1] OR [(text byte) AND 1]
				result[b] = (byte)((result[b] << 1) | (image[offset] & 1));
			}
		}
		return result;
	}
}


Was This Post Helpful? 0
  • +
  • -

#7 matJeff  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 12-February 10

Re: Audio steganography..

Posted 12 February 2010 - 09:01 AM

Can you please tell the name of the algorithm used to develop the code in dr.cean's code? Thank you very much...
Was This Post Helpful? 0
  • +
  • -

#8 kartikp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-March 10

Re: Audio steganography..

Posted 20 March 2010 - 02:28 AM

View Postsirish49, on 28 March 2009 - 06:22 AM, said:

View Postdr.cean, on 28 Jan, 2008 - 11:36 AM, said:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import java.util.*;
import sun.audio.*;
import java.applet.*;
import java.math.*;

class mainframe extends JFrame implements ActionListener,Runnable
 {
  JLabel Lfilename,Lmessage,Ldesign,Ltitle;
  JButton Bplay,Bopen,Bsave,Bstop,Bencrypt,Bdecrypt,Bsend,Bclear;
  JTextArea Amessage;
  JTextField Tfilename;
  Icon Iplay,Iopen,Istop,Isave;
  String Ekey,Dkey,address,name;
  JFileChooser filechooser;
  File Ofilename,Sfilename,tempfilename;
  InetAddress ipaddress;
  int Copened,Cencrypt,Cdecrypt,Cplay,Cstop,Csave;
  InputStream ins;
  AudioStream as;
  Thread t;

  public mainframe()throws Exception
   {

	// frame

	super("Swathe 1.0 - Steganography Using Audio");
	Container con=getContentPane();
	con.setLayout(null);

	// Basic

	Copened=0;
	Cencrypt=0;
	Cdecrypt=0;
	Cplay=0;
	Csave=0;
	Cstop=0;

	t=new Thread(this);
	t.start();

	// Icons

	Iplay=new ImageIcon("c:\Icon\play.gif");
	Isave=new ImageIcon("c:\Icon\save.gif");
	Iopen=new ImageIcon("c:\Icon\open.gif");
	Istop=new ImageIcon("c:\Icon\stop1.gif");

	// file chooser

	filechooser=new JFileChooser();
	filechooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

	// comp

	Ltitle=new JLabel("Steganography Using Audio");
	Ldesign=new JLabel("Designed By : M.Dayananthan, D.Langesh,
M.Vanitha");
	Lfilename=new JLabel("File Name ");
	Lmessage=new JLabel("Message  ");
	Bplay=new JButton("",Iplay);
	Bopen=new JButton("",Iopen);
	Bsave=new JButton("",Isave);
	Bstop=new JButton("",Istop);
	Bclear=new JButton("Clear");
	Bencrypt=new JButton("Encoding");
	Bdecrypt=new JButton("Decoding");
	Bsend=new JButton("Send");
	Amessage=new JTextArea();
	Tfilename=new JTextField();

	// tool tips

	Tfilename.setToolTipText("Opened filename");
	Bplay.setToolTipText("play");
	Bopen.setToolTipText("open");
	Bsave.setToolTipText("save");
	Bstop.setToolTipText("stop");

	Tfilename.setEditable(false);

	// Bounds

	Ltitle.setBounds(300,30,250,25);
	Lfilename.setBounds(100,100,100,25);
	Tfilename.setBounds(100,125,230,25);
	Lmessage.setBounds(450,100,100,25);
	Amessage.setBounds(450,125,300,220);
	Bclear.setBounds(450,370,80,22);
	Bplay.setBounds(100,200,50,25);
	Bstop.setBounds(160,200,50,25);
	Bopen.setBounds(220,200,50,25);
	Bsave.setBounds(280,200,50,25);
	Bencrypt.setBounds(100,250,110,25);
	Bdecrypt.setBounds(220,250,110,25);
	Bsend.setBounds(160,300,110,25);
	Ldesign.setBounds(350,420,400,50);


	// add

	con.add(Ltitle);
	con.add(Ldesign);
	con.add(Lfilename);
	con.add(Tfilename);
	con.add(Lmessage);
	con.add(Amessage);
	con.add(Bclear);
	con.add(Bplay);
	con.add(Bopen);
	con.add(Bsave);
	con.add(Bstop);
	con.add(Bencrypt);
	con.add(Bdecrypt);
	con.add(Bsend);

	// actionListener

	Bclear.addActionListener(this);
	Bplay.addActionListener(this);
	Bopen.addActionListener(this);
	Bsave.addActionListener(this);
	Bstop.addActionListener(this);
	Bencrypt.addActionListener(this);
	Bdecrypt.addActionListener(this);
	Bsend.addActionListener(this);

   } // constr of mainframe

  public void run()
   {
	try
	 {
	  recv r=new recv();
	 }
	catch(Exception e)
	 {
	  System.out.println(e);
	 }
   }

  public void Audioencrypt(String message,File file,int key) throws
Exception
   {
	byte b[]=new byte[1];
	BigInteger Abi,Mbi;
	int k,k1;
	InputStream ins=new FileInputStream(file);
	OutputStream outs=new FileOutputStream(new File("d:\temp.wav"));
	for(int c=0;c<key;c++)
	 {
	  int ch=ins.read();
	  outs.write(ch);
	 }
	int len=message.length();
	byte mess[]=new byte[1];
	char chmess[]=new char[len+1];
	k=k1=0;
	for(int i=0;i<=len;i++)
	 {
	  message.getChars(0,len,chmess,0);
	  if(i==0)
	   {
		BigDecimal bd=new BigDecimal(len);
		BigInteger Blen=bd.toBigInteger();
		String Slen=Blen.toString(2);
		char Clen[]=new char[Blen.bitLength()];
		Slen.getChars(0,Blen.bitLength(),Clen,0);
		for(int j=0;j<=7;j++)
		 {
		  if(j==0)
		   {
			for(k=0;k<8-Blen.bitLength();k++)
			 {
			  int n=ins.read(B)/>;
			  Abi=new BigInteger(B)/>;
			  String Aby=Abi.toString(2);
			  int Alen=Abi.bitLength();
			  if(b[0]<0)
				Alen++;
			  char Ach[]=new char[Alen+1];
			  Aby.getChars(0,Alen,Ach,0);

		  if(b[0]==0)
		   {
		   }
		  else
		   {
			  if(Ach[Alen-1]=='1')
			   {
				if(Alen==Abi.bitLength())
		 {
				  BigInteger bi=new BigInteger("11111110",2);
				  BigInteger big=Abi.and(bi);
		  b=big.toByteArray();
		 }
 		else
		 {
						BigInteger bi=new BigInteger("-1",2);
					  BigInteger big=Abi.subtract(bi);
		  b=big.toByteArray();
		 }
			   }
		outs.write(B)/>;
			 }
		   }  //for loop k
		 j=j+k-1;
		 } // if of j
			else
			 {
			  int n=ins.read(B)/>;
			  Abi=new BigInteger(B)/>;
			  String Aby=Abi.toString(2);
			  int Alen=Abi.bitLength();
				  if(b[0]<0)
				  Alen++;
			  char Ach[]=new char[Alen+1];
			  Aby.getChars(0,Alen,Ach,0);
			 if(b[0]==0)
			  {
				   Alen=1;
			  }
				if(Clen[j-k]=='0' && Ach[Alen-1]=='1')
				 {
					   if(Alen==Abi.bitLength())
						{
				 	 BigInteger bi=new BigInteger("11111110",2);
					 BigInteger big=Abi.and(bi);
			 b=big.toByteArray();
						}
					   else
						{
						BigInteger bi=new BigInteger("-1",2);
					  BigInteger big=Abi.subtract(bi);
			 b=big.toByteArray();
						}
			 		 }
				else if(Clen[j-k]=='1' && Ach[Alen-1]=='0')
				 {
					  if(Alen==Abi.bitLength())
			 {
					BigInteger bi=new BigInteger("1",2);
			BigInteger big=Abi.add(bi);
			b=big.toByteArray();
			 }
					  else
			 {
					BigInteger bi=new BigInteger("-1",2);
			BigInteger big=Abi.add(bi);
			b=big.toByteArray();
			 }

				 }
	   		   outs.write(B)/>;
				 } // end else

			} // for loop j

		} // end of if

	  else
	   {
		String slen=String.valueOf(chmess[i-1]);
		byte blen[]=slen.getBytes();
		BigInteger Blen=new BigInteger(blen);
		String Slen=Blen.toString(2);
		char Clen[]=new char[Blen.bitLength()];
		Slen.getChars(0,Blen.bitLength(),Clen,0);
		for(int j=0;j<=7;j++)
		 {
		  if(j==0)
		   {
			for(k1=0;k1<8-Blen.bitLength();k1++)
			 {
			  int n=ins.read(B)/>;
			  Abi=new BigInteger(B)/>;
		  String Aby=Abi.toString(2);
			  int Alen=Abi.bitLength();
				  if(b[0]<0)
				  Alen++;
			  char Ach[]=new char[Alen+1];
			  Aby.getChars(0,Alen,Ach,0);
 		if(b[0]==0)
			   {

			   }
		  else
		   {
				  if(Ach[Alen-1]=='1')
				   {
						if(Alen==Abi.bitLength())
						 {
					  BigInteger bi=new BigInteger("11111110",2);
					  BigInteger big=Abi.and(bi);
			  b=big.toByteArray();
						 }
						else
						 {
						BigInteger bi=new BigInteger("-1",2);
					  BigInteger big=Abi.subtract(bi);
			  b=big.toByteArray();
						 }
				   }
		   }
		outs.write(B)/>;

			  }  //for loop k

		j=j+k1-1;

			 } // if of j

		else
		 {
		  int n=ins.read(B)/>;
		   Abi=new BigInteger(B)/>;
			  String Aby=Abi.toString(2);
			  int Alen=Abi.bitLength();
				  if(b[0]<0)
				  Alen++;
			  char Ach[]=new char[Alen+1];
			  Aby.getChars(0,Alen,Ach,0);
			  if(b[0]==0)
			   {
			Alen=1;
			   }

				if(Clen[j-k1]=='0' && Ach[Alen-1]=='1')
				 {
			if(Alen==Abi.bitLength())
 			 {
						BigInteger bi=new BigInteger("11111110",2);
					  BigInteger big=Abi.and(bi);
			  b=big.toByteArray();
						 }
						else
 			 {
						BigInteger bi=new BigInteger("-1",2);
					  BigInteger big=Abi.subtract(bi);
			  b=big.toByteArray();
						 }
				 }
				else if(Clen[j-k1]=='1' && Ach[Alen-1]=='0')
				 {
			if(Alen==Abi.bitLength())
			 {
			   	  BigInteger bi=new BigInteger("1",2);
					  BigInteger big=Abi.add(bi);
			  b=big.toByteArray();
 			 }
			else
			 {
			   	  BigInteger bi=new BigInteger("-1",2);
					  BigInteger big=Abi.add(bi);
			  b=big.toByteArray();
 			 }
				 }
		outs.write(B)/>;
		 } // end else

	   } // for loop j
	 } // end of else

   } // for loop i

  while(true)
   {
	int i=ins.read();
	if(i==-1) break;
	outs.write(i);
   }
	ins.close();
	outs.close();
   }

public void Audiodecrypt(File filename,int key)throws Exception
 {
  InputStream ins=new FileInputStream(filename);
  byte b[]=new byte[1];
  BigInteger bb1;
  char mess[]=new char[8];
  int c=0;
  for(int i=0;i<key;i++)
  {
   int n=ins.read();
  }
  for(int i=0;i<8;i++)
   {
	ins.read(B)/>;
	bb1=new BigInteger(B)/>;
	String str=bb1.toString(2);
	int len=bb1.bitLength();
	if(b[0]<0)
	 len++;
	char ch[]=new char[len+1];
	str.getChars(0,len,ch,0);
	if(b[0]==0)
	 mess[i]='0';
	else
	 mess[i]=ch[len-1];
   }
  String dd=new String(mess);
  BigInteger bb=new BigInteger(dd,2);
  String s=bb.toString(2);
 int l=bb.intValue();

char me[]=new char[l];
int count=0;

for(int m=0;m<l;m++)
 {
for(int i=0;i<8;i++)
   {
	ins.read(B)/>;
	bb1=new BigInteger(B)/>;
	String str=bb1.toString(2);
	int len=bb1.bitLength();
	if(b[0]<0)
	 len++;
	char ch[]=new char[len+1];
	str.getChars(0,len,ch,0);
	if(b[0]==0)
	 mess[i]='0';
	else
	 mess[i]=ch[len-1];
   }
  String dd1=new String(mess);
  BigInteger bb2=new BigInteger(dd1,2);
  String s1=bb2.toString(2);
 int l1=bb2.intValue();
 me[count]=(char)l1;
 count++;
 }

String message=new String(me);
Amessage.setText(message);
ins.close();

 }

  public void actionPerformed(ActionEvent ae)
   {

   try
	{

 // Action for encryption button

	if(ae.getSource()==Bencrypt)
	 {
	  if(Copened==1)
	   {
		Ekey=JOptionPane.showInputDialog("Enter The Key For 
Encryption");
//String type
		if(Ekey.trim().equals(""))
		 JOptionPane.showMessageDialog(this,"Enter the
Key","Error",JOptionPane.ERROR_MESSAGE);
		else
		 {
		  // encrypt the message
		  int key=Integer.parseInt(Ekey);
		  Audioencrypt(Amessage.getText(),Ofilename,key);
		  Cencrypt=1;
		 }
	   }
	  else
	   {
		JOptionPane.showMessageDialog(this,"File Not
Opened","Error",JOptionPane.ERROR_MESSAGE);
	   }
	 } // end of Bencrypt

// Action for Clear button

	else if(ae.getSource()==Bclear)
	 {
	  Amessage.setText("");
	 } // end of clear button

// Action for Decrypt button

	else if(ae.getSource()==Bdecrypt)
	 {
	  if(Copened==1)
	   {
		Dkey=JOptionPane.showInputDialog("Enter The Key For 
Decryption");
//String type
		if(Dkey.trim().equals(""))
		 JOptionPane.showMessageDialog(this,"Enter the
Key","Error",JOptionPane.ERROR_MESSAGE);
		else
		 {
		 // decrypt message
		  int key=Integer.parseInt(Dkey);
		 Audiodecrypt(Ofilename,key);
		 Cdecrypt=1;
		 }
	   }
	  else
	   JOptionPane.showMessageDialog(this,"File Not
Opened","Error",JOptionPane.ERROR_MESSAGE);
	 } // end of Decrypt button

// Action for Play button

	else if(ae.getSource()==Bplay)
	 {
	  if(Copened==1)
	   {

		 ins=new FileInputStream(Ofilename);
		 as=new AudioStream(ins);
		 AudioPlayer.player.start(as);
		 Cplay=1;
		 Cstop=0;

	   } // start playing

	  else
	   JOptionPane.showMessageDialog(this,"File Not
Opened","Error",JOptionPane.ERROR_MESSAGE);

	 } // end of play button



// Action for Stop button

	else if(ae.getSource()==Bstop)
	 {

	  if(Cplay==1)
	   {

		Cplay=0;
		Cstop=1;
		AudioPlayer.player.stop(as);

	   } // stop plaing

	  else

	   JOptionPane.showMessageDialog(this,"No Audio Is
playing","Error",JOptionPane.ERROR_MESSAGE);

	 } // end of stop button



// Action for open Button

	else if(ae.getSource()==Bopen)
	 {
	  int r=filechooser.showOpenDialog(this);
	  tempfilename=filechooser.getSelectedFile(); //File type
	  if(r==JFileChooser.CANCEL_OPTION)
	   JOptionPane.showMessageDialog(this,"File Not
Selected","Error",JOptionPane.ERROR_MESSAGE);
	  else
	   {
		name=tempfilename.getName();

		if(!(name.endsWith(".wav")))

		  JOptionPane.showMessageDialog(this,"Select Only
Wav","Error",JOptionPane.ERROR_MESSAGE);

		else
		  {
			Copened=1;
			Ofilename=tempfilename;
			Tfilename.setEditable(true);
			Tfilename.setText(name);
			Tfilename.setEditable(false);
		   }

		 }
	 }   // end of Open button

// Action for Save Button

	else if(ae.getSource()==Bsave)
	 {
	  if(Copened==1 && Cencrypt==1 || Cdecrypt==1)
	   {
		int r=filechooser.showSaveDialog(this);
		Sfilename=filechooser.getSelectedFile(); //File type
		InputStream in=new FileInputStream("d:\temp.wav");
		OutputStream out=new FileOutputStream(Sfilename);
		Ofilename=Sfilename;
	name=Sfilename.getName();
		Tfilename.setEditable(true);
		Tfilename.setText(name);
		Tfilename.setEditable(false);
		while(true)
		 {
		  int i=in.read();
		  if(i==-1) break;
		  out.write(i);
		 }
	   in.close();
	   out.close();
	   }
	  else
	   {
		String s;
		if(Copened==0)
		 s="File not Opened";
		else if(Cencrypt==0)
		 s="Not Encrypted";
		else
		 s="Not Decrypted";

JOptionPane.showMessageDialog(this,s,"Error",JOptionPane.ERROR_MESSAGE);
	   }
	 } // end of save button

// Action for send button

	else if(ae.getSource()==Bsend)
	 {
	  if(Copened==1 && Cencrypt==1)
	   {
		address=JOptionPane.showInputDialog("Enter The IPaddress");
		ipaddress=InetAddress.getByName(address);
		Socket socket=new Socket(ipaddress,6000);
		OutputStream out=socket.getOutputStream();
		InputStream in=new FileInputStream(Ofilename);
		while(true)
		 {
		  int i=in.read();
		  if(i==-1) break;
		  out.write(i);
		 }
		 in.close();
		 out.close();
	   }
	  else
	   {
		String s;
		if(Copened==1)
		  s="Encryption not done";
		else
		  s="Open the File first";

JOptionPane.showMessageDialog(this,s,"Error",JOptionPane.ERROR_MESSAGE);
	   }
	 }

	} // end try
	catch(Exception e)
	 {
	 //
JOptionPane.showMessageDialog(this,e,"Error",JOptionPane.ERROR_MESSAGE);
	 }

   } // end of actionperformed

 }//end of class


class recv extends JFrame implements Runnable
 {
   JFileChooser fc;
   ServerSocket ss;
   Socket s;
   InputStream ins;
   OutputStream out;
   byte b[];
   int len;

  public recv() throws Exception
	{

	  b=new byte[100];
	  fc=new JFileChooser();
	  fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
	  ss=new ServerSocket(6000);
	  torun();
	}
  public void torun() throws Exception
   {
	  while(true)
	   {
		s=ss.accept();
		ins=s.getInputStream();
		String str="Your have Receive An AudioFile.
Save them";

JOptionPane.showMessageDialog(this,str,"Information",JOptionPane.INFORMATI
ON_MESSAGE);
		int r=fc.showSaveDialog(this);
		File file=fc.getSelectedFile();
		out=new FileOutputStream(file);
		Thread t=new Thread(this);
		t.start();
	   }
	}
   public void run()
	{
	  try
		{
		 while(true)
		  {
		   int n=ins.read();
 	   if(n==-1) break;
		   out.write(n);
		  }
	   //  s.close();
		 ins.close();
		 out.close();
		}
	  catch(Exception e)
		{
		   System.out.println(e);
		}
	} // end of run
 } //end of class




public class techmeet1
 {
  public static void main(String arg[])throws Exception
   {
	mainframe frame=new mainframe();
	frame.setSize(800,600);
	frame.setVisible(true);


	frame.addWindowListener( new WindowAdapter()
	 {
	  public void windowClosing(WindowEvent we)
	   {
		System.exit(0);
	   }
	 });

   } // end of main

 } // end of class


hey siris49
what is B in the code that you have provided.
plz rep fast.

This post has been edited by kartikp: 20 March 2010 - 02:31 AM

Was This Post Helpful? 0
  • +
  • -

#9 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10179
  • View blog
  • Posts: 37,585
  • Joined: 27-December 08

Re: Audio steganography..

Posted 20 March 2010 - 03:27 AM

Is the b you were looking for byte b = new byte[1];?

This post has been edited by macosxnerd101: 20 March 2010 - 03:28 AM

Was This Post Helpful? 0
  • +
  • -

#10 Guest_amit*


Reputation:

Re: Audio steganography..

Posted 06 April 2010 - 01:59 PM

View Postsirish49, on 28 March 2009 - 06:22 AM, said:

View Postdr.cean, on 28 Jan, 2008 - 11:36 AM, said:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import java.util.*;
import sun.audio.*;
import java.applet.*;
import java.math.*;

class mainframe extends JFrame implements ActionListener,Runnable
 {
  JLabel Lfilename,Lmessage,Ldesign,Ltitle;
  JButton Bplay,Bopen,Bsave,Bstop,Bencrypt,Bdecrypt,Bsend,Bclear;
  JTextArea Amessage;
  JTextField Tfilename;
  Icon Iplay,Iopen,Istop,Isave;
  String Ekey,Dkey,address,name;
  JFileChooser filechooser;
  File Ofilename,Sfilename,tempfilename;
  InetAddress ipaddress;
  int Copened,Cencrypt,Cdecrypt,Cplay,Cstop,Csave;
  InputStream ins;
  AudioStream as;
  Thread t;

  public mainframe()throws Exception
   {

	// frame

	super("Swathe 1.0 - Steganography Using Audio");
	Container con=getContentPane();
	con.setLayout(null);

	// Basic

	Copened=0;
	Cencrypt=0;
	Cdecrypt=0;
	Cplay=0;
	Csave=0;
	Cstop=0;

	t=new Thread(this);
	t.start();

	// Icons

	Iplay=new ImageIcon("c:\Icon\play.gif");
	Isave=new ImageIcon("c:\Icon\save.gif");
	Iopen=new ImageIcon("c:\Icon\open.gif");
	Istop=new ImageIcon("c:\Icon\stop1.gif");

	// file chooser

	filechooser=new JFileChooser();
	filechooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

	// comp

	Ltitle=new JLabel("Steganography Using Audio");
	Ldesign=new JLabel("Designed By : M.Dayananthan, D.Langesh,
M.Vanitha");
	Lfilename=new JLabel("File Name ");
	Lmessage=new JLabel("Message  ");
	Bplay=new JButton("",Iplay);
	Bopen=new JButton("",Iopen);
	Bsave=new JButton("",Isave);
	Bstop=new JButton("",Istop);
	Bclear=new JButton("Clear");
	Bencrypt=new JButton("Encoding");
	Bdecrypt=new JButton("Decoding");
	Bsend=new JButton("Send");
	Amessage=new JTextArea();
	Tfilename=new JTextField();

	// tool tips

	Tfilename.setToolTipText("Opened filename");
	Bplay.setToolTipText("play");
	Bopen.setToolTipText("open");
	Bsave.setToolTipText("save");
	Bstop.setToolTipText("stop");

	Tfilename.setEditable(false);

	// Bounds

	Ltitle.setBounds(300,30,250,25);
	Lfilename.setBounds(100,100,100,25);
	Tfilename.setBounds(100,125,230,25);
	Lmessage.setBounds(450,100,100,25);
	Amessage.setBounds(450,125,300,220);
	Bclear.setBounds(450,370,80,22);
	Bplay.setBounds(100,200,50,25);
	Bstop.setBounds(160,200,50,25);
	Bopen.setBounds(220,200,50,25);
	Bsave.setBounds(280,200,50,25);
	Bencrypt.setBounds(100,250,110,25);
	Bdecrypt.setBounds(220,250,110,25);
	Bsend.setBounds(160,300,110,25);
	Ldesign.setBounds(350,420,400,50);


	// add

	con.add(Ltitle);
	con.add(Ldesign);
	con.add(Lfilename);
	con.add(Tfilename);
	con.add(Lmessage);
	con.add(Amessage);
	con.add(Bclear);
	con.add(Bplay);
	con.add(Bopen);
	con.add(Bsave);
	con.add(Bstop);
	con.add(Bencrypt);
	con.add(Bdecrypt);
	con.add(Bsend);

	// actionListener

	Bclear.addActionListener(this);
	Bplay.addActionListener(this);
	Bopen.addActionListener(this);
	Bsave.addActionListener(this);
	Bstop.addActionListener(this);
	Bencrypt.addActionListener(this);
	Bdecrypt.addActionListener(this);
	Bsend.addActionListener(this);

   } // constr of mainframe

  public void run()
   {
	try
	 {
	  recv r=new recv();
	 }
	catch(Exception e)
	 {
	  System.out.println(e);
	 }
   }

  public void Audioencrypt(String message,File file,int key) throws
Exception
   {
	byte b[]=new byte[1];
	BigInteger Abi,Mbi;
	int k,k1;
	InputStream ins=new FileInputStream(file);
	OutputStream outs=new FileOutputStream(new File("d:\temp.wav"));
	for(int c=0;c<key;c++)
	 {
	  int ch=ins.read();
	  outs.write(ch);
	 }
	int len=message.length();
	byte mess[]=new byte[1];
	char chmess[]=new char[len+1];
	k=k1=0;
	for(int i=0;i<=len;i++)
	 {
	  message.getChars(0,len,chmess,0);
	  if(i==0)
	   {
		BigDecimal bd=new BigDecimal(len);
		BigInteger Blen=bd.toBigInteger();
		String Slen=Blen.toString(2);
		char Clen[]=new char[Blen.bitLength()];
		Slen.getChars(0,Blen.bitLength(),Clen,0);
		for(int j=0;j<=7;j++)
		 {
		  if(j==0)
		   {
			for(k=0;k<8-Blen.bitLength();k++)
			 {
			  int n=ins.read(B)/>;
			  Abi=new BigInteger(B)/>;
			  String Aby=Abi.toString(2);
			  int Alen=Abi.bitLength();
			  if(b[0]<0)
				Alen++;
			  char Ach[]=new char[Alen+1];
			  Aby.getChars(0,Alen,Ach,0);

		  if(b[0]==0)
		   {
		   }
		  else
		   {
			  if(Ach[Alen-1]=='1')
			   {
				if(Alen==Abi.bitLength())
		 {
				  BigInteger bi=new BigInteger("11111110",2);
				  BigInteger big=Abi.and(bi);
		  b=big.toByteArray();
		 }
 		else
		 {
						BigInteger bi=new BigInteger("-1",2);
					  BigInteger big=Abi.subtract(bi);
		  b=big.toByteArray();
		 }
			   }
		outs.write(B)/>;
			 }
		   }  //for loop k
		 j=j+k-1;
		 } // if of j
			else
			 {
			  int n=ins.read(B)/>;
			  Abi=new BigInteger(B)/>;
			  String Aby=Abi.toString(2);
			  int Alen=Abi.bitLength();
				  if(b[0]<0)
				  Alen++;
			  char Ach[]=new char[Alen+1];
			  Aby.getChars(0,Alen,Ach,0);
			 if(b[0]==0)
			  {
				   Alen=1;
			  }
				if(Clen[j-k]=='0' && Ach[Alen-1]=='1')
				 {
					   if(Alen==Abi.bitLength())
						{
				 	 BigInteger bi=new BigInteger("11111110",2);
					 BigInteger big=Abi.and(bi);
			 b=big.toByteArray();
						}
					   else
						{
						BigInteger bi=new BigInteger("-1",2);
					  BigInteger big=Abi.subtract(bi);
			 b=big.toByteArray();
						}
			 		 }
				else if(Clen[j-k]=='1' && Ach[Alen-1]=='0')
				 {
					  if(Alen==Abi.bitLength())
			 {
					BigInteger bi=new BigInteger("1",2);
			BigInteger big=Abi.add(bi);
			b=big.toByteArray();
			 }
					  else
			 {
					BigInteger bi=new BigInteger("-1",2);
			BigInteger big=Abi.add(bi);
			b=big.toByteArray();
			 }

				 }
	   		   outs.write(B)/>;
				 } // end else

			} // for loop j

		} // end of if

	  else
	   {
		String slen=String.valueOf(chmess[i-1]);
		byte blen[]=slen.getBytes();
		BigInteger Blen=new BigInteger(blen);
		String Slen=Blen.toString(2);
		char Clen[]=new char[Blen.bitLength()];
		Slen.getChars(0,Blen.bitLength(),Clen,0);
		for(int j=0;j<=7;j++)
		 {
		  if(j==0)
		   {
			for(k1=0;k1<8-Blen.bitLength();k1++)
			 {
			  int n=ins.read(B)/>;
			  Abi=new BigInteger(B)/>;
		  String Aby=Abi.toString(2);
			  int Alen=Abi.bitLength();
				  if(b[0]<0)
				  Alen++;
			  char Ach[]=new char[Alen+1];
			  Aby.getChars(0,Alen,Ach,0);
 		if(b[0]==0)
			   {

			   }
		  else
		   {
				  if(Ach[Alen-1]=='1')
				   {
						if(Alen==Abi.bitLength())
						 {
					  BigInteger bi=new BigInteger("11111110",2);
					  BigInteger big=Abi.and(bi);
			  b=big.toByteArray();
						 }
						else
						 {
						BigInteger bi=new BigInteger("-1",2);
					  BigInteger big=Abi.subtract(bi);
			  b=big.toByteArray();
						 }
				   }
		   }
		outs.write(B)/>;

			  }  //for loop k

		j=j+k1-1;

			 } // if of j

		else
		 {
		  int n=ins.read(B)/>;
		   Abi=new BigInteger(B)/>;
			  String Aby=Abi.toString(2);
			  int Alen=Abi.bitLength();
				  if(b[0]<0)
				  Alen++;
			  char Ach[]=new char[Alen+1];
			  Aby.getChars(0,Alen,Ach,0);
			  if(b[0]==0)
			   {
			Alen=1;
			   }

				if(Clen[j-k1]=='0' && Ach[Alen-1]=='1')
				 {
			if(Alen==Abi.bitLength())
 			 {
						BigInteger bi=new BigInteger("11111110",2);
					  BigInteger big=Abi.and(bi);
			  b=big.toByteArray();
						 }
						else
 			 {
						BigInteger bi=new BigInteger("-1",2);
					  BigInteger big=Abi.subtract(bi);
			  b=big.toByteArray();
						 }
				 }
				else if(Clen[j-k1]=='1' && Ach[Alen-1]=='0')
				 {
			if(Alen==Abi.bitLength())
			 {
			   	  BigInteger bi=new BigInteger("1",2);
					  BigInteger big=Abi.add(bi);
			  b=big.toByteArray();
 			 }
			else
			 {
			   	  BigInteger bi=new BigInteger("-1",2);
					  BigInteger big=Abi.add(bi);
			  b=big.toByteArray();
 			 }
				 }
		outs.write(B)/>;
		 } // end else

	   } // for loop j
	 } // end of else

   } // for loop i

  while(true)
   {
	int i=ins.read();
	if(i==-1) break;
	outs.write(i);
   }
	ins.close();
	outs.close();
   }

public void Audiodecrypt(File filename,int key)throws Exception
 {
  InputStream ins=new FileInputStream(filename);
  byte b[]=new byte[1];
  BigInteger bb1;
  char mess[]=new char[8];
  int c=0;
  for(int i=0;i<key;i++)
  {
   int n=ins.read();
  }
  for(int i=0;i<8;i++)
   {
	ins.read(B)/>;
	bb1=new BigInteger(B)/>;
	String str=bb1.toString(2);
	int len=bb1.bitLength();
	if(b[0]<0)
	 len++;
	char ch[]=new char[len+1];
	str.getChars(0,len,ch,0);
	if(b[0]==0)
	 mess[i]='0';
	else
	 mess[i]=ch[len-1];
   }
  String dd=new String(mess);
  BigInteger bb=new BigInteger(dd,2);
  String s=bb.toString(2);
 int l=bb.intValue();

char me[]=new char[l];
int count=0;

for(int m=0;m<l;m++)
 {
for(int i=0;i<8;i++)
   {
	ins.read(B)/>;
	bb1=new BigInteger(B)/>;
	String str=bb1.toString(2);
	int len=bb1.bitLength();
	if(b[0]<0)
	 len++;
	char ch[]=new char[len+1];
	str.getChars(0,len,ch,0);
	if(b[0]==0)
	 mess[i]='0';
	else
	 mess[i]=ch[len-1];
   }
  String dd1=new String(mess);
  BigInteger bb2=new BigInteger(dd1,2);
  String s1=bb2.toString(2);
 int l1=bb2.intValue();
 me[count]=(char)l1;
 count++;
 }

String message=new String(me);
Amessage.setText(message);
ins.close();

 }

  public void actionPerformed(ActionEvent ae)
   {

   try
	{

 // Action for encryption button

	if(ae.getSource()==Bencrypt)
	 {
	  if(Copened==1)
	   {
		Ekey=JOptionPane.showInputDialog("Enter The Key For 
Encryption");
//String type
		if(Ekey.trim().equals(""))
		 JOptionPane.showMessageDialog(this,"Enter the
Key","Error",JOptionPane.ERROR_MESSAGE);
		else
		 {
		  // encrypt the message
		  int key=Integer.parseInt(Ekey);
		  Audioencrypt(Amessage.getText(),Ofilename,key);
		  Cencrypt=1;
		 }
	   }
	  else
	   {
		JOptionPane.showMessageDialog(this,"File Not
Opened","Error",JOptionPane.ERROR_MESSAGE);
	   }
	 } // end of Bencrypt

// Action for Clear button

	else if(ae.getSource()==Bclear)
	 {
	  Amessage.setText("");
	 } // end of clear button

// Action for Decrypt button

	else if(ae.getSource()==Bdecrypt)
	 {
	  if(Copened==1)
	   {
		Dkey=JOptionPane.showInputDialog("Enter The Key For 
Decryption");
//String type
		if(Dkey.trim().equals(""))
		 JOptionPane.showMessageDialog(this,"Enter the
Key","Error",JOptionPane.ERROR_MESSAGE);
		else
		 {
		 // decrypt message
		  int key=Integer.parseInt(Dkey);
		 Audiodecrypt(Ofilename,key);
		 Cdecrypt=1;
		 }
	   }
	  else
	   JOptionPane.showMessageDialog(this,"File Not
Opened","Error",JOptionPane.ERROR_MESSAGE);
	 } // end of Decrypt button

// Action for Play button

	else if(ae.getSource()==Bplay)
	 {
	  if(Copened==1)
	   {

		 ins=new FileInputStream(Ofilename);
		 as=new AudioStream(ins);
		 AudioPlayer.player.start(as);
		 Cplay=1;
		 Cstop=0;

	   } // start playing

	  else
	   JOptionPane.showMessageDialog(this,"File Not
Opened","Error",JOptionPane.ERROR_MESSAGE);

	 } // end of play button



// Action for Stop button

	else if(ae.getSource()==Bstop)
	 {

	  if(Cplay==1)
	   {

		Cplay=0;
		Cstop=1;
		AudioPlayer.player.stop(as);

	   } // stop plaing

	  else

	   JOptionPane.showMessageDialog(this,"No Audio Is
playing","Error",JOptionPane.ERROR_MESSAGE);

	 } // end of stop button



// Action for open Button

	else if(ae.getSource()==Bopen)
	 {
	  int r=filechooser.showOpenDialog(this);
	  tempfilename=filechooser.getSelectedFile(); //File type
	  if(r==JFileChooser.CANCEL_OPTION)
	   JOptionPane.showMessageDialog(this,"File Not
Selected","Error",JOptionPane.ERROR_MESSAGE);
	  else
	   {
		name=tempfilename.getName();

		if(!(name.endsWith(".wav")))

		  JOptionPane.showMessageDialog(this,"Select Only
Wav","Error",JOptionPane.ERROR_MESSAGE);

		else
		  {
			Copened=1;
			Ofilename=tempfilename;
			Tfilename.setEditable(true);
			Tfilename.setText(name);
			Tfilename.setEditable(false);
		   }

		 }
	 }   // end of Open button

// Action for Save Button

	else if(ae.getSource()==Bsave)
	 {
	  if(Copened==1 && Cencrypt==1 || Cdecrypt==1)
	   {
		int r=filechooser.showSaveDialog(this);
		Sfilename=filechooser.getSelectedFile(); //File type
		InputStream in=new FileInputStream("d:\temp.wav");
		OutputStream out=new FileOutputStream(Sfilename);
		Ofilename=Sfilename;
	name=Sfilename.getName();
		Tfilename.setEditable(true);
		Tfilename.setText(name);
		Tfilename.setEditable(false);
		while(true)
		 {
		  int i=in.read();
		  if(i==-1) break;
		  out.write(i);
		 }
	   in.close();
	   out.close();
	   }
	  else
	   {
		String s;
		if(Copened==0)
		 s="File not Opened";
		else if(Cencrypt==0)
		 s="Not Encrypted";
		else
		 s="Not Decrypted";

JOptionPane.showMessageDialog(this,s,"Error",JOptionPane.ERROR_MESSAGE);
	   }
	 } // end of save button

// Action for send button

	else if(ae.getSource()==Bsend)
	 {
	  if(Copened==1 && Cencrypt==1)
	   {
		address=JOptionPane.showInputDialog("Enter The IPaddress");
		ipaddress=InetAddress.getByName(address);
		Socket socket=new Socket(ipaddress,6000);
		OutputStream out=socket.getOutputStream();
		InputStream in=new FileInputStream(Ofilename);
		while(true)
		 {
		  int i=in.read();
		  if(i==-1) break;
		  out.write(i);
		 }
		 in.close();
		 out.close();
	   }
	  else
	   {
		String s;
		if(Copened==1)
		  s="Encryption not done";
		else
		  s="Open the File first";

JOptionPane.showMessageDialog(this,s,"Error",JOptionPane.ERROR_MESSAGE);
	   }
	 }

	} // end try
	catch(Exception e)
	 {
	 //
JOptionPane.showMessageDialog(this,e,"Error",JOptionPane.ERROR_MESSAGE);
	 }

   } // end of actionperformed

 }//end of class


class recv extends JFrame implements Runnable
 {
   JFileChooser fc;
   ServerSocket ss;
   Socket s;
   InputStream ins;
   OutputStream out;
   byte b[];
   int len;

  public recv() throws Exception
	{

	  b=new byte[100];
	  fc=new JFileChooser();
	  fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
	  ss=new ServerSocket(6000);
	  torun();
	}
  public void torun() throws Exception
   {
	  while(true)
	   {
		s=ss.accept();
		ins=s.getInputStream();
		String str="Your have Receive An AudioFile.
Save them";

JOptionPane.showMessageDialog(this,str,"Information",JOptionPane.INFORMATI
ON_MESSAGE);
		int r=fc.showSaveDialog(this);
		File file=fc.getSelectedFile();
		out=new FileOutputStream(file);
		Thread t=new Thread(this);
		t.start();
	   }
	}
   public void run()
	{
	  try
		{
		 while(true)
		  {
		   int n=ins.read();
 	   if(n==-1) break;
		   out.write(n);
		  }
	   //  s.close();
		 ins.close();
		 out.close();
		}
	  catch(Exception e)
		{
		   System.out.println(e);
		}
	} // end of run
 } //end of class




public class techmeet1
 {
  public static void main(String arg[])throws Exception
   {
	mainframe frame=new mainframe();
	frame.setSize(800,600);
	frame.setVisible(true);


	frame.addWindowListener( new WindowAdapter()
	 {
	  public void windowClosing(WindowEvent we)
	   {
		System.exit(0);
	   }
	 });

   } // end of main

 } // end of class

Was This Post Helpful? 0

#11 Guest_amit*


Reputation:

Re: Audio steganography..

Posted 06 April 2010 - 02:10 PM

whenevr i run this code

4 warnings appear that AudioPlayer is SUN proprietary and may be removed in the future release..
after that when the window appears ,i click on the encoding button then it prompts to enter the key for encryption.
but as soon as i enter the key ,a message appears

"java.io.filenotfoundexception :D:temp.wav, incorrect synyaxor filename in the directory could not be found"

can anyone help me with this

thanking u in advance..
reply me at *************

Edited by Dogstopper: Don't do emails here sorry.

This post has been edited by Dogstopper: 06 April 2010 - 02:20 PM

Was This Post Helpful? 0

#12 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2857
  • View blog
  • Posts: 10,960
  • Joined: 15-July 08

Re: Audio steganography..

Posted 06 April 2010 - 02:21 PM

This topic has gone on far too long with no effort. I'm going to close it so that it can die naturally.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1