📄 steganongrapy using audio ( project ).txt
字号:
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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -