/*************************************************** Copyright 2003 Darrell Johnson This file is part of Yu-gi-oh. Yu-gi-oh 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, or (at your option) any later version. Yu-gi-oh 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 Yu-gi-oh; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ****************************************************/ package vig; /** * * @author xz3zsf */ public class vig extends javax.swing.JApplet { /** Creates new form vig */ public vig() { initComponents(); initvar(); } void initvar(){ cipherset = 0; } /** 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. */ private void initComponents() {//GEN-BEGIN:initComponents jPanel1 = new javax.swing.JPanel(); jLabel8 = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel(); jRadioButton1 = new javax.swing.JRadioButton(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); jButton1 = new javax.swing.JButton(); jScrollPane2 = new javax.swing.JScrollPane(); jTextArea2 = new javax.swing.JTextArea(); jLabel5 = new javax.swing.JLabel(); jButton2 = new javax.swing.JButton(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); getContentPane().setLayout(null); jPanel1.setLayout(null); jPanel1.setBackground(new java.awt.Color(204, 204, 255)); jPanel1.add(jLabel8); jLabel8.setBounds(130, 0, 220, 60); jLabel1.setBackground(new java.awt.Color(51, 51, 255)); jLabel1.setFont(new java.awt.Font("SansSerif", 1, 14)); jLabel1.setForeground(new java.awt.Color(51, 51, 51)); jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel1.setText("The Vigga"); jLabel1.setVerticalAlignment(javax.swing.SwingConstants.TOP); jPanel1.add(jLabel1); jLabel1.setBounds(180, 0, 110, 20); jRadioButton1.setBackground(new java.awt.Color(204, 204, 255)); jRadioButton1.setText("Vigenere"); jRadioButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jRadioButton1ActionPerformed(evt); } }); jPanel1.add(jRadioButton1); jRadioButton1.setBounds(10, 50, 76, 24); jLabel2.setText("Choose a cipher"); jLabel2.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0))); jPanel1.add(jLabel2); jLabel2.setBounds(10, 30, 94, 18); jLabel3.setText("Keyword for encryption / decryption"); jLabel3.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0))); jPanel1.add(jLabel3); jLabel3.setBounds(10, 80, 203, 18); jTextField1.setFocusCycleRoot(true); jPanel1.add(jTextField1); jTextField1.setBounds(10, 100, 140, 20); jLabel4.setText("Text to encrypt/decrypt"); jLabel4.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0))); jPanel1.add(jLabel4); jLabel4.setBounds(10, 120, 140, 18); jTextArea1.setFocusCycleRoot(true); jScrollPane1.setViewportView(jTextArea1); jPanel1.add(jScrollPane1); jScrollPane1.setBounds(10, 140, 410, 100); jButton1.setBackground(new java.awt.Color(204, 204, 255)); jButton1.setText("Encrypt"); jButton1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jPanel1.add(jButton1); jButton1.setBounds(10, 244, 49, 20); jTextArea2.setEditable(false); jTextArea2.setFocusCycleRoot(true); jScrollPane2.setViewportView(jTextArea2); jPanel1.add(jScrollPane2); jScrollPane2.setBounds(10, 270, 410, 100); jPanel1.add(jLabel5); jLabel5.setBounds(160, 120, 310, 20); jButton2.setBackground(new java.awt.Color(204, 204, 255)); jButton2.setText("Decrypt"); jButton2.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); jButton2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jPanel1.add(jButton2); jButton2.setBounds(370, 244, 50, 20); jLabel6.setFont(new java.awt.Font("Dialog", 0, 10)); jLabel6.setText("Vigenere cipher encryption/decryption tool"); jLabel6.setVerticalAlignment(javax.swing.SwingConstants.TOP); jPanel1.add(jLabel6); jLabel6.setBounds(140, 20, 210, 14); jLabel7.setFont(new java.awt.Font("Dialog", 0, 10)); jLabel7.setText("Key needed for decryption"); jPanel1.add(jLabel7); jLabel7.setBounds(170, 30, 125, 14); getContentPane().add(jPanel1); jPanel1.setBounds(0, 0, 474, 402); }//GEN-END:initComponents private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // Add your handling code here: String key; String fieldtext; String ciphertext; char[] testkey; boolean valid = true; key = jTextField1.getText(); fieldtext = jTextArea1.getText(); if(cipherset <= 0){ jLabel5.setText("Select a cipher"); valid = false; } else if(key.length() < 1){ jLabel5.setText("Enter a keyword here"); valid = false; } else if(key.length() == 1){ jLabel5.setText("That's a pretty weak key. Try something longer"); valid = false; } else if (fieldtext.length() <= 1){ jLabel5.setText("Enter stuff to decrypt here"); valid = false; } else{ key = key.toLowerCase(); testkey = new char[key.length()]; testkey = key.toCharArray(); for(int i = 0; i < key.length(); i++){ if(testkey[i] < 97 || (testkey[i] > 122)){ jLabel5.setText("Invalid character in the keyword. Only letters!"); valid = false; } } if(valid){ Vigenere v = new Vigenere(key); jTextArea2.setText( v.decrypt(fieldtext) ); } } }//GEN-LAST:event_jButton2ActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // Add your handling code here: String key; String fieldtext; String ciphertext; char[] testkey; boolean valid = true; key = jTextField1.getText(); fieldtext = jTextArea1.getText(); if(cipherset <= 0){ jLabel5.setText("Select a cipher"); valid = false; } else if(key.length() < 1){ jLabel5.setText("Enter a keyword here"); valid = false; } else if(key.length() == 1){ jLabel5.setText("That's a pretty weak key. Try something longer"); valid = false; } else if (fieldtext.length() <= 1){ jLabel5.setText("Enter stuff to encrypt here"); valid = false; } else{ key = key.toLowerCase(); testkey = new char[key.length()]; testkey = key.toCharArray(); for(int i = 0; i < key.length(); i++){ if(testkey[i] < 97 || (testkey[i] > 122)){ jLabel5.setText("Invalid character in the keyword. Only letters!"); valid = false; } } if(valid){ Vigenere v = new Vigenere(key); jTextArea2.setText( v.encrypt(fieldtext) ); } } }//GEN-LAST:event_jButton1ActionPerformed private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed // Add your handling code here: cipherset = 1; }//GEN-LAST:event_jRadioButton1ActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel4; private javax.swing.JButton jButton2; private javax.swing.JTextArea jTextArea2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JRadioButton jRadioButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel2; private javax.swing.JButton jButton1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JLabel jLabel7; private javax.swing.JTextArea jTextArea1; private javax.swing.JPanel jPanel1; private javax.swing.JLabel jLabel6; private javax.swing.JTextField jTextField1; private javax.swing.JLabel jLabel5; // End of variables declaration//GEN-END:variables private int cipherset; }