6 * Created on 24. září 2007, 0:37
13 public class hlavokno
extends javax
.swing
.JFrame
{
15 /** Creates new form hlavokno */
20 /** This method is called from within the constructor to
21 * initialize the form.
22 * WARNING: Do NOT modify this code. The content of this method is
23 * always regenerated by the Form Editor.
25 // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
26 private void initComponents() {
27 jDialog1
= new javax
.swing
.JDialog();
28 jFileChooser1
= new javax
.swing
.JFileChooser();
29 jButton1
= new javax
.swing
.JButton();
30 jTextField1
= new javax
.swing
.JTextField();
31 jButton2
= new javax
.swing
.JButton();
32 jTextField2
= new javax
.swing
.JTextField();
33 jButton3
= new javax
.swing
.JButton();
34 jTextField3
= new javax
.swing
.JTextField();
35 jButton4
= new javax
.swing
.JButton();
36 jTextField4
= new javax
.swing
.JTextField();
37 jButton5
= new javax
.swing
.JButton();
39 jFileChooser1
.setCurrentDirectory(null);
41 org
.jdesktop
.layout
.GroupLayout jDialog1Layout
= new org
.jdesktop
.layout
.GroupLayout(jDialog1
.getContentPane());
42 jDialog1
.getContentPane().setLayout(jDialog1Layout
);
43 jDialog1Layout
.setHorizontalGroup(
44 jDialog1Layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.LEADING
)
45 .add(jFileChooser1
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
)
47 jDialog1Layout
.setVerticalGroup(
48 jDialog1Layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.LEADING
)
49 .add(jFileChooser1
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
)
52 setDefaultCloseOperation(javax
.swing
.WindowConstants
.EXIT_ON_CLOSE
);
53 setTitle("One-time pad (XOR) symetric encryption [<-Harvie 2oo7]");
54 jButton1
.setText("Input");
55 jButton1
.addMouseListener(new java
.awt
.event
.MouseAdapter() {
56 public void mouseClicked(java
.awt
.event
.MouseEvent evt
) {
57 jButton1MouseClicked(evt
);
61 jButton2
.setText("Output");
62 jButton2
.addMouseListener(new java
.awt
.event
.MouseAdapter() {
63 public void mouseClicked(java
.awt
.event
.MouseEvent evt
) {
64 jButton2MouseClicked(evt
);
68 jButton3
.setText("Key");
69 jButton3
.addMouseListener(new java
.awt
.event
.MouseAdapter() {
70 public void mouseClicked(java
.awt
.event
.MouseEvent evt
) {
71 jButton3MouseClicked(evt
);
75 jButton4
.setText("Start");
76 jButton4
.addMouseListener(new java
.awt
.event
.MouseAdapter() {
77 public void mouseClicked(java
.awt
.event
.MouseEvent evt
) {
82 jTextField4
.setEditable(false);
83 jTextField4
.setText("Waiting...");
85 jButton5
.setText(".ccr");
86 jButton5
.addMouseListener(new java
.awt
.event
.MouseAdapter() {
87 public void mouseClicked(java
.awt
.event
.MouseEvent evt
) {
88 jButton5MouseClicked(evt
);
92 org
.jdesktop
.layout
.GroupLayout layout
= new org
.jdesktop
.layout
.GroupLayout(getContentPane());
93 getContentPane().setLayout(layout
);
94 layout
.setHorizontalGroup(
95 layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.LEADING
)
96 .add(org
.jdesktop
.layout
.GroupLayout
.TRAILING
, layout
.createSequentialGroup()
98 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.TRAILING
)
99 .add(org
.jdesktop
.layout
.GroupLayout
.LEADING
, jButton4
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, 467, Short
.MAX_VALUE
)
100 .add(org
.jdesktop
.layout
.GroupLayout
.LEADING
, layout
.createSequentialGroup()
101 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.TRAILING
)
102 .add(jButton3
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, 78, Short
.MAX_VALUE
)
103 .add(org
.jdesktop
.layout
.GroupLayout
.LEADING
, jButton2
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, Short
.MAX_VALUE
)
104 .add(org
.jdesktop
.layout
.GroupLayout
.LEADING
, jButton1
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, 78, Short
.MAX_VALUE
))
105 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.RELATED
)
106 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.TRAILING
)
107 .add(jTextField3
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, 383, Short
.MAX_VALUE
)
108 .add(org
.jdesktop
.layout
.GroupLayout
.LEADING
, jTextField1
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, 383, Short
.MAX_VALUE
)
109 .add(layout
.createSequentialGroup()
110 .add(jTextField2
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, 323, Short
.MAX_VALUE
)
111 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.RELATED
)
113 .add(org
.jdesktop
.layout
.GroupLayout
.LEADING
, jTextField4
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, 467, Short
.MAX_VALUE
))
116 layout
.setVerticalGroup(
117 layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.LEADING
)
118 .add(layout
.createSequentialGroup()
120 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.BASELINE
)
122 .add(jTextField1
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
, 24, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
))
123 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.RELATED
)
124 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.LEADING
)
125 .add(layout
.createSequentialGroup()
126 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.BASELINE
)
127 .add(jTextField2
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, 25, Short
.MAX_VALUE
)
130 .add(layout
.createSequentialGroup()
132 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.RELATED
)))
133 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.RELATED
)
134 .add(layout
.createParallelGroup(org
.jdesktop
.layout
.GroupLayout
.LEADING
, false)
136 .add(jButton3
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, Short
.MAX_VALUE
))
137 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.RELATED
)
138 .add(jButton4
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
, 26, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
)
139 .addPreferredGap(org
.jdesktop
.layout
.LayoutStyle
.RELATED
)
140 .add(jTextField4
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
, org
.jdesktop
.layout
.GroupLayout
.DEFAULT_SIZE
, org
.jdesktop
.layout
.GroupLayout
.PREFERRED_SIZE
)
144 }// </editor-fold>//GEN-END:initComponents
146 private void crypt (java
.awt
.event
.MouseEvent evt
) {//GEN-FIRST:event_crypt
147 // TODO crypt code here:
149 jTextField4
.setText("Working...");
150 //jProgressBar1.setValue(0);
152 if(jTextField1
.getText().equals(jTextField2
.getText())) { jTextField4
.setText("Output to Input - Can't do this!"); return; }
155 if( !(new File(jTextField1
.getText()).isFile()) ) { jTextField4
.setText("Input file not found!"); return; }
156 if( !(new File(jTextField3
.getText()).isFile()) ) { jTextField4
.setText("Key file not found!"); return; }
157 if( new File(jTextField2
.getText()).isFile() ) { jTextField4
.setText("Working (Rewriting output file)..."); }
158 long size
= (new File(jTextField1
.getText()).length());
159 long keysize
= (new File(jTextField3
.getText()).length());
162 BufferedInputStream in
= new BufferedInputStream(new FileInputStream(jTextField1
.getText()));
163 BufferedInputStream key
= new BufferedInputStream(new FileInputStream(jTextField3
.getText()));
164 BufferedOutputStream out
= new BufferedOutputStream(new FileOutputStream(jTextField2
.getText()));
167 int inb
, keyb
, progress
;
168 while((inb
= in
.read()) != -1) {
169 while((keyb
= key
.read()) == -1 /*|| keyb == 0x0A*/ ) {
171 key
= new BufferedInputStream(new FileInputStream(jTextField3
.getText()));
175 //jProgressBar1.setValue((int)((pos/size)*100));
182 jTextField4
.setText("Waiting... ["+size
+" b (en|de)crypted using "+keysize
+" b key]");
183 } catch(Exception e
) { jTextField4
.setText("I/O Error!"); }
184 }//GEN-LAST:event_crypt
186 private void jButton5MouseClicked (java
.awt
.event
.MouseEvent evt
) {//GEN-FIRST:event_jButton5MouseClicked
187 // TODO add your handling code here:
188 jTextField2
.setText(jTextField2
.getText()+".ccr");
189 }//GEN-LAST:event_jButton5MouseClicked
191 private void jButton3MouseClicked (java
.awt
.event
.MouseEvent evt
) {//GEN-FIRST:event_jButton3MouseClicked
192 // TODO add your handling code here:
193 int returnVal
= jFileChooser1
.showOpenDialog(jDialog1
);
194 if(jFileChooser1
.getSelectedFile() != null) {
195 jTextField3
.setText(jFileChooser1
.getCurrentDirectory()+"/"+jFileChooser1
.getSelectedFile().getName());
197 }//GEN-LAST:event_jButton3MouseClicked
199 private void jButton2MouseClicked (java
.awt
.event
.MouseEvent evt
) {//GEN-FIRST:event_jButton2MouseClicked
200 // TODO add your handling code here:
201 int returnVal
= jFileChooser1
.showOpenDialog(jDialog1
);
202 if(jFileChooser1
.getSelectedFile() != null) {
203 jTextField2
.setText(jFileChooser1
.getCurrentDirectory()+"/"+jFileChooser1
.getSelectedFile().getName());
205 }//GEN-LAST:event_jButton2MouseClicked
207 private void jButton1MouseClicked (java
.awt
.event
.MouseEvent evt
) {//GEN-FIRST:event_jButton1MouseClicked
208 // TODO add your handling code here:
209 int returnVal
= jFileChooser1
.showOpenDialog(jDialog1
);
210 if(jFileChooser1
.getSelectedFile() != null) {
211 jTextField1
.setText(jFileChooser1
.getCurrentDirectory()+"/"+jFileChooser1
.getSelectedFile().getName());
212 jTextField2
.setText(jFileChooser1
.getCurrentDirectory()+"/"+jFileChooser1
.getSelectedFile().getName());
214 }//GEN-LAST:event_jButton1MouseClicked
217 * @param args the command line arguments
219 public static void main (String args
[]) {
220 java
.awt
.EventQueue
.invokeLater (new Runnable () {
222 new hlavokno ().setVisible (true);
227 // Variables declaration - do not modify//GEN-BEGIN:variables
228 private javax
.swing
.JButton jButton1
;
229 private javax
.swing
.JButton jButton2
;
230 private javax
.swing
.JButton jButton3
;
231 private javax
.swing
.JButton jButton4
;
232 private javax
.swing
.JButton jButton5
;
233 private javax
.swing
.JDialog jDialog1
;
234 private javax
.swing
.JFileChooser jFileChooser1
;
235 private javax
.swing
.JTextField jTextField1
;
236 private javax
.swing
.JTextField jTextField2
;
237 private javax
.swing
.JTextField jTextField3
;
238 private javax
.swing
.JTextField jTextField4
;
239 // End of variables declaration//GEN-END:variables