/*
JaVi v0.8 - JavaVigenere - 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 , blanc_teutoburgo@yahoo.it
http://it.geocities.com/teutoburgo (italiano)
http://it.geocities.com/teutoburgo/indexEn.html (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
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
public class Frame1
extends JFrame {
Vigenere vig = new Vigenere();
int about=0;
//Construct the frame
public Frame1() {
enableEvents
(AWTEvent.
WINDOW_EVENT_MASK);
try {
jbInit();
}
e.printStackTrace();
}
}
//Component initialization
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane
= (JPanel) this.
getContentPane();
contentPane.
setPreferredSize(new Dimension(1000, 1000
));
contentPane.setLayout(borderLayout1);
this.setJMenuBar(jMenuBar1);
this.setTitle("Frame Title");
jPanel1.setLayout(borderLayout2);
jPNorth.
setBackground(Color.
white);
jPNorth.setLayout(borderLayout6);
jPSouth.
setBackground(Color.
orange);
jPanel4.setLayout(gridLayout4);
jPanel4.
setBackground(Color.
orange);
jPanel4.
setPreferredSize(new Dimension(90, 60
));
jPCenter.setLayout(borderLayout4);
jPanel2.
setBackground(Color.
orange);
jPanel2.
setPreferredSize(new Dimension(90, 10
));
jPanel2.setLayout(gridLayout2);
jPanel5.
setMinimumSize(new Dimension(30, 10
));
jPanel5.
setPreferredSize(new Dimension(30, 10
));
jPanel5.setLayout(borderLayout3);
jPanel6.
setBackground(new Color(255, 223, 0
));
jPanel6.
setMinimumSize(new Dimension(30, 10
));
jPanel6.
setPreferredSize(new Dimension(30, 10
));
jPanel9.
setBackground(Color.
orange);
jPanel9.
setPreferredSize(new Dimension(80, 70
));
jPNord1.setLayout(gridLayout1);
gridLayout1.setColumns(1);
gridLayout1.setRows(2);
jLabel1.setText("JaVi - v0.8 - A Java implementation of the Vigenere algorithm.");
jLabel2.setToolTipText("");
jLabel2.setText("Copyright (C) 2002 Pierre Blanc - "+
"blanc_teutoburgo@yahoo.it - http://it.geocities.com/teutoburgo");
jLabel3.
setBackground(Color.
pink);
jLabel3.setToolTipText("");
jLabel3.setText("This software is under the GPL license v.2");
jLabel4.
setBackground(Color.
pink);
jLabel4.setToolTipText("");
jLabel4.setText("b<AE=<");
jPSud1.setLayout(flowLayout1);
flowLayout1.setHgap(10);
flowLayout1.setVgap(0);
jLabel6.setToolTipText("");
jLabel6.setText("50%");
jLabel5.setToolTipText("");
jLabel5.setText("Forza chiave:");
jPanel3.
setMinimumSize(new Dimension(30, 10
));
jPanel3.
setPreferredSize(new Dimension(30, 10
));
jPanel3.setLayout(gridLayout3);
jScrollPane1.
setHorizontalScrollBarPolicy(JScrollPane.
HORIZONTAL_SCROLLBAR_NEVER);
jScrollPane1.
getViewport().
setBackground(Color.
orange);
jScrollPane1.setBorder(null);
jScrollPane1.
setPreferredSize(new Dimension(200, 40
));
jTextAreaChiave.
setPreferredSize(new Dimension(100, 17
));
jTextAreaChiave.setLineWrap(true);
jTextAreaChiave.setRows(5);
jTextAreaChiave.
addKeyListener(new java.
awt.
event.
KeyAdapter() {
jTextAreaChiave_keyTyped(e);
}
});
jScrollPane2.
setPreferredSize(new Dimension(200, 40
));
jTextAreaCrittata.
setPreferredSize(new Dimension(100, 17
));
jTextAreaCrittata.setColumns(20);
jTextAreaCrittata.setLineWrap(true);
jTextAreaCrittata.setRows(5);
jScrollPane3.
setPreferredSize(new Dimension(200, 40
));
jTextAreaFrase.
setMaximumSize(new Dimension(100, 17
));
jTextAreaFrase.
setMinimumSize(new Dimension(100, 17
));
jTextAreaFrase.
setPreferredSize(new Dimension(100, 17
));
jTextAreaFrase.setText("inserisci qui la tua frase");
jTextAreaFrase.setLineWrap(true);
jTextAreaFrase.setRows(5);
jPanel13.setLayout(flowLayout2);
jPanel13.
setBackground(Color.
orange);
jPanel13.
setPreferredSize(new Dimension(200, 70
));
jButton1.
setBackground(new Color(131, 0, 255
));
jButton1.
setForeground(Color.
white);
jButton1.setText("English");
jButton1.
addMouseListener(new java.
awt.
event.
MouseAdapter() {
jButton1_mouseClicked(e);
}
});
engl.
setBackground(new Color(79, 151, 39
));
engl.
setForeground(Color.
white);
engl.
setPreferredSize(new Dimension(79, 79
));
engl.setText("italiano");
engl_mouseClicked(e);
}
});
jPanel16.
setBackground(Color.
darkGray);
jPanel16.
setPreferredSize(new Dimension(200, 79
));
jPanel15.
setBackground(Color.
darkGray);
jPanel15.
setPreferredSize(new Dimension(200, 80
));
jButton2.setText("decritta");
jButton2.
addMouseListener(new java.
awt.
event.
MouseAdapter() {
jButton2_mouseClicked(e);
}
});
jButton3.
setPreferredSize(new Dimension(79, 27
));
jButton3.setText("critta");
jButton3.
addMouseListener(new java.
awt.
event.
MouseAdapter() {
jButton3_mousePressed(e);
}
});
jLabel7.setText("Chiave:");
jPanel1.
setPreferredSize(new Dimension(1000, 100
));
gridLayout2.setColumns(1);
gridLayout2.setRows(3);
jPanel7.
setPreferredSize(new Dimension(79, 79
));
jPanel7.setLayout(gridLayout5);
gridLayout3.setColumns(1);
gridLayout3.setRows(3);
gridLayout4.setColumns(1);
gridLayout4.setRows(3);
jCheckBox1.setSelected(true);
jCheckBox1.setText("Chiave editabile");
jCheckBox1.
addItemListener(new java.
awt.
event.
ItemListener() {
jCheckBox1_itemStateChanged(e);
}
});
jCheckBox2.setSelected(true);
jCheckBox2.setText("Chiave visibile");
jCheckBox2.
addItemListener(new java.
awt.
event.
ItemListener() {
jCheckBox2_itemStateChanged(e);
}
});
jButton4.setText("Resetta chiave");
jButton4.
addMouseListener(new java.
awt.
event.
MouseAdapter() {
jButton4_mouseClicked(e);
}
});
jLabel8.
setForeground(Color.
white);
jLabel8.setToolTipText("");
jLabel8.setText("Frase Crittata:");
jLabel9.
setForeground(Color.
white);
jLabel9.setText("Frase:");
jMenu1.setText("File");
jMenuApri.setText("Apri");
jMenuItemFrase.setText("Frase");
jMenuItemFrase.
addMouseListener(new java.
awt.
event.
MouseAdapter() {
jMenuItemFrase_mousePressed(e);
}
});
jMenuItemChiave.setText("Chiave");
jMenuItemChiave.
addMouseListener(new java.
awt.
event.
MouseAdapter() {
jMenuItemChiave_mousePressed(e);
}
});
jMenuItemCrittata.setActionCommand("Frase Crittata");
jMenuItemCrittata.setText("Frase Crittata");
jMenuItemCrittata.
addMouseListener(new java.
awt.
event.
MouseAdapter() {
jMenuItemCrittata_mousePressed(e);
}
});
jMenu3.setText("Help");
jMenuItem5.setText("About...");
jMenuItem5.
addMouseListener(new java.
awt.
event.
MouseAdapter() {
jMenuItem5_mousePressed(e);
}
});
jMenuSalva.setText("Salva");
jMenuItemFraseS.setText("Frase");
jMenuItemFraseS.
addMouseListener(new java.
awt.
event.
MouseAdapter() {
jMenuItemFraseS_mousePressed(e);
}
});
jMenuItemChiaveS.setText("Chiave");
jMenuItemChiaveS.
addMouseListener(new java.
awt.
event.
MouseAdapter() {
jMenuItemChiaveS_mousePressed(e);
}
});
jMenuItemCrittataS.setText("Crittata");
jMenuItemCrittataS.
addMouseListener(new java.
awt.
event.
MouseAdapter() {
jMenuItemCrittataS_mousePressed(e);
}
});
jPNord1.add(jLabel1, null);
jPNord1.add(jLabel2, null);
jPSud1.add(jLabel3, null);
jPSud1.add(jLabel4, null);
jPSouth.add(jButton4, null);
jPSouth.add(jCheckBox2, null);
jPSouth.add(jCheckBox1, null);
jPanel4.add(engl, null);
jPanel4.add(jButton1, null);
jPanel4.add(jPanel9, null);
jPanel13.add(jLabel7, null);
jPanel13.add(jScrollPane1, null);
jScrollPane1.getViewport().add(jTextAreaChiave, null);
jPanel13.add(jButton3, null);
jPanel13.add(jButton2, null);
jPanel3.add(jPanel16, null);
jPanel16.add(jLabel9, null);
jPanel16.add(jScrollPane3, null);
jPanel3.add(jPanel13, null);
jPanel3.add(jPanel15, null);
jPanel15.add(jLabel8, null);
jPanel15.add(jScrollPane2, null);
jScrollPane2.getViewport().add(jTextAreaCrittata, null);
jScrollPane3.getViewport().add(jTextAreaFrase, null);
jPanel2.add(jPanel7, null);
jPanel7.add(jLabel5, null);
jPanel2.add(jPanel5, null);
jPanel2.add(jPanel6, null);
jMenuBar1.add(jMenu1);
jMenuBar1.add(jMenu3);
jMenu1.add(jMenuApri);
jMenu1.add(jMenuSalva);
jMenuApri.add(jMenuItemFrase);
jMenuApri.add(jMenuItemChiave);
jMenuApri.add(jMenuItemCrittata);
jMenu3.add(jMenuItem5);
jMenuSalva.add(jMenuItemFraseS);
jMenuSalva.add(jMenuItemChiaveS);
jMenuSalva.add(jMenuItemCrittataS);
}
//Overridden so we can exit when window is closed
super.processWindowEvent(e);
}
}
jTextAreaCrittata.setText(vig.getEncryptedPhrase(jTextAreaFrase.getText(),jTextAreaChiave.getText()));
jTextAreaFrase.setText("");
}
jTextAreaFrase.setText(vig.getPhrase(jTextAreaCrittata.getText(),jTextAreaChiave.getText()));
}
void jTextAreaChiave_keyTyped
(KeyEvent e
) {
int accuratezza = vig.getKSPerCent(jTextAreaChiave.getText(),30);
jLabel6.setText(accuratezza+"%");
if (accuratezza<60) {
jPanel6.
setBackground(new Color(255,0,0
));
}
else {
jPanel6.
setBackground(new Color(0,255,0
));
}
}
jTextAreaChiave.setText("");
}
void jCheckBox2_itemStateChanged
(ItemEvent e
) {
if (jTextAreaChiave.isVisible()) {
jTextAreaChiave.setVisible(false);
}
else {
jTextAreaChiave.setVisible(true);
}
}
void jCheckBox1_itemStateChanged
(ItemEvent e
) {
if (jTextAreaChiave.isEditable()) {
jTextAreaChiave.setEditable(false);
}
else {
jTextAreaChiave.setEditable(true);
}
}
void englishVersion (){
jLabel5.setText("Key Strength:");
jLabel9.setText("Phrase");
jButton3.setText("Encrypt");
jLabel7.setText(" Key ");
jButton2.setText("Decrypt");
jLabel8.setText("Encrypted Phrase");
jCheckBox2.setText("Visible Key ");
jCheckBox1.setText("Editable Key ");
jButton4.setText(" Reset Key ");
jTextAreaFrase.setText("Insert your phrase here");
//jTextArea1.selectAll();
jLabel1.setText("JaVi - v0.8 - A Java implementation of the Vigenere"+
" algorithm.");
jLabel3.setText("This software is under the GPL license v.2");
jMenuApri.setText("Open");
jMenuSalva.setText("Save");
jMenuItemFrase.setText("Phrase");
jMenuItemChiave.setText("Key");
jMenuItemCrittata.setText("Encrypted");
jMenuItemFraseS.setText("Phrase");
jMenuItemChiaveS.setText("Key");
jMenuItemCrittataS.setText("Encrypted");
if (about==1) {
jLabel2.setText(" ...featuring Sara Cristilli and Danila Komar (Swing GUI DJs)");
}
}
englishVersion();
}
jLabel5.setText("Forza Chiave:");
jLabel9.setText("Frase");
jButton3.setText("Critta");
jLabel7.setText("Chiave");
jButton2.setText("Decritta");
jLabel8.setText("Frase Crittata");
jCheckBox2.setText("Chiave visibile");
jCheckBox1.setText("Chiave editabile");
jButton4.setText("Resetta Chiave");
jTextAreaFrase.setText("Inserisci qui la tua frase");
//textArea1.selectAll();
jLabel1.setText("JaVi - v0.8 - Un'implementazione Java dell'algoritmo "+
"di Vigenere.");
jLabel3.setText("Questo software e' tutelato dalla GPL license v.2");
jMenuApri.setText("Apri");
jMenuSalva.setText("Salva");
jMenuItemFrase.setText("Frase");
jMenuItemChiave.setText("Chiave");
jMenuItemCrittata.setText("Crittata");
jMenuItemFraseS.setText("Frase");
jMenuItemChiaveS.setText("Chiave");
jMenuItemCrittataS.setText("Crittata");
if (about==1) {
jLabel2.setText(" ...con la collaborazione di Sara Cristilli e Danila Komar (Swing GUI)");
}
}
int returnVal = jFileChooser1.showOpenDialog(this);
int j = 0;
try{
File file
= new File(jFileChooser1.
getSelectedFile().
getAbsolutePath());
int l=(int)file.length();
char [] arrCar= new char[l];
while (fr.ready()){
j += fr.read(arrCar,j,l-j);
}
for (int k=0; k<l-1; k++)
if ((int)arrCar[k]==13)
if((int)arrCar[k+1]==10){
arrCar[k]='*';
arrCar[k+1]='*';
}
fr.close();
ex.printStackTrace();
}
}
return str;
}
public void writeFile
(String str
){
try{
int returnVal = jFileChooser1.showSaveDialog(this);
File file
= new File(jFileChooser1.
getSelectedFile().
getAbsolutePath());
fw.write(str,0,str.length());
fw.close();
}
ex.printStackTrace();
}
}
jTextAreaFrase.setText(readFile());
}
jTextAreaChiave.setText(readFile());
}
void jMenuItemCrittata_mousePressed
(MouseEvent e
) {
jTextAreaCrittata.setText(readFile());
}
writeFile(jTextAreaFrase.getText());
}
void jMenuItemChiaveS_mousePressed
(MouseEvent e
) {
writeFile(jTextAreaChiave.getText());
}
void jMenuItemCrittataS_mousePressed
(MouseEvent e
) {
writeFile(jTextAreaCrittata.getText());
}
if(about==0){
if (jMenuItemChiave.getText().equals("Chiave")) {
jLabel2.setText(" ...con la collaborazione di Sara Cristilli e Danila Komar (Swing GUI)");
} else {
jLabel2.setText(" ...featuring Sara Cristilli and Danila Komar (Swing GUI DJs)");
}
about=1;
} else {
about=0;
jLabel2.setText("Copyright (C) 2002 Pierre Blanc - "+
"blanc_teutoburgo@yahoo.it - http://it.geocities.com/teutoburgo");
}
}
}