LAMPIRAN A: LISTING PROGRAM
TampilanUtama.java
/** To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package vigenerecipherlfsr;
/*
*
*
* @author rimavirgie
*/
public class TampilanutamavigenereLFSR extends javax.swing.JFrame {
public TampilanutamavigenereLFSR() {
initComponents();
this.setLocationRelativeTo(getRootPane());//untuk menampilkan ketengah
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel4 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
menuBar = new javax.swing.JMenuBar();
fileMenu = new javax.swing.JMenu();
openMenuItem = new javax.swing.JMenuItem();
saveMenuItem = new javax.swing.JMenuItem();
editMenu = new javax.swing.JMenu();
helpMenu = new javax.swing.JMenu();
jLabel4.setText("jLabel4");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setFont(new java.awt.Font("Tempus Sans ITC", 1, 14)); // NOI18N
jLabel1.setText("IMPLEMENTASI VIGENERE CIPHER DENGAN METODE");
jLabel2.setFont(new java.awt.Font("Tempus Sans ITC", 1, 14)); // NOI18N
jLabel2.setText("LINEAR FEEDBACK SHIFT REGISTER PADA TEXT");
jLabel3.setFont(new java.awt.Font("Traditional Arabic", 1, 14)); // NOI18N
jLabel3.setText("RIA FIRGI YANI");
jLabel5.setFont(new java.awt.Font("Traditional Arabic", 1, 14)); // NOI18N
jLabel5.setText("081401095");
fileMenu.setMnemonic('f');
fileMenu.setText("MENU");
openMenuItem.setMnemonic('o');
openMenuItem.setText("ENKRIPSI");
openMenuItem.addActionListener(new java.awt.event.ActionListener() {
openMenuItemActionPerformed(evt);
}
});
fileMenu.add(openMenuItem);
saveMenuItem.setMnemonic('s');
saveMenuItem.setText("DEKRIPSI");
saveMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
saveMenuItemActionPerformed(evt);
}
});
fileMenu.add(saveMenuItem);
menuBar.add(fileMenu);
editMenu.setMnemonic('e');
editMenu.setText("ABOUT");
editMenu.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
editMenuMouseClicked(evt);
}
});
editMenu.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
editMenuActionPerformed(evt);
}
});
menuBar.add(editMenu);
helpMenu.setMnemonic('h');
helpMenu.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
helpMenuMouseClicked(evt);
}
});
menuBar.add(helpMenu);
setJMenuBar(menuBar);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(62, 62, 62)
.addComponent(jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE, 396, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 63, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 358, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(178, 178, 178))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(190, 190, 190))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(25, 25, 25)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(30, 30, 30)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel5)
.addContainerGap(100, Short.MAX_VALUE))
pack();
}// </editor-fold>
private void
openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
Enkripsi enkrip = new Enkripsi();//untuk memanggil kelas enkrip
enkrip.show();//menampilkan
this.dispose(); //untuk menutup menu sebelumnya
}
private void
saveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
Dekripsi dekrip = new Dekripsi () ;//untuk memanggil kelas dekrip
dekrip.show();//menampilkan
this.dispose();//untuk menutup menu sebelumnya
}
private void editMenuActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void editMenuMouseClicked(java.awt.event.MouseEvent evt) {
About about = new About();//untuk memanggil kelas about
about.show();//untuk menampilkan
}
private void helpMenuMouseClicked(java.awt.event.MouseEvent evt) {
MenuHelp help = new MenuHelp();//untuk menampilkan kelas menu
help.show();//untuk menampilakan
this.dispose();//untuk menutup menu sebelumnya
}
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.h tml
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(TampilanutamavigenereLFSR.class.ge tName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(TampilanutamavigenereLFSR.class.ge tName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(TampilanutamavigenereLFSR.class.ge tName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(TampilanutamavigenereLFSR.class.ge tName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TampilanutamavigenereLFSR().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JMenu editMenu;
private javax.swing.JMenu fileMenu;
private javax.swing.JMenu helpMenu;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JMenuBar menuBar;
private javax.swing.JMenuItem openMenuItem;
private javax.swing.JMenuItem saveMenuItem;
// End of variables declaration
}
Enkripsi.java /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package vigenerecipherlfsr;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
/**
*
* @author rimavirgie
*/
public class Enkripsi extends javax.swing.JFrame {
// deklarasi variabel
String key,enkripsi,plainteks;
/**
* Creates new form Enkripsi
*/
public Enkripsi() {
initComponents();
this.setLocationRelativeTo(getRootPane());//untuk menampilkan ketengah
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jMenuBar2 = new javax.swing.JMenuBar();
jMenu3 = new javax.swing.JMenu();
jMenu4 = new javax.swing.JMenu();
jMenu5 = new javax.swing.JMenu();
jMenu6 = new javax.swing.JMenu();
jTextField2 = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
ValueKey = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
Plain = new javax.swing.JTextField();
cipher = new javax.swing.JTextField();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jMenu3.setText("File");
jMenuBar2.add(jMenu3);
jMenu4.setText("Edit");
jMenuBar2.add(jMenu4);
jMenu5.setText("File");
jMenuBar3.add(jMenu5);
jMenu6.setText("Edit");
jMenuBar3.add(jMenu6);
jTextField2.setText("jTextField2");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setFont(new java.awt.Font("Traditional Arabic", 1, 12)); // NOI18N
jLabel1.setText("KEY");
jLabel2.setText("Plaintext");
jLabel3.setFont(new java.awt.Font("Traditional Arabic", 1, 12)); // NOI18N
jLabel3.setText("Ciphertext");
ValueKey.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ValueKeyActionPerformed(evt);
}
});
jButton1.setFont(new java.awt.Font("Traditional Arabic", 1, 12)); // NOI18N
jButton1.setText("Generate");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton5.setFont(new java.awt.Font("Traditional Arabic", 1, 12)); // NOI18N
jButton5.setText("Enkripsi");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
cipher.addActionListener(new java.awt.event.ActionListener() {
cipherActionPerformed(evt);
}
});
jButton2.setFont(new java.awt.Font("Traditional Arabic", 1, 12)); // NOI18N
jButton2.setText("Save");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setFont(new java.awt.Font("Traditional Arabic", 1, 12)); // NOI18N
jButton3.setText("Back");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jButton4.setFont(new java.awt.Font("Traditional Arabic", 1, 12)); // NOI18N
jButton4.setText("save");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(23, 23, 23)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(44, 44, 44)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.LEADING, false)
.addComponent(cipher,
javax.swing.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE)
.addComponent(Plain)
.addComponent(ValueKey))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED )
.addComponent(jButton1)
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(91, 91, 91)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 122, Short.MAX_VALUE)
.addComponent(jButton2)
.addGap(76, 76, 76))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jButton5)
.addGap(148, 148, 148))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(145, 145, 145))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(27, 27, 27)
.addComponent(jLabel1))
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.BASELINE)
.addComponent(ValueKey, javax.swing.GroupLayout.PREFERRED_SIZE, 42,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1))))
.addGap(18, 18, 18)
.addComponent(jButton4)
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.BASELINE)
.addComponent(jLabel2)
.addComponent(Plain, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jButton5)
.addGap(59, 59, 59)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.LEADING)
.addComponent(jLabel3)
.addComponent(cipher, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED )
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.LEADING)
.addComponent(jButton2)
.addComponent(jButton3))
);
pack();
}// </editor-fold>
private void ValueKeyActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void cipherActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
LFSR lfsr = new LFSR();//untuk memanggil kelas lfsr
key = lfsr.generateKey(13);//memanggil method generate key pada kelas lfsr
ValueKey.setText(key);
}
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
plainteks = Plain.getText();
enkripsi = VigenereLFSR.encrypt(plainteks, ValueKey.getText());
cipher.setText(enkripsi);
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
TampilanutamavigenereLFSR menu = new TampilanutamavigenereLFSR();
menu.show();
this.dispose(); // TODO add your handling code here:
}
FileWriter fw = null;
try {
String nmfile = "cipherteks.txt";
fw = new FileWriter(nmfile);
BufferedWriter bw = new BufferedWriter(fw);
String isiText="";
String nilaiN="";
isiText = cipher.getText();
bw.write(isiText);
bw.newLine();
bw.close();
fw.close();
JOptionPane.showMessageDialog(rootPane, "Cipherteks disimpan di D:\\vigenerecipherlfsr");
}
catch (IOException ex) {
Logger.getLogger(Enkripsi.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
FileWriter fw = null;
try {
String nmfile = "Key.txt";
fw = new FileWriter(nmfile);
BufferedWriter bw = new BufferedWriter(fw); //Membuat objek untuk memils file
String isiText="";
bw.write(isiText);
bw.close();
fw.close();
JOptionPane.showMessageDialog(rootPane, "nilai key di simpan di D:\\vigenerecipherlfsr");
}
catch (IOException ex) {
Logger.getLogger(Enkripsi.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.h tml
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Enkripsi.class.getName()).log(java .util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Enkripsi.class.getName()).log(java .util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Enkripsi.class.getName()).log(java .util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Enkripsi.class.getName()).log(java .util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Enkripsi().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField Plain;
private javax.swing.JTextField ValueKey;
private javax.swing.JTextField cipher;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenu jMenu4;
private javax.swing.JMenu jMenu5;
private javax.swing.JMenu jMenu6;
private javax.swing.JMenuBar jMenuBar2;
private javax.swing.JMenuBar jMenuBar3;
private javax.swing.JTextField jTextField2;
// End of variables declaration
}
Dekripsi.java /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package vigenerecipherlfsr;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author rimavirgie
*/
public class Dekripsi extends javax.swing.JFrame {
/**
* Creates new form Dekripsi
*/
public Dekripsi() {
initComponents();
this.setLocationRelativeTo(getRootPane());//untuk menampilkan ketengah
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
txtcipher = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
txtkey = new javax.swing.JTextField();
jButton2 = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
txtdekrip = new javax.swing.JTextField();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Ciphertext");
jButton1.setFont(new java.awt.Font("Traditional Arabic", 1, 12)); // NOI18N
jButton1.setText("Browse");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
txtcipher.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtcipherActionPerformed(evt);
}
});
jLabel2.setFont(new java.awt.Font("Traditional Arabic", 1, 12)); // NOI18N
jLabel2.setText("Key");
jButton2.setFont(new java.awt.Font("Traditional Arabic", 1, 12)); // NOI18N
jButton2.setText("Dekripsi");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jLabel3.setText("Plaintext");
jButton3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jButton3.setText("Back");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jButton4.setFont(new java.awt.Font("Traditional Arabic", 1, 12)); // NOI18N
jButton4.setText("Browse");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap())))))
.addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(162, 162, 162)
.addComponent(jButton2))
.addGroup(layout.createSequentialGroup()
.addGap(56, 56, 56)
.addComponent(jButton3)))
.addGap(0, 0, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(20, 20, 20)
.addComponent(jLabel1))
.addGroup(layout.createSequentialGroup()
.addGap(12, 12, 12)
.addComponent(txtcipher, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(17, 17, 17)
.addComponent(jButton4)))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.TRAILING)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(txtkey, javax.swing.GroupLayout.PREFERRED_SIZE, 34,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(5, 5, 5))))
.addGap(18, 18, 18)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 52, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.BASELINE)
.addComponent(jLabel3)
.addComponent(txtdekrip, javax.swing.GroupLayout.PREFERRED_SIZE, 65,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3)
.addGap(14, 14, 14))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
FileChooser file = new FileChooser();
try {
fil = file.Browse();
} catch (IOException ex) {
}
txtkey.setText(fil);
}
private void txtcipherActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
VigenereLFSR dekripsi = new VigenereLFSR();
dekrip = dekripsi.decrypt(txtcipher.getText(), txtkey.getText());
txtdekrip.setText(dekrip);
// TODO add your handling code here:
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
TampilanutamavigenereLFSR menu = new TampilanutamavigenereLFSR();
menu.show();
this.dispose(); // TODO add your handling code here:
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
FileChooser file = new FileChooser();
try {
fil = file.Browse();
} catch (IOException ex) {
}
txtcipher.setText(fil);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.h tml
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Dekripsi.class.getName()).log(java .util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Dekripsi.class.getName()).log(java .util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger.getLogger(Dekripsi.class.getName()).log(java .util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Dekripsi.class.getName()).log(java .util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Dekripsi().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JTextField txtcipher;
private javax.swing.JTextField txtdekrip;
private javax.swing.JTextField txtkey;
// End of variables declaration
}
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package vigenerecipherlfsr;
/**
*
* @author rimavirgie
*/
public class About extends javax.swing.JFrame {
/**
* Creates new form About
*/
public About() {
initComponents();
this.setLocationRelativeTo(getRootPane());//untuk menampilkan ketengah
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
jLabel1.setText("APLIKASI INI DIGUNAKAN UNTUK ");
jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
jLabel2.setText(" MENJAGA KEAMANAN PESAN ");
jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
jLabel3.setText("AGAR LEBIH TERJAGA KERAHASIANNYA APLIKASI INI DIRANCANG");
jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
jLabel4.setText(" UNTUK MEMENUHI TUGAS AKHIR DI FAKULTAS S1 ILMU KOMPUTER");
jLabel5.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
jButton1.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jButton1.setText("OK");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel7.setIcon(new
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(54, 54, 54)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.LEADING)
.addComponent(jLabel3)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel2))
.addComponent(jLabel4)))
.addGroup(layout.createSequentialGroup()
.addGap(63, 63, 63)
.addComponent(jLabel5)
.addGap(61, 61, 61)
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(20, Short.MAX_VALUE))
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(198, 198, 198))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.BASELINE)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel4)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(73, 73, 73)
.addComponent(jLabel5)
.addContainerGap(167, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED )
.addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel7,
javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addComponent(jButton1)
.addGap(12, 12, 12))))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.h tml
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(About.class.getName()).log(java.ut il.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(About.class.getName()).log(java.ut il.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(About.class.getName()).log(java.ut il.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(About.class.getName()).log(java.ut il.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new About().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
// End of variables declaration
}
LFSR.java
VigenereLFSR.java /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package vigenerecipherlfsr;
/**
*
* @author rimavirgie
*/
public class VigenereLFSR {
private static final String table =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.";
public static String encrypt(String plain, String key){
key = key + plain;
String cipher = "";
int i, p, k, c;
for (i = 0; i < plain.length(); i++) {
p = table.indexOf(plain.charAt(i));
c = (p + k) % table.length();
cipher = cipher + table.charAt(c);
}
return cipher;
}
public static String decrypt(String cipher, String key){
String plain = "";
int i, p, k, c;
for (i = 0; i < cipher.length(); i++) {
c = table.indexOf(cipher.charAt(i));
k = table.indexOf(key.charAt(i));
p = (c - k) % table.length();
if (p < 0)
p = p + table.length();
plain = plain + table.charAt(p);
key = key + table.charAt(p);
}
return plain;
}
static class LFSR {
private final boolean[] b = new boolean[32 + 1];
public LFSR() {
int seed = (int)System.currentTimeMillis();
for(int i = 0; i < 32; i++)
b[i] = (((1 << i) & seed) >>> i) == 1;
}
public String generateKey(int length) {
String key = "";
int t = 0;
for(int i = 0; i < 32; i++)
t |= (b[i] ? 1 : 0) << i;
if (t < 0)
t++;
int x = t % table.length();
if (x < 0)
x += table.length();
key += table.charAt(x);
b[32] = false;
b[32] ^= b[31];
b[32] ^= b[30];
b[32] ^= b[10];
b[32] ^= b[0];
for(int i = 0; i < 32; i++)
b[i] = b[i + 1];
}
return key;
}
}
public static void main(String[] args) {
String plain, key, cipher, decrypted;
plain = "Vigenere with LFSR";
LFSR r = new LFSR();
key = r.generateKey(13);
cipher = encrypt(plain, key);
decrypted = decrypt(cipher, key);
System.out.println("plaintext = " + plain);
System.out.println("ciphertext = " + cipher);
System.out.println("decryptedtext = " + decrypted);
}
}
FileChooser.java /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package vigenerecipherlfsr;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
/**
*
* @author rimavirgie
*/
public class FileChooser {
public static String Browse() throws FileNotFoundException, IOException {
String str = "";
int returnVal = chooser.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION) {
BufferedReader br = null;
File f = chooser.getSelectedFile();
br = new BufferedReader(new FileReader(f));
String st="";
while((st=br.readLine())!=null){
str += st;
}
br.close();
}
return str;
}
}
MenuHelp.java /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package vigenerecipherlfsr;
public class MenuHelp extends javax.swing.JFrame {
/**
* Creates new form MenuHelp
*/
public MenuHelp() {
initComponents();
this.setLocationRelativeTo(getRootPane());//untuk menampilkan ketengah
}
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel2 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
jLabel2.setText("jLabel2");
jButton1.setText("jButton1");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel1.setText("Tampilan menu enkripsi");
jLabel3.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel4.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel4.setText("2.Plaintext : masukkan pesan");
jLabel5.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel5.setText("3.Ciphertext : hasil enkripsi pesan");
jLabel6.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel6.setText("Tampilan menu dekripsi");
jLabel7.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel7.setText("1.Ciphertext : masukkan pesan");
jLabel8.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel8.setText("2.Key : bangkitkan kunci");
jLabel9.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel9.setText("3.Plaintext : hasil dekrip pesan");
jLabel10.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel10.setText("Untuk keterangan lebih lanjut bisa mengirimkan pesan ke email");
jLabel11.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel11.setForeground(new java.awt.Color(0, 204, 255));
jLabel11.setText("[email protected]");
jButton2.setText("Kembali");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
.addGap(71, 71, 71) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen t.LEADING)
.addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 165,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGap(71, 71, 71)
.addComponent(jButton2)))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(13, 13, 13)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED )
.addComponent(jLabel3)
.addGap(13, 13, 13)
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED )
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(30, 30, 30)
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED )
.addComponent(jLabel7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED )
.addComponent(jLabel8)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED )
.addGap(18, 18, 18)
.addComponent(jLabel10)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED )
.addComponent(jLabel11)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
TampilanutamavigenereLFSR menu = new TampilanutamavigenereLFSR();
menu.show();
this.dispose();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.h tml
*/
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MenuHelp.class.getName()).log(java .util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MenuHelp.class.getName()).log(java .util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MenuHelp.class.getName()).log(java .util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(MenuHelp.class.getName()).log(java
.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MenuHelp().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
// End of variables declaration