置換加密算法_第1頁
置換加密算法_第2頁
置換加密算法_第3頁
置換加密算法_第4頁
置換加密算法_第5頁
已閱讀5頁,還剩2頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、精選優(yōu)質(zhì)文檔-傾情為你奉上import java.awt.*;import javax.swing.*;import java.awt.event.*;public class MainFrame extends JFrame/置換加密算法private JPanel panel1 = null;private JPanel panel2 = null;private JPanel panel11 = null;private JPanel panel12 = null;private JPanel panel13 = null;private JPanel panel14 = null;pr

2、ivate JPanel panel15 = null;private JPanel panel21 = null;private JPanel panel22 = null;private JPanel panel23 = null;private JPanel panel24 = null;private JPanel panel25 = null;private JLabel label1 = null;private JLabel label2 = null;private JLabel label3 = null;private JLabel label4 = null;privat

3、e JLabel label5 = null;private JLabel label6 = null;private JLabel label7 = null;private JLabel label8 = null;private JButton button1=null;private JButton button2=null;private JButton button3=null;private JButton button4=null;private JTextArea ta1 = null;private JTextArea ta2 = null;private JTextAre

4、a ta3 = null;private JTextArea ta4 = null;private JTextField tf1 = null;private JTextField tf2 = null;private Container container;private String text=null; /用于明文private String key1=null; /用于密鑰1private String cipher=null; /用于密文private String key2=null; /用于密鑰2public MainFrame () container = this.getCo

5、ntentPane();label1=new JLabel("置換加密");label2=new JLabel("置換解密");label3=new JLabel("明文:");label4=new JLabel("密鑰:");label5=new JLabel("密文:");label6=new JLabel("密文:");label7=new JLabel("密鑰:");label8=new JLabel("明文:");button

6、1 = new JButton("加密");button2 = new JButton("清空");button3 = new JButton("解密");button4 = new JButton("清空");button1.addActionListener(new ActionLis();button2.addActionListener(new ActionLis();button3.addActionListener(new ActionLis();button4.addActionListener(ne

7、w ActionLis();ta1= new JTextArea(3, 15);ta2= new JTextArea(3, 15);ta3= new JTextArea("<顯示解密結(jié)果>",3, 15);ta4= new JTextArea("<顯示解密結(jié)果>",3, 15);ta3.setLineWrap(true);ta3.setLineWrap(true);tf1 = new JTextField(10);tf2 = new JTextField(10);panel1 = new JPanel();panel2 = new

8、 JPanel();panel11 = new JPanel();panel12 = new JPanel();panel13 = new JPanel();panel14 = new JPanel();panel15 = new JPanel();panel21 = new JPanel();panel22 = new JPanel();panel23 = new JPanel();panel24 = new JPanel();panel25 = new JPanel();panel11.add(label1);panel12.add(label3);panel12.add(ta1);pan

9、el13.add(label4);panel13.add(tf1);panel14.add(button1);panel14.add(button2);panel15.add(label5);panel15.add(ta3);panel1.add(panel11);panel1.add(panel12);panel1.add(panel13);panel1.add(panel14);panel1.add(panel15);panel21.add(label2);panel22.add(label6);panel22.add(ta2);panel23.add(label7);panel23.ad

10、d(tf2);panel24.add(button3);panel24.add(button4);panel25.add(label8);panel25.add(ta4);panel2.add(panel21);panel2.add(panel22);panel2.add(panel23);panel2.add(panel24);panel2.add(panel25);panel1.setLayout(new GridLayout(5, 1); panel2.setLayout(new GridLayout(5, 1); container.add(panel1);container.add(

11、panel2);container.setLayout(new GridLayout(1, 2); this.setTitle("置換加密解密"); this.setSize(600, 500); this.setVisible(true);class ActionLis implements ActionListener public void actionPerformed(ActionEvent e) if (e.getSource() = button1) text=ta1.getText(); key1=tf1.getText(); Crypt c =new Cr

12、ypt(text,key1); ta3.setText(c.getcrypt(); else if (e.getSource() = button2) ta1.setText(""); tf1.setText(""); ta3.setText(""); else if (e.getSource() = button3) cipher=ta2.getText(); key2=tf2.getText(); Decrypt d =new Decrypt(cipher,key2); ta4.setText(d.gettext(); else

13、ta2.setText(""); tf2.setText(""); ta4.setText(""); public static void main(String args) new MainFrame();加密public class Crypt private String text,key,ctext,otext;private int ctextl,keyl;private char ch1,ch3,ch4;private int in1;private char ch2;private int ch2r;public Cry

14、pt(String text,String key) this.text=text;this.key=key;String ctext=text.replaceAll(" ","");/消去明文中空格ch1=ctext.toCharArray();ctextl=ctext.length(); keyl=key.length();if(ctextl%keyl=0)/設(shè)置二維數(shù)組行大小ch2r=ctextl/keyl;elsech2r=ctextl/keyl+1; ch2=new charch2rkeyl;for(int i=0,j=0;i<ch2r;

15、i+ )/明文存入二維數(shù)組中for(int k=0;k<keyl && j<ctextl;k+)ch2ik=ch1j; j+;in1=new intkeyl;Keys x=new Keys(key);in1=x.getkey();ch4=new charch2r*keyl;/存儲輸出的字符數(shù)組for(int i=0,k=0;i<keyl;i+) for(int j=0;j<ch2r && k<(ch2r*keyl);j+) ch4k=ch2jin1i; k+; otext=String.valueOf(ch4);String get

16、crypt()return otext;解密public class Decrypt private String cipher,key,otext;private int cipherl,keyl;private char ch1,ch3,ch4;private char ch2;private int ch2r;private int in;public Decrypt(String cipher,String key) this.cipher=cipher;this.key=key;cipherl=cipher.length();keyl=key.length();ch1=cipher.

17、toCharArray();if(cipherl%keyl=0)/設(shè)置二維數(shù)組行大小ch2r=cipherl/keyl;elsech2r=cipherl/keyl+1; in=new intkeyl;Keys x=new Keys(key);in=x.getkey();/*ch3=key.toCharArray();for(int i=0;i<keyl;i+) ini=Integer.parseInt(String.valueOf(ch3i);*/ch2=new charch2rkeyl;for(int i=0,k=0;i<keyl;i+) for(int j=0;j<ch2

18、r && k<cipherl;j+) ch2jini=ch1k; k+; ch4=new charch2r*keyl;for(int i=0,k=0;i<ch2r;i+) for(int j=0;j<keyl && k<(ch2r*keyl);j+) ch4k=ch2ij; k+; otext=String.valueOf(ch4);String gettext()return otext;public class Keys private String key;private char ch1,ch2;private int in;private int keyl;public Keys(String key) ch1=key.toCharArray();ch2=key.toCharArray();keyl=key.length();in=new intkeyl; char temp ;for(int i=0;i<keyl-1;i+) int k=i; for(int j=i+1;j<keyl;j+) if( ch

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論