Minim
Minim
For the partial fulfillment of the requirements for the award of the degree of Master of
Computer Application affiliated to University of Madras.
By
J.DHINESH KUMAR
SC80124
1
Velammal College of Management and Computer Studies
Velammal Nagar , Chennai – 600 066
BONAFIDE CERTIFICATE
Certified that this project report titled “Video Steganography” is the bonafide work of
J.Dhinesh Kumar Register No: - SC80124 who carried out the project work under my
supervision. Certified further, that to the best of my knowledge the work reported herein does
not form part of any other project report or dissertation on the basis of which a degree or
award was conferred on an earlier occasion on this or any other candidate.
2
ACKNOWLEDGEMENT
I would like to thank Mrs. G. SAVITHRI MCA, M.Phil. (Ph.D.), Senior Lecturer
my internal guides for her valuable guidance, advice and encouragement for the successful
completion of this project.
I also extend my sincere thanks to my friends, and my parents for their support and
guidance for the successful completion of the project. I would also like to thank all the
teaching and non-teaching staff of our M.C.A Department for their helpful attitude.
J.DHINESH KUMAR
(Reg.No:SC80124)
3
DECLARATION
Date: (Reg.No:SC80124)
4
CONTENT
1. INTRODUCTION
2 SYSTEM CONFIGURATION
3 PROJECT DESIGN
4 MODULES
4.1 ENCODE 9
4.2 DECODE
10
5 PROGRAM CODE 11
6 SCREEN LAYOUTS 46
7 CONCLUSION 57
8 BIBLIOGRAPHY 58
CHAPTER I
5
INTRODUCTION
1.1PROJECT DESCRIPTION:-
Video Steganography is a technique to hide any type of files and messages
into a carrying a file. The carrying file should be a video file. In this application two modules
are Encode and Decode. In this Encode module there are two different types available,
Encode with message and another one is Encode with file. In this Encode with message will
accept the four different types of video file formats. Those formats are “.mpg” , “.mkv” ,
“.flv” , “.mpeg”. For other files it will shown the error message. In the save option the user
can save file with same extension and any directory. If it’s in the same directory and same
name means it will show error message. In this Encode with file option it will accept only the
“.mpeg”. In the hidden file can be any format like “.txt” , “.doc”, ”.docx” and “.wav” ,
”.wmv”. In the save options save with same extension as input. The hidden file should be
encoded with original file name.
In the Decode modules also having two types, those are Decode the message
and another one is decoding file. In this decode the message it will check when the user
select the file it should end with any of the four formats video file. If it’s not in those formats
it will shown the error message. The video file should be check and tell the message hidden
in that video files. If it’s not containing any message means it will show the error message as
no hidden message are in that video file. Otherwise it will display the hidden message in that
text area. In the Decode with file it will check the file’s end’s with “.mpeg” and accepts the
input. Otherwise it show error message. After the file selected retrieve button press then
automatically it will fetch the file from video and saved in the same directory where the
application located. If it’s not containing any files mean it show error message.
In this application is useful for very secure communication with video files.
The file or message can’t view for third party.
CHAPTER-II
6
SYSTEM CONFIGURATION
MEMORY : 1 GB RAM
CHAPTER – III
7
PROJECT DESIGN
ENCODE DECODE
MESSAG
MESSAGE FILE FILE
E
RETRIVE RETRIVE
SELECT HIDE FILE
SAVE
VIDEO
DISPLAY MESSAGE
SAVE
VIDEO
ENTER MESSAGE
EMBEDED EMBEDED
STOP
MESSAGE FILE
MESSAGE FILE
SELECT SELECT
SELECT SELECT THE
THE
THE THE VIDEO
VIDEO
VIDEO VIDEO
SAVE THE
ENTER THE Save video file DISPLAY THE
MESSAGE MESSAGE FILE
SELECT SELECT
EMBEDED EMBEDED
CHAPTER – IV
MODULE DESCRIPTION
4.1 ENCODE:-
In this module the application contains two options one is encode with
message and another one is encode with file. In this encode with message we can select
the different types of video formats like “.mpg”, “.mkv”, “.flv”, “.mpeg”. It can be any
directory of hard drives. It selected by the user to hide message in that particular video
file. The video file is now called as “carrying file” because it’s contains the hidden
9
message. The video file should not harm. It should be play after the message to be
inserted. In that way only the message will be appended to that video file. In that we are
shifting the bytes of message into video file. In this application user must select the
carrying file should be saved. That in the same directory as input video means user
should give the different name and also the same extension. Otherwise it will show the
error message. After the message typed by the user embedded button should be pressed.
When the embedded button pressed encodes will start. Automatically it will create a new
file in the user specified location. That file is the carrying file should contain user hidden
message.
In this encode modules another one is encode with file option. In this the
application supports only one type of video file that’s “.mpeg”. In this also video file
should be selected by the user in the hard drive. It will reject input when the other type of
video files selected. In this also user selected the output file where to be saved. This also
gives error message when the extensions are different from input file. Also shows the
error message when the name is same as input and a saved in same directory. In this
hidden file also user should be selected. This can be in any formats like
“.txt” ,”.doc” ,”.jpg” ,”.wav” and etc.,. The output file should be play after the file to
insert. In this the file will inserted as same name and its content also should be encoded
into the original video file. these are all should be done with help of this application.
4.2 DECODE:-
In this module the application contains two types of decode one is decode
with message and another one is decode the file. In this decode with message user select
the video file from the source. It may be in hard drives or DVD’s or pen drives. First it
will check the file in the following formats or not. If the files are
“.mpeg” ,”mkv” ,”.flv” ,”.mpg” then only it will accept. Otherwise it show error message.
After selecting the video file the decode button is pressed. When the file contains
message it will be displayed in the text area. Otherwise it will show the message “The file
does not contain any messages”.
10
In decode the file options first it will check the file end’s with “.mpeg” or
not. If it’s not “.mpeg” files mean it shows error message. If the file should “.mpeg”
means it will accept the input. After the retrieve button pressed the hidden file should be
retrieved from that video file. First it will get the hidden file name and then it will create
the data output stream for that hidden file. That file content also retrieved from that video
file and then it will buffered into the data output stream. It will be write the file up to the
end of the original hidden file. Then it will finish the write operation and close that file.
The file should be saved in the same directory where the application is located. If that
video file should not contain any message means it will be shown the message like” The
file does not contain any hidden files” After the file retrieved from that video file. The
video file should contain messages. That should not be deleted from that video file.
CHAPTER – V
5. PROGRAM CODE:-
// MiniprojectApp.java
package miniproject;
import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;
public class MiniprojectApp extends SingleFrameApplication {
@Override protected void startup() {
show(new MiniprojectView(this));
}
@Override protected void configureWindow(java.awt.Window root) {
11
}
public static MiniprojectApp getApplication() {
return Application.getInstance(MiniprojectApp.class);
}
public static void main(String[] args) {
launch(MiniprojectApp.class, args);
}
}
// MiniprojectView.java
package miniproject;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
public class MiniprojectView extends FrameView {
public MiniprojectView(SingleFrameApplication app) {
super(app);
initComponents();
ResourceMap resourceMap = getResourceMap();
int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
messageTimer = new Timer(messageTimeout, new ActionListener() {
public void actionPerformed(ActionEvent e) {
statusMessageLabel.setText("");
}
});
messageTimer.setRepeats(false);
int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
for (int i = 0; i < busyIcons.length; i++) {
busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
}
busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
public void actionPerformed(ActionEvent e) {
busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
}
});
idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
statusAnimationLabel.setIcon(idleIcon);
12
progressBar.setVisible(false);
TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener()
{
public void propertyChange(java.beans.PropertyChangeEvent evt) {
String propertyName = evt.getPropertyName();
if ("started".equals(propertyName)) {
if (!busyIconTimer.isRunning()) {
statusAnimationLabel.setIcon(busyIcons[0]);
busyIconIndex = 0;
busyIconTimer.start();
}
progressBar.setVisible(true);
progressBar.setIndeterminate(true);
} else if ("done".equals(propertyName)) {
busyIconTimer.stop();
statusAnimationLabel.setIcon(idleIcon);
progressBar.setVisible(false);
progressBar.setValue(0);
} else if ("message".equals(propertyName)) {
String text = (String)(evt.getNewValue());
statusMessageLabel.setText((text == null) ? "" : text);
messageTimer.restart();
} else if ("progress".equals(propertyName)) {
int value = (Integer)(evt.getNewValue());
progressBar.setVisible(true);
progressBar.setIndeterminate(false);
progressBar.setValue(value);
}
}
});
}
@Action
public void showAboutBox() {
if (aboutBox == null) {
JFrame mainFrame = MiniprojectApp.getApplication().getMainFrame();
aboutBox = new MiniprojectAboutBox(mainFrame);
aboutBox.setLocationRelativeTo(mainFrame);
}
MiniprojectApp.getApplication().show(aboutBox);
}
@SuppressWarnings("unchecked")
private void initComponents() {
mainPanel = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
menuBar = new javax.swing.JMenuBar();
13
javax.swing.JMenu fileMenu = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
jMenu1 = new javax.swing.JMenu();
jMenuItem3 = new javax.swing.JMenuItem();
jMenuItem4 = new javax.swing.JMenuItem();
javax.swing.JMenu helpMenu = new javax.swing.JMenu();
javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
statusPanel = new javax.swing.JPanel();
javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
statusMessageLabel = new javax.swing.JLabel();
statusAnimationLabel = new javax.swing.JLabel();
progressBar = new javax.swing.JProgressBar();
org.jdesktop.application.ResourceMap resourceMap =
org.jdesktop.application.Application.getInstance(miniproject.MiniprojectApp.class).getC
ontext().getResourceMap(MiniprojectView.class);
mainPanel.setBackground(resourceMap.getColor("mainPanel.background")); //
NOI18N
mainPanel.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1,
resourceMap.getColor("mainPanel.border.matteColor"))); // NOI18N
mainPanel.setMaximumSize(new java.awt.Dimension(800, 800));
mainPanel.setName("mainPanel"); // NOI18N
mainPanel.setOpaque(false);
mainPanel.setRequestFocusEnabled(false);
jLabel1.setIcon(resourceMap.getIcon("jLabel1.icon")); // NOI18N
jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
jLabel1.setName("jLabel1"); // NOI18N
javax.swing.GroupLayout mainPanelLayout = new
javax.swing.GroupLayout(mainPanel);
mainPanel.setLayout(mainPanelLayout);
mainPanelLayout.setHorizontalGroup(
mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA
DING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 783,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
);
mainPanelLayout.setVerticalGroup(
mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA
DING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
mainPanelLayout.createSequentialGroup()
14
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 636,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
);
menuBar.setBackground(resourceMap.getColor("menuBar.background")); //
NOI18N
menuBar.setName("menuBar"); // NOI18N
fileMenu.setBackground(resourceMap.getColor("fileMenu.background")); //
NOI18N
fileMenu.setForeground(resourceMap.getColor("fileMenu.foreground")); //
NOI18N
fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
fileMenu.setName("fileMenu"); // NOI18N
jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.
VK_M, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem1.setText(resourceMap.getString("jMenuItem1.text")); // NOI18N
jMenuItem1.setName("jMenuItem1"); // NOI18N
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
fileMenu.add(jMenuItem1);
jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.
VK_F, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem2.setText(resourceMap.getString("jMenuItem2.text")); // NOI18N
jMenuItem2.setName("jMenuItem2"); // NOI18N
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
fileMenu.add(jMenuItem2);
javax.swing.ActionMap actionMap =
org.jdesktop.application.Application.getInstance(miniproject.MiniprojectApp.class).getC
ontext().getActionMap(MiniprojectView.class, this);
exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
exitMenuItem.setName("exitMenuItem"); // NOI18N
fileMenu.add(exitMenuItem);
menuBar.add(fileMenu);
jMenu1.setBackground(resourceMap.getColor("jMenu1.background")); // NOI18N
jMenu1.setForeground(resourceMap.getColor("jMenu1.foreground")); // NOI18N
jMenu1.setText(resourceMap.getString("jMenu1.text")); // NOI18N
jMenu1.setName("jMenu1"); // NOI18N
15
jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.
VK_M, java.awt.event.InputEvent.ALT_MASK));
jMenuItem3.setText(resourceMap.getString("jMenuItem3.text")); // NOI18N
jMenuItem3.setName("jMenuItem3"); // NOI18N
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem3ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem3);
jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.
VK_F, java.awt.event.InputEvent.ALT_MASK));
jMenuItem4.setText(resourceMap.getString("jMenuItem4.text")); // NOI18N
jMenuItem4.setName("jMenuItem4"); // NOI18N
jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem4ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem4);
menuBar.add(jMenu1);
helpMenu.setBackground(resourceMap.getColor("helpMenu.background")); //
NOI18N
helpMenu.setForeground(resourceMap.getColor("helpMenu.foreground")); //
NOI18N
helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
aboutMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.Key
Event.VK_A, java.awt.event.InputEvent.CTRL_MASK));
aboutMenuItem.setText(resourceMap.getString("aboutMenuItem.text")); // NOI18N
aboutMenuItem.setName("aboutMenuItem"); // NOI18N
helpMenu.add(aboutMenuItem);
menuBar.add(helpMenu);
statusPanel.setBackground(resourceMap.getColor("statusPanel.background")); //
NOI18N
statusPanel.setName("statusPanel"); // NOI18N
statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N
statusMessageLabel.setName("statusMessageLabel"); // NOI18N
statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N
progressBar.setName("progressBar"); // NOI18N
javax.swing.GroupLayout statusPanelLayout = new
javax.swing.GroupLayout(statusPanel);
statusPanel.setLayout(statusPanelLayout);
statusPanelLayout.setHorizontalGroup(
16
statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addComponent(statusPanelSeparator,
javax.swing.GroupLayout.DEFAULT_SIZE, 795, Short.MAX_VALUE)
.addGroup(statusPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(statusMessageLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
625, Short.MAX_VALUE)
.addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(statusAnimationLabel)
.addContainerGap())
);
statusPanelLayout.setVerticalGroup(
statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addGroup(statusPanelLayout.createSequentialGroup()
.addComponent(statusPanelSeparator,
javax.swing.GroupLayout.PREFERRED_SIZE, 2,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(statusMessageLabel)
.addComponent(statusAnimationLabel)
.addComponent(progressBar,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(3, 3, 3))
);
setComponent(mainPanel);
setMenuBar(menuBar);
setStatusBar(statusPanel);
}// </editor-fold>
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
EncodeMessage obj = new EncodeMessage();
obj.setVisible(true);
}
private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {
DecodeFile obj = new DecodeFile();
obj.setVisible(true);
17
}
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
EncodeFile obj = new EncodeFile();
obj.setVisible(true);
}
private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {
DecodeMessage obj = new DecodeMessage();
obj.setVisible(true);
}
private javax.swing.JLabel jLabel1;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JMenuItem jMenuItem4;
private javax.swing.JPanel mainPanel;
private javax.swing.JMenuBar menuBar;
private javax.swing.JProgressBar progressBar;
private javax.swing.JLabel statusAnimationLabel;
private javax.swing.JLabel statusMessageLabel;
private javax.swing.JPanel statusPanel;
private final Timer messageTimer;
private final Timer busyIconTimer;
private final Icon idleIcon;
private final Icon[] busyIcons = new Icon[15];
private int busyIconIndex = 0;
private JDialog aboutBox;
}
//MiniprojectAboutBox.java
package miniproject;
import org.jdesktop.application.Action;
public class MiniprojectAboutBox extends javax.swing.JDialog {
public MiniprojectAboutBox(java.awt.Frame parent) {
super(parent);
initComponents();
getRootPane().setDefaultButton(closeButton);
}
@Action public void closeAboutBox() {
dispose();
}
private void initComponents() {
javax.swing.JLabel appTitleLabel = new javax.swing.JLabel();
javax.swing.JLabel appDescLabel = new javax.swing.JLabel();
javax.swing.JLabel imageLabel = new javax.swing.JLabel();
label1 = new java.awt.Label();
18
label2 = new java.awt.Label();
label3 = new java.awt.Label();
label4 = new java.awt.Label();
label6 = new java.awt.Label();
label7 = new java.awt.Label();
label8 = new java.awt.Label();
label9 = new java.awt.Label();
closeButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
org.jdesktop.application.ResourceMap resourceMap =
org.jdesktop.application.Application.getInstance(miniproject.MiniprojectApp.class).getC
ontext().getResourceMap(MiniprojectAboutBox.class);
setTitle(resourceMap.getString("title")); // NOI18N
setModal(true);
setName("aboutBox"); // NOI18N
setResizable(false);
appTitleLabel.setFont(appTitleLabel.getFont().deriveFont(appTitleLabel.getFont().g
etStyle() | java.awt.Font.BOLD, appTitleLabel.getFont().getSize()+4));
appTitleLabel.setText(resourceMap.getString("Application.title")); // NOI18N
appTitleLabel.setName("appTitleLabel"); // NOI18N
appDescLabel.setText(resourceMap.getString("appDescLabel.text")); // NOI18N
appDescLabel.setName("appDescLabel"); // NOI18N
imageLabel.setIcon(resourceMap.getIcon("imageLabel.icon")); // NOI18N
imageLabel.setName("imageLabel"); // NOI18N
label1.setFont(resourceMap.getFont("label1.font")); // NOI18N
label1.setName("label1"); // NOI18N
label1.setText(resourceMap.getString("label1.text")); // NOI18N
label2.setFont(resourceMap.getFont("label2.font")); // NOI18N
label2.setName("label2"); // NOI18N
label2.setText(resourceMap.getString("label2.text")); // NOI18N
label3.setFont(resourceMap.getFont("label3.font")); // NOI18N
label3.setName("label3"); // NOI18N
label3.setText(resourceMap.getString("label3.text")); // NOI18N
label4.setFont(resourceMap.getFont("label4.font")); // NOI18N
label4.setName("label4"); // NOI18N
label4.setText(resourceMap.getString("label4.text")); // NOI18N
label6.setFont(resourceMap.getFont("label6.font")); // NOI18N
label6.setName("label6"); // NOI18N
label6.setText(resourceMap.getString("label6.text")); // NOI18N
label7.setFont(resourceMap.getFont("label7.font")); // NOI18N
label7.setName("label7"); // NOI18N
label7.setText(resourceMap.getString("label7.text")); // NOI18N
label8.setFont(resourceMap.getFont("label8.font")); // NOI18N
label8.setName("label8"); // NOI18N
label8.setText(resourceMap.getString("label8.text")); // NOI18N
label9.setFont(resourceMap.getFont("label9.font")); // NOI18N
19
label9.setName("label9"); // NOI18N
label9.setText(resourceMap.getString("label9.text")); // NOI18N
javax.swing.ActionMap actionMap =
org.jdesktop.application.Application.getInstance(miniproject.MiniprojectApp.class).getC
ontext().getActionMap(MiniprojectAboutBox.class, this);
closeButton.setAction(actionMap.get("closeAboutBox")); // NOI18N
closeButton.setName("closeButton"); // NOI18N
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(imageLabel, javax.swing.GroupLayout.PREFERRED_SIZE,
227, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.L
EADING)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRE
LATED)
.addComponent(appTitleLabel))
.addGroup(layout.createSequentialGroup()
.addGap(10, 10, 10)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(label8,
javax.swing.GroupLayout.PREFERRED_SIZE, 58,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RE
LATED))
.addGroup(layout.createSequentialGroup()
.addComponent(label6,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(103, 103, 103)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.
LEADING)
.addComponent(label7,
javax.swing.GroupLayout.PREFERRED_SIZE, 149,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(label2,
javax.swing.GroupLayout.PREFERRED_SIZE, 189,
javax.swing.GroupLayout.PREFERRED_SIZE)
20
.addComponent(label4,
javax.swing.GroupLayout.PREFERRED_SIZE, 135,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.
TRAILING)
.addComponent(closeButton)
.addComponent(label9,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(130, 130, 130))
.addGroup(layout.createSequentialGroup()
.addComponent(label1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RE
LATED))
.addGroup(layout.createSequentialGroup()
.addComponent(label3,
javax.swing.GroupLayout.PREFERRED_SIZE, 77,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RE
LATED))))
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(appDescLabel)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.T
RAILING)
.addComponent(imageLabel,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(appTitleLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELAT
ED)
.addComponent(appDescLabel,
javax.swing.GroupLayout.PREFERRED_SIZE, 33,
javax.swing.GroupLayout.PREFERRED_SIZE)
21
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELAT
ED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.
LEADING, false)
.addComponent(label7, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(label6, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELAT
ED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.
LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(label8, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RE
LATED)
.addComponent(label1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(label9,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RE
LATED)
.addComponent(label2,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELAT
ED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.
LEADING)
.addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(label4, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(12, 12, 12)
.addComponent(closeButton)
.addGap(46, 46, 46)))
.addContainerGap())
22
);
pack();
}// </editor-fold>
private javax.swing.JButton closeButton;
private java.awt.Label label1;
private java.awt.Label label2;
private java.awt.Label label3;
private java.awt.Label label4;
private java.awt.Label label6;
private java.awt.Label label7;
private java.awt.Label label8;
private java.awt.Label label9;
}
// EncodeMessage.java
package miniproject;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
public class EncodeMessage extends javax.swing.JFrame {
JFileChooser fileChooser=new JFileChooser();
public static final int OFFSET= 64;
private short messageSize, temp;
private int i, j, size;
byte by,byt, byb;
private String path;
String pathtest,pathtest1;
JFileChooser fileChooser1=new JFileChooser();
public EncodeMessage() {
initComponents();
}
@SuppressWarnings("unchecked")
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jButton2 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
23
jTextField2 = new javax.swing.JTextField();
jButton3 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
org.jdesktop.application.ResourceMap resourceMap =
org.jdesktop.application.Application.getInstance(miniproject.MiniprojectApp.class).getConte
xt().getResourceMap(EncodeMessage.class);
setTitle(resourceMap.getString("Form.title")); // NOI18N
setBackground(resourceMap.getColor("Form.background")); // NOI18N
setName("Form"); // NOI18N
jPanel1.setName("jPanel1"); // NOI18N
jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N
jTextField1.setName("jTextField1"); // NOI18N
jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
jButton1.setName("jButton1"); // NOI18N
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
jLabel1.setName("jLabel1"); // NOI18N
jScrollPane1.setName("jScrollPane1"); // NOI18N
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jTextArea1.setName("jTextArea1"); // NOI18N
jScrollPane1.setViewportView(jTextArea1);
jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
jButton2.setName("jButton2"); // NOI18N
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.ActionMap actionMap =
org.jdesktop.application.Application.getInstance(miniproject.MiniprojectApp.class).getConte
xt().getActionMap(EncodeMessage.class, this);
jButton5.setAction(actionMap.get("quit")); // NOI18N
jButton5.setText(resourceMap.getString("jButton5.text")); // NOI18N
jButton5.setName("jButton5"); // NOI18N
jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
jLabel2.setName("jLabel2"); // NOI18N
jTextField2.setText(resourceMap.getString("jTextField2.text")); // NOI18N
jTextField2.setName("jTextField2"); // NOI18N
jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
24
jButton3.setName("jButton3"); // NOI18N
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.
LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(40, 40, 40)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.
LEADING)
.addComponent(jScrollPane1,
javax.swing.GroupLayout.PREFERRED_SIZE, 309,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRE
LATED)
.addComponent(jButton5))))
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.
TRAILING, false)
.addComponent(jTextField2,
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField1,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, 239, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELAT
ED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEAD
ING, false)
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addContainerGap(44, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup() .addGap(45, 45, 45)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addGap(104, 104, 104))
25
.addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 64,
javax.swing.GroupLayout.PREFERRED_SIZE).addContainerGap(326,
Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 22,
javax.swing.GroupLayout.PREFERRED_SIZE).addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.
BASELINE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.
addComponent(jButton1)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.
RELATED).addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Align
ment.BASELINE).addComponent(jTextField2,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(jButton3)).addGap(18, 18,
18)
.
addComponent(jLabel1).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.R
ELATED).addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE,
124, javax.swing.GroupLayout.PREFERRED_SIZE)
.
addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addC
omponent(jButton2).addComponent(jButton5)).addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addCo
mponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 311,
Short.MAX_VALUE)
);
pack();
}// </editor-fold>
26
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int retval = fileChooser.showOpenDialog(this);
if (retval == JFileChooser.APPROVE_OPTION) {
pathtest=fileChooser.getSelectedFile().getPath();
if(pathtest.endsWith(".mpg")||pathtest.endsWith(".flv")||pathtest.endsWith(".mkv")||
pathtest.endsWith(".mpeg")&&pathtest.length()>=0)
jTextField1.setText(pathtest);
else
JOptionPane.showMessageDialog(null, "select only '.mpg'(or) '.flv'(or) '.mkv'(or)
'.mpeg' files");
}
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
int retval = fileChooser.showSaveDialog(this);
if (retval == JFileChooser.APPROVE_OPTION) {
pathtest1=fileChooser.getSelectedFile().getPath();
if(pathtest.endsWith(".mpg")==pathtest1.endsWith(".mpg")
&&pathtest.endsWith(".flv")==pathtest1.endsWith(".flv")&&pathtest.endsWith(".mkv")==p
athtest1.endsWith(".mkv")&&pathtest.endsWith(".mpeg")==pathtest1.endsWith(".mpeg"))
{
if(pathtest.equals(pathtest1))
{
JOptionPane.showMessageDialog(null, "save with different name" );
}
else
jTextField2.setText(fileChooser.getSelectedFile().getPath());
}
else
JOptionPane.showMessageDialog(null, "save the file with same extension as
input" );
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
DataInputStream in = null;
DataOutputStream out = null;
String message = jTextArea1.getText();
String inFile = jTextField1.getText();
String outFile = jTextField2.getText();
try
{
in= new DataInputStream(new FileInputStream(inFile)); // Open the
data file
out= new DataOutputStream(new FileOutputStream(outFile));
// Skip past OFFSET bytes
for(i=0; i<= OFFSET; i++)
out.writeByte(in.readByte());
27
messageSize= (short) message.length();
for(i=14; i>=0; i-=2)
{
temp= messageSize;
temp>>=i;// Shift the bits in pair of 2 to least significant
position
by= (byte) temp; // and store them in the Vector
by&= 0x03;
// messageSize being 16 bit short type, will be stored in 8 pairs of 2
bits
// Write these bytes to the output file
byt= in.readByte();
byt&= 0xFC;
byt|= by;
out.writeByte(byt);
}
for(i=0; i<messageSize; i++) // Embed the message
{
byt= (byte) message.charAt(i);
byt&= 0x7F;
for(j=6; j>=0; j-=2)
{
by= byt;
by>>= j;
by&= 0x03;
// Write these bytes to the output file
byb= in.readByte();
byb&= 0xFC;
byb|= by;
out.writeByte(byb);
}
}
// Write the remaining bytes
while(true)
{
by= in.readByte();
out.writeByte(by);
}
}
catch(EOFException e)
{
}
catch(Exception e)
{
message= "Oops!!\nError: "+ e.toString();
JOptionPane.showMessageDialog(null, message);
28
}
finally
{
try
{ in.close();
out.close();
}
catch(Exception ex)
{
message= "Oops!!\nError: "+ ex.toString();
JOptionPane.showMessageDialog(null, message);
}
}
JOptionPane.showMessageDialog(null, "message encoded successfully");
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new EncodeMessage().setVisible(true);
}
});
}
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton5;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
}
// EncodeFile.java
package miniproject;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
public class EncodeFile extends javax.swing.JFrame {
public static final int OFFSET= 64;
29
JFileChooser fileChooser=new JFileChooser();
JFileChooser fileChooser1=new JFileChooser();
private DataInputStream in;
private DataInputStream data;
private DataOutputStream out;
private int i;
private byte by;
private String message;
private short messageSize;
private int dataFileSize;
private short temp;
private byte byt;
private int j;
private byte byb;
String pathtest,pathtest1;
private int tempInt;
public EncodeFile() {
initComponents();
}
@SuppressWarnings("unchecked")
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jTextField2 = new javax.swing.JTextField();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jTextField3 = new javax.swing.JTextField();
jButton5 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
org.jdesktop.application.ResourceMap resourceMap =
org.jdesktop.application.Application.getInstance(miniproject.MiniprojectApp.class).getConte
xt().getResourceMap(EncodeFile.class);
setTitle(resourceMap.getString("Form.title")); // NOI18N
setName("Form"); // NOI18N
jPanel1.setName("jPanel1"); // NOI18N
jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N
jTextField1.setName("jTextField1"); // NOI18N
jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
30
jTextField2.setText(resourceMap.getString("jTextField2.text")); // NOI18N
jTextField2.setName("jTextField2"); // NOI18N
jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
jButton2.setName("jButton2"); // NOI18N
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
jButton3.setName("jButton3"); // NOI18N
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
javax.swing.ActionMap actionMap =
org.jdesktop.application.Application.getInstance(miniproject.MiniprojectApp.class).getConte
xt().getActionMap(EncodeFile.class, this);
jButton4.setAction(actionMap.get("quit")); // NOI18N
jButton4.setFont(resourceMap.getFont("jButton4.font")); // NOI18N
jButton4.setText(resourceMap.getString("jButton4.text")); // NOI18N
jButton4.setName("jButton4"); // NOI18N
jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
jLabel1.setName("jLabel1"); // NOI18N
jTextField3.setText(resourceMap.getString("jTextField3.text")); // NOI18N
jTextField3.setName("jTextField3"); // NOI18N
jButton5.setText(resourceMap.getString("jButton5.text")); // NOI18N
jButton5.setName("jButton5"); // NOI18N
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.
addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout.createParallelGr
oup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel1Layout.createSeque
ntialGroup().addGap(60, 60, 60).addComponent(jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE, 230,
javax.swing.GroupLayout.PREFERRED_SIZE)).addGroup(jPanel1Layout.createSequential
Group().addContainerGap()addGroup(jPanel1Layout.createParallelGroup(javax.swing.Grou
31
pLayout.Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILI
NG, false).addComponent(jTextField2, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, 256,
Short.MAX_VALUE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UN
RELATED)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 96,
Short.MAX_VALUE)
.addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 96,
Short.MAX_VALUE)))
.addGroup(jPanel1Layout.createSequentialGroup().addComponent(jButton3).addGap(18, 18,
18) .addComponent(jButton4))))
.
addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(jText
Field3, javax.swing.GroupLayout.PREFERRED_SIZE, 255,
javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.
ComponentPlacement.UNRELATED).addComponent(jButton5))).addGap(28, 28, 28))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(j
Label1)
.addGap(27, 27, 27)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.
BASELINE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(jButton1)).addGap(18, 18,
18).addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BAS
ELINE).addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton2)).addGap(19, 19,
19).addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BAS
ELINE).addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(jButton5)).addGap(18, 18,
18).addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BAS
ELINE).addComponent(jButton3).addComponent(jButton4)).addContainerGap(100,
Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
32
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignme
nt.LEADING).addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int retval = fileChooser.showOpenDialog(this);
if (retval == JFileChooser.APPROVE_OPTION) {
pathtest=fileChooser.getSelectedFile().getPath();
if(pathtest.endsWith(".mpeg")&&pathtest.length()>=0)
jTextField1.setText(fileChooser.getSelectedFile().getPath());
else
JOptionPane.showMessageDialog(null, "use only with '.mpeg' files with size");
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
int retval1 = fileChooser1.showOpenDialog(this);
if (retval1 == JFileChooser.APPROVE_OPTION) {
jTextField2.setText(fileChooser1.getSelectedFile().getPath());
}
}
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
int retval = fileChooser.showSaveDialog(this);
if (retval == JFileChooser.APPROVE_OPTION) {
pathtest1=fileChooser.getSelectedFile().getPath();
if(pathtest.endsWith(".mpeg")==pathtest1.endsWith(".mpeg"))
{
if(pathtest.equals(pathtest1))
{
JOptionPane.showMessageDialog(null,"save with different name");
}
else
jTextField3.setText(fileChooser.getSelectedFile().getPath());
}
}
else
JOptionPane.showMessageDialog(null, "save the file with same extension as
input" );
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
33
String inputFile=jTextField1.getText();
String dataFile=jTextField2.getText();
String outputFile=jTextField3.getText();
try
{
in= new DataInputStream(new FileInputStream(inputFile));
data= new DataInputStream(new FileInputStream(dataFile));
out= new DataOutputStream(new FileOutputStream(outputFile));
// Write OFFSET bytes from input file to output file
for(i=0; i<=OFFSET; i++)
{
by= in.readByte();
out.writeByte(by);
}
File file= new File(dataFile);
message= file.getName();
messageSize= (short) message.length();
dataFileSize= (int) file.length();
34
}
// Embed the size of the data file
// dataFileSize being 32 bit long type, will be stored in 16 pairs of 2 bits
for(i=30; i>=0; i-=2)
{
tempInt= dataFileSize;
tempInt>>=i;
by= (byte) tempInt;
by&= 0x03;
// Write these bytes to output file
byt= in.readByte();
byt&= 0xFC;
byt|= by;
out.writeByte(byt);
}
while(true)
{
byt= data.readByte();
35
catch(EOFException e) {}
catch(Exception e)
{
message= "Oops!!\nError: "+ e.toString();
JOptionPane.showMessageDialog(null, message);
}
finally
{
try
{
in.close();
data.close();
out.close();
}
catch(Exception ex)
{
message= "Oops!!\nError: "+ ex.toString();
JOptionPane.showMessageDialog(null, message);
}
}
message= "Data file embedded successfully in "+ new File(outputFile).getName();
JOptionPane.showMessageDialog(null, message);
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new EncodeFile().setVisible(true);
}
});
}
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
}
// DecodeMessage.java
package miniproject;
import java.io.DataInputStream;
import java.io.FileInputStream;
import javax.swing.JFileChooser;
36
import javax.swing.JOptionPane;
public class DecodeMessage extends javax.swing.JFrame {
public static final int OFFSET= 64;
JFileChooser fileChooser=new JFileChooser();
private DataInputStream in;
private int messageSize;
private int i;
private byte by;
private short temp;
private String message;
String pathtest;
private int j;
private byte byt;
public DecodeMessage() {
initComponents();
}
@SuppressWarnings("unchecked")
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
org.jdesktop.application.ResourceMap resourceMap =
org.jdesktop.application.Application.getInstance(miniproject.MiniprojectApp.class).getConte
xt().getResourceMap(DecodeMessage.class);
setTitle(resourceMap.getString("Form.title")); // NOI18N
setName("Form"); // NOI18N
jPanel1.setName("jPanel1"); // NOI18N
jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
jLabel1.setName("jLabel1"); // NOI18N
jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N
jTextField1.setName("jTextField1"); // NOI18N
jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
jButton1.setName("jButton1"); // NOI18N
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
37
jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
jLabel2.setName("jLabel2"); // NOI18N
jScrollPane1.setName("jScrollPane1"); // NOI18N
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jTextArea1.setName("jTextArea1"); // NOI18N
jScrollPane1.setViewportView(jTextArea1);
jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
jButton2.setName("jButton2"); // NOI18N
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.ActionMap actionMap =
org.jdesktop.application.Application.getInstance(miniproject.MiniprojectApp.class).getConte
xt().getActionMap(DecodeMessage.class, this);
jButton3.setAction(actionMap.get("quit")); // NOI18N
jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
jButton3.setName("jButton3"); // NOI18N
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.
addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout.createParallelGr
oup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel1Layout.createSeque
ntialGroup().addGap(88, 88,
88..addComponent(jLabel1)).addGroup(jPanel1Layout.createSequentialGroup().addGap(19,
19,
19).addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA
DING).addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 91,
javax.swing.GroupLayout.PREFERRED_SIZE).addGroup(jPanel1Layout.createSequentialG
roup().addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 245,
javax.swing.GroupLayout.PREFERRED_SIZE).addGap(18, 18,
18).addComponent(jButton1)))).addGroup(jPanel1Layout.createSequentialGroup().addGap(
39, 39, 39)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG).addGroup(jPanel1Layout.createSequentialGroup().addComponent(jButton2).addGap(18
, 18, 18) .addComponent(jButton3)).addComponent(jScrollPane1,
javax.swing.GroupLayout.PREFERRED_SIZE, 303,
javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap(15, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
38
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(jLabe
l1).addGap(18, 18,
18).addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BAS
ELINE).addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(jButton1)).addGap(30, 30,
30).addComponent(jLabel2).addPreferredGap(javax.swing.LayoutStyle.ComponentPlaceme
nt.UNRELATED).addComponent(jScrollPane1,
javax.swing.GroupLayout.PREFERRED_SIZE, 122,
javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.
ComponentPlacement.UNRELATED).addGroup(jPanel1Layout.createParallelGroup(javax.s
wing.GroupLayout.Alignment.BASELINE).addComponent(jButton2).addComponent(jButto
n3)).addContainerGap(20, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int retval = fileChooser.showOpenDialog(this);
if (retval == JFileChooser.APPROVE_OPTION) {
pathtest=fileChooser.getSelectedFile().getPath(); if(pathtest.endsWith(".mpg")||
pathtest.endsWith(".flv")||pathtest.endsWith(".mkv")||
pathtest.endsWith(".mpeg")&&pathtest.length()>=0)
jTextField1.setText(pathtest);
else
JOptionPane.showMessageDialog(null, "select only '.mpg'(or) '.flv'(or) '.mkv'(or)
'.mpeg' files");
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
String inputFile=jTextField1.getText();
char mesg[]= null;
try
{
39
in= new DataInputStream(new FileInputStream(inputFile));
// Get the size of the message
messageSize= 0;
for(i=0; i<=OFFSET; i++) // Skip OFFSET bytes
in.readByte();
for(i=14; i>=0; i-=2)
{
by= in.readByte(); // Read a byte from input file
temp= (short) by;
temp&= 0x0003;
temp<<= i;// Shift the bits in pair of 2 to get them to the right position
messageSize|= temp;
}
if(messageSize<=0)
{
message= "This file does not contain a message.";
JOptionPane.showMessageDialog(null, message);
}
mesg= new char[messageSize]; // Create a character array of size messageSize
for(i=0; i<messageSize; i++)
{
by= 0;
for(j=6; j>=0; j-=2)
{
byt= in.readByte(); // Read a byte from input file
byt&= 0x03;
byt<<= j;
by|= byt;
}
mesg[i]= (char) (((char) by)& 0x007F);
}
}
catch(Exception e)
{
message= "Oops!!\n Error: "+ e;
JOptionPane.showMessageDialog(null, message);
}
finally
{
try
{
in.close();
}
catch(Exception ex)
{
message= "Oops!!\nError: "+ ex;
40
JOptionPane.showMessageDialog(null, message);
}
message= "Message size: "+ messageSize+ " B";
String messg= new String(mesg);
jTextArea1.setText(messg);
}
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new DecodeMessage().setVisible(true);
}
});
}
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField jTextField1;
}
// DecodeFile.java
package miniproject;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
public class DecodeFile extends javax.swing.JFrame {
public static final int OFFSET= 64;
JFileChooser fileChooser=new JFileChooser();
private DataInputStream in;
private int i;
private int messageSize;
private byte by;
private short temp;
private int j;
private byte byt;
private String message;
private int dataFileSize;
private int tempInt;
41
String pathtest;
private DataOutputStream out;
private String pathtest1;
public DecodeFile() {
initComponents();
}
@SuppressWarnings("unchecked")
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setName("Form"); // NOI18N
jPanel1.setName("jPanel1"); // NOI18N
org.jdesktop.application.ResourceMap resourceMap =
org.jdesktop.application.Application.getInstance(miniproject.MiniprojectApp.class).getConte
xt().getResourceMap(DecodeFile.class);
jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
jLabel1.setName("jLabel1"); // NOI18N
jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N
jTextField1.setName("jTextField1"); // NOI18N
jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
jButton1.setName("jButton1"); // NOI18N
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
jButton2.setName("jButton2"); // NOI18N
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.ActionMap actionMap =
org.jdesktop.application.Application.getInstance(miniproject.MiniprojectApp.class).getConte
xt().getActionMap(DecodeFile.class, this);
jButton3.setAction(actionMap.get("quit")); // NOI18N
jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
jButton3.setName("jButton3"); // NOI18N
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
42
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLa
yout.Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addGroup(jP
anel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGrou
p(jPanel1Layout.createSequentialGroup().addGap(93, 93, 93).addComponent(jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE, 200,
javax.swing.GroupLayout.PREFERRED_SIZE)).addGroup(jPanel1Layout.createSequential
Group().addGap(19, 19,
19).addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEA
DING)
.addGroup(jPanel1Layout.createSequentialGroup().addComponent(jButton
2).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addCompo
nent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 70,
javax.swing.GroupLayout.PREFERRED_SIZE)).addGroup(jPanel1Layout.createSequential
Group().addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 243,
javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.
ComponentPlacement.UNRELATED).addComponent(jButton1))))).addContainerGap(41,
Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(jLabe
l1).addGap(39, 39, 39)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASEL
INE).addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(jButton1)).addGap(66, 66,
66)
.
addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELI
NE).addComponent(jButton2).addComponent(jButton3)).addContainerGap(123,
Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
43
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int retval = fileChooser.showOpenDialog(this);
if (retval == JFileChooser.APPROVE_OPTION) {
pathtest=fileChooser.getSelectedFile().getPath();
if(!pathtest.endsWith(".mpeg"))
{
JOptionPane.showMessageDialog(null,"open only '.mpeg' file");
}
else
{
jTextField1.setText(fileChooser.getSelectedFile().getPath());
}
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
char fileName[];
String inputFile=jTextField1.getText();
try
{
in= new DataInputStream(new FileInputStream(inputFile));
// Skip past Offset bytes
for(i=0; i<= OFFSET; i++) {
in.readByte();
}
messageSize= 0;
// Retrieve the size of the file name
for(i=6; i>=0; i-=2)
{
by= in.readByte();
by&= 0x03;
temp= (short) by;
temp<<=i;
messageSize|= temp;
}
// Retrieve the message
fileName= new char[messageSize];
for(i=0; i<messageSize; i++)
{
by= 0;
for(j=6; j>=0; j-=2)
{
byt= in.readByte();
byt&= 0x03;
byt<<= j;
by|= byt;
44
}
by&= 0x7F;
fileName[i]= (char) by;
}
message= new String(fileName);
// Retrieve the data file size
dataFileSize= 0;
for(i=30; i>=0; i-=2)
{
by= in.readByte();
tempInt= (int) by;
tempInt&= 0x00000003;
tempInt<<=i;
dataFileSize|= tempInt;
}
out= new DataOutputStream(new FileOutputStream(message));
for(i=0; i<dataFileSize; i++)
{
by= 0;
for(j=6; j>=0; j-=2)
{
byt= in.readByte();
byt&= 0x03;
byt<<= j;
by|= byt;
}
out.writeByte(by);
}
}
catch(EOFException e) {}
catch(Exception ex)
{
message= "Oops!!\nError: "+ ex.toString();
JOptionPane.showMessageDialog(null, message);
}
finally
{
try
{
in.close();
out.close();
}
catch(Exception ex)
{
message= "Oops!!\nError: "+ ex.toString();
JOptionPane.showMessageDialog(null, message);
45
}
}
message= "Data file retrieved successfully as "+ message;
JOptionPane.showMessageDialog(null, message);
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new DecodeFile().setVisible(true);
}
});
}
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextField1;
}
CHAPTER VI
6. SCREEN LAYOUTS:-
46
ENCODE DESIGN:-
47
DECODE DESIGN:-
48
ABOUT ME DESIGN:-
49
ENCODE WITH MESSAGE:-
50
51
ENCODE WITH FILE:-
52
53
54
DECODE MESSAGE:-
55
DECODE FILE:-
56
ABOUT ME FORM:-
57
CONCLUSION:-
This application will be tested under the J unit test cases with the default Net Bean’s
IDE.
Thus, a conclusion can be made that developed Application is useful for very secure
communication like cryptography.
58
BIBLIOGRAPHY:-
1. H.sachidt , 2002,java2 complete reference, 5th edition ,Tata McGraw Hill, New Delhi.
WEB SITES:-
1. http://www.java2s.com/Tutorial/Java/0240__Swing/Catalog0240__Swing.htm
2. http://www.java2s.com/Tutorial/Java/0180__File/Catalog0180__File.htm
3. http://www.roseindia.net/programming-tutorial/J2EE-Tutorials/J2EE
59