JaViApplet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*
  JaVi - JavaVigenere - v0.5  A Java implementation of the Vigenere cryptographical
          algorithm
          Un'implementazione Java dell'algoritmo di Vigenere
          per la crittografia
    Copyright (C) 2002 Pierre Blanc
    Pierre Blanc: pierre@trek.eu.org , teutoburgo@yahoo.it
    http://it.geocities.com/teutoburgo


    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    or go to      http://www.gnu.org/copyleft/gpl.html


    Questo  programma è  software  libero; è  lecito redistribuirlo  o
    modificarlo secondo i termini  della Licenza Pubblica Generica GNU
    come è pubblicata dalla Free  Software Foundation, o la versione 2
    della licenza.
    Questo programma  è distribuito nella  speranza che sia  utile, ma
    SENZA  ALCUNA GARANZIA;  senza  neppure la  garanzia implicita  di
    NEGOZIABILITĄ  o di  APPLICABILITĄ PER  UN PARTICOLARE  SCOPO.  Si
    veda la Licenza Pubblica Generica GNU per avere maggiori dettagli.

    Questo  programma deve  essere  distribuito assieme  ad una  copia
    della Licenza Pubblica Generica GNU;  in caso contrario, se ne può
    ottenere  una scrivendo  alla Free  Software Foundation,  Inc., 59
    Temple Place, Suite 330, Boston, MA 02111-1307 USA  oppure da
    http://www.gnu.org/copyleft/gpl.html
*/

package JaVi;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import com.borland.jbcl.layout.*;

public class Javi2Applet extends Applet {
  
boolean isTAKEditable = false;
  
boolean isTAKVisible = true;
  
boolean isStandalone = false;
  Vigenere vi=
new Vigenere();
  BorderLayout borderLayout1 = 
new BorderLayout();
  Panel panelLanguage = 
new Panel();
  VerticalFlowLayout verticalFlowLayout3 = 
new VerticalFlowLayout();
  Button buttonEnglish = 
new Button();
  Button buttonItaliano = 
new Button();
  Panel panel1 = 
new Panel();
  VerticalFlowLayout verticalFlowLayout1 = 
new VerticalFlowLayout();
  Panel panelPhrase = 
new Panel();
  Panel panelKey = 
new Panel();
  Panel panelEncrypted = 
new Panel();
  FlowLayout flowLayout1 = 
new FlowLayout();
  Label labelPhrase = 
new Label();
  TextArea textArea1 = 
new TextArea("Insert your phrase here",3,30,
                                   TextArea.SCROLLBARS_VERTICAL_ONLY);
  FlowLayout flowLayout2 = 
new FlowLayout();
  Button buttonCrypt = 
new Button();
  Label labelKey = 
new Label();
  TextArea textAreaKey = 
new TextArea("Key",3,30,
                                      TextArea.SCROLLBARS_VERTICAL_ONLY);
  Button buttonDecrypt = 
new Button();
  FlowLayout flowLayout3 = 
new FlowLayout();
  Label labelEncrypted = 
new Label();
  TextArea textArea3 = 
new TextArea("Encrypted",3,30,
                                    TextArea.SCROLLBARS_VERTICAL_ONLY);
  Panel panelCheck = 
new Panel();
  Panel panelEditable = 
new Panel();
  Panel panelVisible = 
new Panel();
  FlowLayout flowLayout4 = 
new FlowLayout();
  Checkbox checkbox1 = 
new Checkbox("CBVisible", isTAKVisible);
  FlowLayout flowLayout5 = 
new FlowLayout();
  Checkbox checkbox2 = 
new Checkbox("CBEditable", isTAKEditable);
  FlowLayout flowLayout6 = 
new FlowLayout();
  Button buttonReset = 
new Button();
  
/**Get a parameter value*/
  
public String getParameter(String key, String def) {
    
return isStandalone ? System.getProperty(key, def) :
      (getParameter(key) != 
null ? getParameter(key) : def);
  }

  
/**Construct the applet*/
  
public Javi2Applet() {
  }
  
/**Initialize the applet*/
  
public void init() {
    
try {
      jbInit();
    }
    
catch(Exception e) {
      e.printStackTrace();
    }
  }
  
/**Component initialization*/
  
private void jbInit() throws Exception {
    
this.resize(500,340);
    
this.setLayout(borderLayout1);
    panelLanguage.setLayout(verticalFlowLayout3);
    buttonEnglish.setLabel(
"English");
    buttonEnglish.addMouseListener(
new java.awt.event.MouseAdapter() {
      
public void mouseClicked(MouseEvent e) {
        buttonEnglish_mouseClicked(e);
      }
    });
    buttonItaliano.setLabel(
"Italiano");
    textArea1.selectAll();

    buttonItaliano.addMouseListener(
new java.awt.event.MouseAdapter() {
      
public void mousePressed(MouseEvent e) {
        buttonItaliano_mousePressed(e);
      }
    });

    panelLanguage.setBackground(Color.gray);
    panel1.setBackground(Color.blue);
    panel1.setLayout(verticalFlowLayout1);
    panelPhrase.setLayout(flowLayout1);
    labelPhrase.setText(
"Phrase");
    panelKey.setLayout(flowLayout2);
    buttonCrypt.setLabel(
"Encrypt");
    buttonCrypt.addMouseListener(
new java.awt.event.MouseAdapter() {
      
public void mouseClicked(MouseEvent e) {
        buttonCrypt_mouseClicked(e);
      }
    });
    labelKey.setText(
"   Key ");
    textAreaKey.setText(Double.toString(java.lang.Math.PI)+Double.toString(java.lang.Math.E));
    textAreaKey.setEditable(isTAKEditable);
    textAreaKey.setVisible(isTAKVisible);
    buttonDecrypt.setLabel(
"Decrypt");
    buttonDecrypt.addMouseListener(
new java.awt.event.MouseAdapter() {
      
public void mouseClicked(MouseEvent e) {
        buttonDecrypt_mouseClicked(e);
      }
    });
    panelEncrypted.setLayout(flowLayout3);
    labelEncrypted.setText(
"Encrypted Phrase");
    textArea3.setText(
"");
    panelCheck.setLayout(flowLayout6);
    panelVisible.setLayout(flowLayout4);
    checkbox1.setLabel(
"Visible Key   ");
//    checkbox1.
    
checkbox1.addMouseListener(new java.awt.event.MouseAdapter() {
      
public void mousePressed(MouseEvent e) {
        checkbox1_mousePressed(e);
      }
    });
    panelEditable.setLayout(flowLayout5);
    checkbox2.setLabel(
"Editable Key   ");
    checkbox2.addMouseListener(
new java.awt.event.MouseAdapter() {
      
public void mousePressed(MouseEvent e) {
        checkbox2_mousePressed(e);
      }
    });
    panelKey.setBackground(Color.pink);
    panelCheck.setBackground(Color.gray);
    panelVisible.setBackground(Color.gray);
    panelEditable.setBackground(Color.gray);
    panelPhrase.setBackground(SystemColor.desktop);
    panelEncrypted.setBackground(SystemColor.desktop);
    buttonReset.setLabel(
"Reset Key     ");
    textArea1.addMouseListener(
new java.awt.event.MouseAdapter() {
      
public void mouseClicked(MouseEvent e) {
        textArea1_mouseClicked(e);
      }
    });
    
this.add(panelLanguage, BorderLayout.EAST);
    panelLanguage.add(buttonEnglish, 
null);
    panelLanguage.add(buttonItaliano, 
null);
    
this.add(panel1, BorderLayout.CENTER);
    panel1.add(panelPhrase, 
null);
    panelPhrase.add(labelPhrase, 
null);
    panelPhrase.add(textArea1, 
null);
    panel1.add(panelKey, 
null);
    panelKey.add(buttonCrypt, 
null);
    panelKey.add(labelKey, 
null);
    panelKey.add(textAreaKey, 
null);
    panelKey.add(buttonDecrypt, 
null);
    panel1.add(panelEncrypted, 
null);
    panelEncrypted.add(labelEncrypted, 
null);
    panelEncrypted.add(textArea3, 
null);
    
this.add(panelCheck, BorderLayout.SOUTH);
    panelCheck.add(buttonReset, 
null);
    panelCheck.add(panelVisible, 
null);
    panelVisible.add(checkbox1, 
null);
    panelCheck.add(panelEditable, 
null);
    panelEditable.add(checkbox2, 
null);
  }
  
/**Get Applet information*/
  
public String getAppletInfo() {
    
return "Applet Information";
  }
  
/**Get parameter info*/
  
public String[][] getParameterInfo() {
    
return null;
  }


  
void buttonItaliano_mousePressed(MouseEvent e) {
    labelPhrase.setText(
"Frase");
    buttonCrypt.setLabel(
"Critta");
    labelKey.setText(
"Chiave");
    buttonDecrypt.setLabel(
"Decritta");
    labelEncrypted.setText(
"Frase Crittata");
    checkbox1.setLabel(
"Chiave visibile");
    checkbox2.setLabel(
"Chiave editabile");
    buttonReset.setLabel(
"Resetta Chiave");
    textArea1.setText(
"Inserisci qui la tua frase");
    textArea1.selectAll();
  }


  
void checkbox1_mousePressed(MouseEvent e) {
    textAreaKey.setVisible(!textAreaKey.isVisible());
  }

  
void checkbox2_mousePressed(MouseEvent e) {
    textAreaKey.setEditable(!textAreaKey.isEditable());
  }

  
void textArea1_mouseClicked(MouseEvent e) {
    textArea1.selectAll();
  }

  
void buttonCrypt_mouseClicked(MouseEvent e) {
    textArea3.setText(vi.getEncryptedPhrase(textArea1.getText(),
                                         textAreaKey.getText()));
    textArea1.setText(
"");

  }

  
void buttonDecrypt_mouseClicked(MouseEvent e) {
    textArea1.setText(vi.getPhrase(textArea3.getText(),
                                          textAreaKey.getText()));
  }

  
void buttonEnglish_mouseClicked(MouseEvent e) {
    labelPhrase.setText(
"Phrase");
    buttonCrypt.setLabel(
"Encrypt");
    labelKey.setText(
"Key");
    buttonDecrypt.setLabel(
"Decrypt");
    labelEncrypted.setText(
"Encrypted Phrase");
    checkbox1.setLabel(
"Visible Key");
    checkbox2.setLabel(
"Editable Key");
    buttonReset.setLabel(
"Reset Key");
    textArea1.setText(
"Insert your phrase here");
    textArea1.selectAll();
  }
}
Java2html