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
261 262 263 264 265 266 267 268 269 270
271 272 273 274 275 276 277 278 279 280
281 282 283 284 285 286 287 288 289 290
291 292 293 294 295 296 297 298 299 300
301 302 303 304 305 306 307 308 309 310
311 312 313 314 315 316 317 318 319 320
321 322 323 324 325 326 327 328 329 330
331 332 333 334 335 336 337 338 339 340
341 342 343 344 345 346 347 348 349 350
351 352 353 354 355 356 357 358 359 360
361 362 363 364 365 366 367 368 369 370
371 372 373 374 375 376 377 378 379 380
381 382 383 384 385 386 387 388 389 390
391 392 393 394 395 396 397 398 399 400
401 402 403 404 405 406 407 408 409 410
411 412 413 414 415 416 417 418 419 420
421 422 423 424 425 426 427 428 429 430
431 432 433 434 435 436 437 438 439 440
441 442 443 444 445 446 447 448 449 450
451 452 453 454 455 456 457 458 459 460
461 462 463 464 465 466 467 468 469 470
471 472 473 474 475 476 477 478 479 480
481 482 483
|
/*
JaVi v1.0 - JavaVigenere - A Java implementation of the Vigenere
cryptographical algorithm
Un'implementazione Java dell'algoritmo di
Vigenere per la crittografia
Copyright (C) 2002 Pierre Blanc
http://www.teutoburgo.tk/it (italiano)
http://www.teutoburgo.tk/en (english)
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
Un grazie sentito a Roberto detto "Piano Man" per l'importante aiuto.
*/
package JaVi;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/**
*
* <p>Title: JaVi Applet</p>
* <p>Description: The class implementing the JaVi applet. It requires
* the Vigenere and the FrequenzaNijk objects</p>
* <p>Copyright: Copyright (c) 2002 Pierre Blanc</p>
* <p>Company: Teutoburgo</p>
* @author Pierre Blanc
* @version 1.0
*/
public class Javi2Applet extends Applet {
int defAcc=30;
boolean isTAKEditable = true;
boolean isTAKVisible = true;
boolean isStandalone = false;
boolean isEvaluable = true;
Vigenere vi;
BorderLayout borderLayout1 = new BorderLayout();
Panel panelLanguage = new Panel();
GridLayout gridLayout3 = new GridLayout(3,1);
Button buttonEnglish = new Button();
Button buttonItaliano = new Button();
Panel panel1 = new Panel();
GridLayout gridLayout1 = new GridLayout(3,1);
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();
Panel panelAbout = new Panel();
GridLayout gridLayout2 = new GridLayout(3,1);
Label label1 = new Label();
Label label3 = new Label();
Panel panel2 = new Panel();
FlowLayout flowLayout7 = new FlowLayout();
Label label2 = new Label();
Label label4 = new Label();
Panel panelGauge = new Panel();
GridLayout gridLayout4 = new GridLayout();
Label labelGauge = new Label();
Label labelGauge2 = new Label();
Label labelGauge3 = new Label();
/**
* Get a parameter value
* @param key
* @param def
* @return the 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
* @throws Exception
*/
private void jbInit() throws Exception {
String accuracy=this.getParameter("ACCURACY","30");
String methodKey=this.getParameter("Method","MAX");
String UnicFirst=this.getParameter("UnicodeFirstChar","32");
String UnicLast=this.getParameter("UnicodeLastChar","123");
defAcc=Integer.parseInt(accuracy);
int Unic0=Integer.parseInt(UnicFirst);
int UnicZ=Integer.parseInt(UnicLast);
vi=new Vigenere(Unic0, UnicZ, methodKey);
labelGauge2.setForeground(Color.black);
this.resize(620,380);
this.setLayout(borderLayout1);
panelLanguage.setLayout(gridLayout3);
buttonEnglish.setBackground(new Color(0, 192, 138));
buttonEnglish.setLabel("English");
buttonEnglish.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
buttonEnglish_mouseClicked(e);
}
});
buttonItaliano.setBackground(new Color(255, 138, 0));
buttonItaliano.setForeground(Color.white);
buttonItaliano.setLabel("Italiano");
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(gridLayout1);
panelPhrase.setLayout(flowLayout1);
labelPhrase.setForeground(Color.yellow);
panelKey.setLayout(flowLayout2);
buttonCrypt.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
buttonCrypt_mouseClicked(e);
}
});
textAreaKey.setText(Double.toString(java.lang.Math.PI)+
Double.toString(java.lang.Math.E));
textAreaKey.setBackground(Color.lightGray);
textAreaKey.setColumns(35);
textAreaKey.setEditable(isTAKEditable);
textAreaKey.setVisible(isTAKVisible);
textAreaKey.addTextListener(new java.awt.event.TextListener() {
public void textValueChanged(TextEvent e) {
textAreaKey_textValueChanged(e);
}
});
buttonDecrypt.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
buttonDecrypt_mouseClicked(e);
}
});
panelEncrypted.setLayout(flowLayout3);
labelEncrypted.setForeground(Color.yellow);
textArea3.setBackground(Color.blue);
textArea3.setColumns(35);
textArea3.setForeground(Color.yellow);
textArea3.setText("");
panelCheck.setLayout(flowLayout6);
panelVisible.setLayout(flowLayout4);
checkbox1.setBackground(SystemColor.text);
checkbox1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(MouseEvent e) {
checkbox1_mousePressed(e);
}
});
panelEditable.setLayout(flowLayout5);
checkbox2.setBackground(SystemColor.text);
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.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
buttonReset_mouseClicked(e);
}
});
textArea1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
textArea1_mouseClicked(e);
}
});
textArea1.setBackground(Color.blue);
textArea1.setColumns(35);
textArea1.setForeground(Color.yellow);
panelAbout.setLayout(gridLayout2);
label3.setText("Copyright (C) P.Blanc 2002 - "+
"http://it.geocities.com/teutoburgo");
this.setBackground(SystemColor.text);
panel2.setLayout(flowLayout7);
label2.setText("b<AE=<");
englishVersion();
panelGauge.setLayout(gridLayout4);
labelGauge.setText("label5");
gridLayout4.setRows(3);
labelGauge2.setText("label5");
labelGauge3.setForeground(Color.white);
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);
this.add(panelAbout, BorderLayout.NORTH);
panelAbout.add(label1, null);
panelAbout.add(label3, null);
panelAbout.add(panel2, null);
panel2.add(label4, null);
panel2.add(label2, null);
this.add(panelGauge, BorderLayout.WEST);
panelGauge.add(labelGauge, null);
panelGauge.add(labelGauge2, null);
panelGauge.add(labelGauge3, null);
labelGauge.setText("Key Strength:");
keyStrength();
buttonReset.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
buttonReset_mouseClicked(e);
}
});
textArea1.addTextListener(new java.awt.event.TextListener() {
public void textValueChanged(TextEvent e) {
textArea1_textValueChanged(e);
}
});
}
/**
* Get Applet information
* @return the applet information
*/
public String getAppletInfo() {
return "Applet Information";
}
/**
* Get parameter info
* @return parameter info
*/
public String[][] getParameterInfo() {
return null;
}
/**
* Richiama il metodo getKSPerCent dell'oggetto Vigenere e colora la
* labelGauge3 di rosso, giallo o verde a seconda della percentuale
* <br>
* Calls the getKSPerCent method of the Vigenere object and fills the
* labelGauge3 of ref, yellow or green depending of the percentual value
*/
void keyStrength(){
if (isEvaluable){
int s=vi.getKSPerCent(textAreaKey.getText(),defAcc);
if (s<=60) labelGauge3.setBackground(Color.red);
if (s<=90 &&s>60) labelGauge3.setBackground(Color.yellow);
if (s>90) labelGauge3.setBackground(Color.green);
labelGauge2.setText(s+" %");
} else {
labelGauge2.setText("--");
labelGauge3.setBackground(Color.lightGray);
}
if (textAreaKey.getText().length()< textArea1.getText().length())
{
labelGauge3.setBackground(Color.red);
labelGauge3.setText("Key Short!");
} else labelGauge3.setText("");
}
/**
* Controlla che la chiave non sia piu' corta della frase; in tal caso stampa
* il messaggio "Key Short!" ("Chiave corta!")
* <br>
* Checks if the key is shorter than the phrase; if so, prints the message
* "Key Short!"
*/
void keyLength(){
String st=labelGauge2.getText();
if (isEvaluable){
if (st.length()==4) st=st.substring(0,2); else
if (st.length()==5) st=st.substring(0,3); else st=st.substring(0,1);
int s=Integer.parseInt(st);
if (s<=60) labelGauge3.setBackground(Color.red);
if (s<=90 &&s>60) labelGauge3.setBackground(Color.yellow);
if (s>90) labelGauge3.setBackground(Color.green);
}
if (textAreaKey.getText().length()< textArea1.getText().length())
{
labelGauge3.setBackground(Color.red);
labelGauge3.setText("Key Short!");
} else {
labelGauge3.setText("");
if (!isEvaluable) labelGauge3.setBackground(Color.lightGray);
}
}
/**
* Imposta il linguaggio italiano alla pressione del buttonItaliano
* <br>
* Sets the italian language when buttonItaliano is pressed
* @param e the MouseEvent
*/
void buttonItaliano_mousePressed(MouseEvent e) {
labelGauge.setText("Forza Chiave:");
labelPhrase.setText("Frase");
buttonCrypt.setLabel("Critta");
labelKey.setText("Chiave");
buttonDecrypt.setLabel("Decritta");
labelEncrypted.setText("Frase Crittata");
checkbox1.setLabel("Chiave visibile");
checkbox2.setLabel("Valuta Chiave");
buttonReset.setLabel("Resetta Chiave");
textArea1.setText("Inserisci qui la tua frase");
textArea1.selectAll();
label1.setText("JaVi - v1.0 - Un'implementazione Java dell'algoritmo "+
"di Vigenere.");
label4.setText("Questo software e' tutelato dalla GPL license v.2");
}
void checkbox1_mousePressed(MouseEvent e) {
textAreaKey.setVisible(!textAreaKey.isVisible());
}
void checkbox2_mousePressed(MouseEvent e) {
isEvaluable=!isEvaluable;
keyStrength();
}
void textArea1_mouseClicked(MouseEvent e) {
textArea1.selectAll();
}
/**
* Richiama il metodo getEncryptedPhrase dell'oggetto Vigenere alla pressione
* del buttonCrypt
* <br>
* Calls the method getEncryptedPhrase of the Vigenere object when buttonCrypt
* is pressed
* @param e the MouseEvent
*/
void buttonCrypt_mouseClicked(MouseEvent e) {
textArea3.setText(vi.getEncryptedPhrase(textArea1.getText(),
textAreaKey.getText()));
textArea1.setText("");
}
/**
* Richiama il metodo getPhrase dell'oggetto Vigenere alla pressione
* del buttonDecrypt
* <br>
* Calls the method getPhrase of the Vigenere object when buttonDecrypt
* is pressed
* @param e the MouseEvent
*/
void buttonDecrypt_mouseClicked(MouseEvent e) {
textArea1.setText(vi.getPhrase(textArea3.getText(),
textAreaKey.getText()));
}
/**
* Richiama il metodo englishVersion alla pressione del buttonEnglish
* <br>
* Calls the englishVersion method when buttonEnglish is pressed
* @param e the MouseEvent
*/
void buttonEnglish_mouseClicked(MouseEvent e) {
englishVersion();
}
void buttonReset_mouseClicked(MouseEvent e) {
textAreaKey.setText(Double.toString(java.lang.Math.PI)+
Double.toString(java.lang.Math.E));
keyStrength();
}
/**
* Imposta il linguaggio inglese
* <br>
* Sets the english language
*/
void englishVersion (){
labelGauge.setText("Key Strength:");
labelPhrase.setText("Phrase");
buttonCrypt.setLabel("Encrypt");
labelKey.setText(" Key ");
buttonDecrypt.setLabel("Decrypt");
labelEncrypted.setText("Encrypted Phrase");
checkbox1.setLabel("Visible Key ");
checkbox2.setLabel("Evaluate Key ");
buttonReset.setLabel(" Reset Key ");
textArea1.setText("Insert your phrase here");
textArea1.selectAll();
label1.setText("JaVi - v1.0 - A Java implementation of the Vigenere"+
" algorithm.");
label4.setText("This software is under the GPL license v.2 ");
}
void textArea1_textValueChanged(TextEvent e) {
keyLength();
}
void textAreaKey_textValueChanged(TextEvent e) {
keyStrength();
}
}
|