Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Home
package dynamic;
import java.io.*;
import java.nio.ByteBuffer;
import java.util.zip.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
/*** Header description: *** In bytes: (4)+ 3+ 1+ 1+ 4= 2+ 9 Bytes. (*4 -
for every 1 byte in () as every 4 bytes of of master file contain 2 bits)
* 3 bytes indicate the version of the software used to embed message eg. 2 0 0
* 1 Byte1 (4 actual bits) incicates features used which include file Compression,
Encryption, Message/File
***/
private Steganograph()
return message;
{
if(msg==null)
return false;
if(msg.length()<1)
return false;
return false;
messageSize= msg.length();
if(compression!= -1)
if(compression< 0) compression= 0;
if(compression>9) compression= 9;
}
else
try
messageSize= messageArray.length;
in.read(byteArrayIn, 0, inputFileSize);
in.close();
masterExtension= fileName.substring(fileName.length()-3,
fileName.length());
if(masterExtension.equalsIgnoreCase("jpg"))
{
// Skip past OFFSET_JPG bytes
byteOut.write(byteArrayIn, 0, OFFSET_JPG);
inputOutputMarker= OFFSET_JPG;
else if(masterExtension.equalsIgnoreCase("png"))
byteOut.write(byteArrayIn, 0,
OFFSET_PNG);
inputOutputMarker= OFFSET_PNG;
else
byteOut.write(byteArrayIn, 0,
OFFSET_GIF_BMP_TIF);
inputOutputMarker=
OFFSET_GIF_BMP_TIF;
tempInt= inputFileSize;
tempInt>>= i;
tempInt&= 0x000000FF;
}
// Embed 4 byte input File size array into the master file
embedBytes(tempByte);
inputOutputMarker= inputFileSize;
writeBytes(VERSION_BYTE);
writeBytes(new byte[]{features});
zOut.setLevel(compression);
zOut.putNextEntry(entry);
zOut.write(messageArray, 0, messageSize);
zOut.closeEntry();
zOut.finish();
zOut.close();
// Get the compressed message byte array
messageArray= arrayOutputStream.toByteArray();
compressionRatio= (short)
((double)messageArray.length / (double)messageSize * 100.0);
messageSize= messageArray.length;
cipher.init(Cipher.ENCRYPT_MODE, spec);
messageArray= cipher.doFinal(messageArray);
messageSize= messageArray.length;
tempInt= messageSize;
tempInt>>= i;
tempInt&= 0x000000FF;
writeBytes(tempByte);
writeBytes(messageArray);
//out.write(byteArrayOut, 0, byteArrayOut.length);
byteOut.writeTo(out);
out.close();
catch(EOFException e)
catch(Exception e)
e.printStackTrace();
return false;
return true;
}
// Retrieves an embedded message from a Master file
features= info.getFeatures();
try
masterFile= info.getFile();
in.read(byteArrayIn, 0, (int)masterFile.length());
in.close();
messageSize= info.getDataLength();
if(messageSize<=0)
return("#FAILED#");
inputOutputMarker= info.getInputMarker();
readBytes(messageArray);
//Decrypt the message if required
cipher= Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE, spec);
try
messageArray= cipher.doFinal(messageArray);
catch(Exception bp)
bp.printStackTrace();
return "#FAILED#";
messageSize= messageArray.length;
zipIn.getNextEntry();
out.write(byteArrayIn, 0, tempInt);
zipIn.close();
out.close();
messageArray= by.toByteArray();
messageSize= messageArray.length;
messg= new
String(SteganoInformation.byteToCharArray(messageArray));
catch(Exception e)
e.printStackTrace();
return("#FAILED#");
return messg;
return false;
if(compression!= 0)
if(compression< 0) compression= 0;
if(compression>9) compression= 9;
else
try
{
in.read(byteArrayIn, 0, inputFileSize);
in.close();
masterExtension= fileName.substring(fileName.length()-3,
fileName.length());
if(masterExtension.equalsIgnoreCase("jpg"))
byteOut.write(byteArrayIn, 0, OFFSET_JPG);
inputOutputMarker= OFFSET_JPG;
else if(masterExtension.equalsIgnoreCase("png"))
byteOut.write(byteArrayIn, 0,
OFFSET_PNG);
inputOutputMarker= OFFSET_PNG;
}
else
byteOut.write(byteArrayIn, 0,
OFFSET_GIF_BMP_TIF);
inputOutputMarker=
OFFSET_GIF_BMP_TIF;
tempInt= inputFileSize;
tempInt>>= i;
tempInt&= 0x000000FF;
// Embed 4 byte input File size array into the master file
embedBytes(tempByte);
inputOutputMarker= inputFileSize;
writeBytes(VERSION_BYTE);
// Write 1 byte for features
writeBytes(new byte[]{features});
in.read(fileArray, 0, messageSize);
in.close();
zOut.setLevel(compression);
zOut.putNextEntry(entry);
zOut.write(fileArray, 0, messageSize);
zOut.closeEntry();
zOut.finish();
zOut.close();
fileArray= arrayOutputStream.toByteArray();
cipher.init(Cipher.ENCRYPT_MODE, spec);
fileArray= cipher.doFinal(fileArray);
messageSize= fileArray.length;
tempInt= messageSize;
tempInt>>= i;
tempInt&= 0x000000FF;
writeBytes(tempByte);
// Embed the message
writeBytes(fileArray);
byteOut.writeTo(out);
out.close();
catch(EOFException e)
catch(Exception e)
e.printStackTrace();
return false;
return true;
try
masterFile= info.getFile();
in.read(byteArrayIn, 0, (int)masterFile.length());
in.close();
messageSize= info.getDataLength();
inputOutputMarker= info.getInputMarker();
readBytes(fileArray);
if(messageSize<=0)
return false;
cipher= Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE, spec);
try
fileArray= cipher.doFinal(fileArray);
catch(Exception bp)
bp.printStackTrace();
return false;
messageSize= fileArray.length;
out.write(byteArrayIn, 0, tempInt);
zipIn.close();
out.close();
fileArray= by.toByteArray();
messageSize= fileArray.length;
info.setDataFile(dataFile);
return false;
out.write(fileArray, 0, fileArray.length);
out.close();
catch(Exception e)
e.printStackTrace();
return false;
}
message= "Retrieved file size: "+ messageSize+ " B";
return true;
byte1= bytes[i];
byte2= byte1;
byte2>>= j;
byte2&= 0x03;
byte3= byteArrayIn[inputOutputMarker];
byte3&= 0xFC;
byte3|= byte2;
byteOut.write(byte3);
inputOutputMarker++;
byteOut.write(bytes[i]);
inputOutputMarker++;
byte1= 0;
byte2= byteArrayIn[inputOutputMarker];
inputOutputMarker++;
byte2&= 0x03;
byte2<<= j;
byte1|= byte2;
}
bytes[i]= byte1;
bytes[i]= byteArrayIn[inputOutputMarker];
inputOutputMarker++;
about.setDisplayed(true);
SwingUtilities.updateComponentTreeUI(about);
{
new HTMLFrame("file:"+ System.getProperty("user.dir") +
System.getProperty("file.separator") +
"help.html", false);
//*********************************************************************//
public AboutFrame()
filler1= new JLabel(" "); filler2= new JLabel(" "); filler3= new
JLabel(" ");
if(new File("Images/About").exists())
else
btnVisit.addActionListener(this);
btnHelp.addActionListener(this);
btnClose.addActionListener(this);
btnComments.addActionListener(this);
panelAbout.setBackground(BLACK);
panelAbout.setForeground(GREEN);
panelAbout.setLayout(gbl);;
gbc.anchor= GridBagConstraints.CENTER;
gbc.weightx= 2;
gbc.weighty= 2;
gbc.gridx= 1; gbc.gridy= 1;
gbl.setConstraints(lblTitle, gbc);
panelAbout.add(lblTitle);
panelAbout.add(filler1);
panelAbout.add(lblName);
panelAbout.add(filler2);
panelAbout.add(lblEmail);
panelAbout.add(filler3);
panelAbout.add(lblPhone);
panelAbout=
UtilityOperations.createBorderedPanel(panelAbout, "About Steganograph", 3, 3);
panelUpper.setBackground(BLACK);
panelUpper.setLayout(new FlowLayout());
panelUpper.add(lblImage);
panelUpper.add(panelAbout);
panelButtons.setLayout(new FlowLayout());
panelButtons.setBackground(Color.black);
panelButtons.add(btnComments);
panelButtons.add(btnHelp);
panelButtons.add(btnClose);
mainPanel.setBackground(Color.black);
mainPanel.setLayout(gbl);
gbc.gridx= 1; gbc.gridy= 1;
gbl.setConstraints(panelUpper, gbc);
mainPanel.add(panelUpper);
mainPanel.add(panelButtons);
mainPanel=
UtilityOperations.createBorderedPanel(mainPanel, 3, 2);
setContentPane(mainPanel);
Dimension d= Toolkit.getDefaultToolkit().getScreenSize();
setSize(width, height);
setResizable(false);
}
public void setDisplayed(boolean choice)
setVisible(choice);
if(e.getSource()== btnVisit)
if(e.getSource()== btnHelp)
new HTMLFrame("file:"+
System.getProperty("user.dir") +
System.getProperty("file.separator") +
"help.html", false);
if(e.getSource()== btnComments)
new
HTMLFrame("http://mujeeb.addr.com/comments.html", true);
if(e.getSource()== btnClose)
setVisible(false);
// Accessor methods
// Mutator methods
this.dataFile= dataFile;
}
byteArray= array;
inputMarker= marker;
byte1= 0;
byte2= byteArray[inputMarker];
inputMarker++;
byte2&= 0x03;
byte2<<= j;
byte1|= byte2;
bytes[i]= byte1;
byte1= 0;
byte2= byteArray[inputMarker];
inputMarker++;
byte2&= 0x03;
byte2<<= j;
byte1|= byte2;
bytes[i]= byte1;
byteArray= array;
inputMarker= marker;
bytes[i]= byteArray[inputMarker];
inputMarker++;
}
}
bytes[i]= byteArray[inputMarker];
inputMarker++;
bytes[i]&= 0x7F;
return chars;
this.file= file;
isEster= false;
if(!file.exists())
starter= null;
return;
if(file.getName().equals("Sec#x&y"))
isEster= true;
return;
try
in.close();
catch(Exception e)
starter= null;
return;
if(fileExtension.equalsIgnoreCase("jpg"))
inputMarker= Steganograph.OFFSET_JPG;
else if(fileExtension.equalsIgnoreCase("png"))
inputMarker= Steganograph.OFFSET_PNG;
else
inputMarker= Steganograph.OFFSET_GIF_BMP_TIF;
dataLength= 0;
temp= name[j];
temp&= 0x000000FF;
temp<<= i;
dataLength|= temp;
inputMarker= dataLength;
if(dataLength<0 || dataLength>file.length())
starter= "Invalid";
return;
}
else
starter= "MUJEEB";
else
ver[i]= versionTemp[j++];
readBytes(name);
features= name[0];
readBytes(name);
name[0]&= 0x7F;
compressionRatio= name[0];
readBytes(name);
dataLength= 0;
temp= name[j];
temp&= 0x000000FF;
temp<<= i;
dataLength|= temp;
if(starter.equals("MUJEEB"))
return true;
else
return false;
JEditorPane editorPane;
JScrollPane scrollPane;
public HTMLFrame(String startURL, boolean isOnline)
editorPane.setEditable(false);
if(isOnline)
editorPane.setBackground(Color.white);
//else
// editorPane.setBackground(Color.black);
editorPane.addHyperlinkListener(this);
try
editorPane.setPage(startURL);
getContentPane().add(scrollPane);
catch(Exception e)
return;
Dimension d= Toolkit.getDefaultToolkit().getScreenSize();
setSize(d.width, d.height);
setVisible(true);
if(e.getEventType()== HyperlinkEvent.EventType.ACTIVATED)
try
editorPane.setPage(e.getURL());
catch(Exception ex)
JOptionPane.showMessageDialog(this, "Oops!!
Error\n"+ ex, "Error", JOptionPane.WARNING_MESSAGE);
}
AES & DES
package dynamic;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.crypto.*;
import javax.crypto.spec.*;
this.client= client;
this.operation= operation;
fileChooser.setFileSelectionMode(fileChooser.FILES_ONLY);
fileChooser.setDialogType(fileChooser.CUSTOM_DIALOG);
//fileChooser.setFileView(fileView);
fileChooser.setAccessory(new FilePreviewer(fileChooser));
fileChooser.addChoosableFileFilter(filter1);
fileChooser.addChoosableFileFilter(filter2);
fileChooser.addChoosableFileFilter(filter3);
if(!chooseMasterFile()) return;
if(!chooseOutputFile()) return;
if(operation== EMBED_FILE)
if(!chooseDataFile()) return;
SteganoInformation steg;
switch(operation)
case RETRIEVE_MESSAGE:
if(steg.isEster())
showEster(steg);
else
if(!steg.isValid())
JOptionPane.showMessageDialog(null,
"File '"+ masterFile.getName()+
else
new PreRetrieveGUI(steg,
PreRetrieveGUI.RETRIEVE_MESSAGE);
break;
case RETRIEVE_FILE:
if(steg.isEster())
showEster(steg);
else
if(!steg.isValid())
JOptionPane.showMessageDialog(null,
"File '"+ masterFile.getName()+
else
new PreRetrieveGUI(steg,
PreRetrieveGUI.RETRIEVE_FILE);
int result;
do
if(result== fileChooser.APPROVE_OPTION)
masterFile= fileChooser.getSelectedFile();
if(!checkFileExistency(masterFile))
continue;
else
break;
} while(result!= fileChooser.CANCEL_OPTION);
int result;
do
if(result== fileChooser.APPROVE_OPTION)
outputFile= fileChooser.getSelectedFile();
if(outputFile.exists())
if(result2== JOptionPane.NO_OPTION)
if(previousFile!= null)
fileChooser.setSelectedFile(previousFile);
continue;
break;
}
} while(result!= fileChooser.CANCEL_OPTION);
do
if(result== fileChooser.APPROVE_OPTION)
dataFile= fileChooser.getSelectedFile();
if(!checkFileExistency(dataFile))
continue;
else
break;
} while(result!= fileChooser.CANCEL_OPTION);
}
// Accessor methods
// Mutator methods
if(!file.exists())
return false;
return true;
message[2]= pass;
, JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
if(result== 1) return;
if(password.length()<8)
else
try
{
DataInputStream in= new DataInputStream(new
FileInputStream(steg.getFile()));
in.read(byteArray, 0, fileSize);
in.close();
cipher.init(Cipher.DECRYPT_MODE, new
SecretKeySpec(password.substring(0, 8).getBytes(), "DES"));
byteArray= cipher.doFinal(byteArray);
catch(Exception e) { return; }
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setBackground(Color.white);
Dimension d= Toolkit.getDefaultToolkit().getScreenSize();
frame.setSize(d.width, d.height/2);
frame.setVisible(true);