📄 playfair1.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. *//* * playfair1.java * * Created on Apr 20, 2009, 1:45:32 AM */package pf;/** * * @author mawaal */public class playfair1 extends javax.swing.JFrame { char key[][] = new char[5][5];public javax.swing.JFileChooser src,des; public String befor="",after=""; int srcInt,desInt; java.io.File srcFile,desFile; java.io.FileInputStream read=null; java.io.FileOutputStream write=null; /** Creates new form playfair1 */ public playfair1() { initComponents(); des=new javax.swing.JFileChooser(); src=new javax.swing.JFileChooser(); }void getkey(){ String s =txtKey.getText(); for(int i = 0; i < s.length(); i++){ char ch = s.charAt(i); if(ch<'a' || ch>'z' ){ javax.swing.JOptionPane.showMessageDialog(null,"Incorrect Key"); } } char c[] = s.toCharArray(); char c1[] = new char[25]; int n = 0; for(int i = 0; i<c.length; i++){ boolean flag = true; if(c[i]=='j'){c[i]='i';} for(int j = 0; j < i; j++) { if( c[i] == c[j]){ flag = false; continue; } } if(flag){ c1[n] = c[i]; n++; } } char c2[] = new char[25]; int t=0; for(int m='a';m<='z';m++) { boolean flag1 = true; if(m =='j'){ continue; } char r = (char)m; for(int i = 0; i < c.length; i++){ if(c[i] == r){ flag1 = false; } } if(flag1 == true){ c1[n] = r; n++; } } int z =0; for( int i = 0; i < 5; i++){ for(int j = 0; j < 5; j++){ key[i][j] = c1[z]; z++; } } char l[] = new char[25]; int e = 0; for( int i = 0; i < 5; i++){ for(int j = 0; j < 5; j++){ l[e] = key[i][j]; e++; System.out.print(key[i][j]); } System.out.println(); } } /** 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">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); txtKey = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); srcPath = new javax.swing.JTextField(); desPath = new javax.swing.JTextField(); srcBrowse = new javax.swing.JButton(); desBrowse = new javax.swing.JButton(); Encode = new javax.swing.JButton(); Decode = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setBackground(new java.awt.Color(255, 255, 255)); setResizable(false); jLabel1.setFont(new java.awt.Font("Comic Sans MS", 1, 11)); jLabel1.setText("Key"); txtKey.setFont(new java.awt.Font("Comic Sans MS", 1, 11)); txtKey.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { txtKeyActionPerformed(evt); } }); txtKey.addFocusListener(new java.awt.event.FocusAdapter() { public void focusLost(java.awt.event.FocusEvent evt) { txtKeyFocusLost(evt); } }); jLabel2.setFont(new java.awt.Font("Comic Sans MS", 1, 11)); jLabel2.setText("In put File "); jLabel3.setFont(new java.awt.Font("Comic Sans MS", 1, 11)); jLabel3.setText("Destination File"); srcPath.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); srcPath.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { srcPathActionPerformed(evt); } }); desPath.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); srcBrowse.setFont(new java.awt.Font("Comic Sans MS", 1, 11)); srcBrowse.setText("Browse"); srcBrowse.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { srcBrowseActionPerformed(evt); } }); desBrowse.setFont(new java.awt.Font("Comic Sans MS", 1, 11)); desBrowse.setText("Browse"); desBrowse.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { desBrowseActionPerformed(evt); } }); Encode.setFont(new java.awt.Font("Comic Sans MS", 1, 11)); Encode.setText("Encode"); Encode.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { EncodeActionPerformed(evt); } }); Decode.setFont(new java.awt.Font("Comic Sans MS", 1, 11)); Decode.setText("Decode"); Decode.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { DecodeActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addComponent(Encode) .addGap(26, 26, 26) .addComponent(Decode)) .addComponent(desPath, javax.swing.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE))) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(32, 32, 32) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(srcPath, javax.swing.GroupLayout.DEFAULT_SIZE, 355, Short.MAX_VALUE) .addComponent(txtKey, javax.swing.GroupLayout.DEFAULT_SIZE, 355, Short.MAX_VALUE)))) .addGap(12, 12, 12) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(desBrowse, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE) .addComponent(srcBrowse, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(35, 35, 35) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(txtKey, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(srcPath, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(srcBrowse, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(desPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(desBrowse)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Encode) .addComponent(Decode)) .addGap(44, 44, 44)) ); pack(); }// </editor-fold>//GEN-END:initComponents private void txtKeyFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtKeyFocusLost }//GEN-LAST:event_txtKeyFocusLost private void txtKeyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtKeyActionPerformed }//GEN-LAST:event_txtKeyActionPerformed private void srcPathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_srcPathActionPerformed return; // TODO add your handling code here:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -