⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 移位密码.txt

📁 JAVA编写的有用户界面的移位密码实现代码
💻 TXT
字号:
import java.awt.*;
import java.awt.event.*;
public class JMJM extends WindowAdapter implements ActionListener,ItemListener
{
	Label l1=new Label("输入:"),l2=new Label("加密:"),l3=new Label("解密:"),l4=new Label("密钥:");
	Frame f;
	TextField t1=new TextField(55),t2=new TextField(55),t3=new TextField(55),t4=new TextField(20);
	Button b1=new Button("加密"),b2=new Button("解密"),b3=new Button("清屏");
	Choice c1;
	Panel p1,p2,p3,p4,p5,p6,p7,p8,p9;
	public void display(){
    f=new Frame("加密算法 宋鹏 20042170 ");
	f.setSize(480,200);
	f.setLocation(200,140);
	f.setBackground(Color.lightGray);
	f.setLayout(new BorderLayout());
	tiajiazujian();
	f.setVisible(true);
	} 
	public void tiajiazujian(){
	c1=new Choice();
	c1.add("移位算法");c1.add("仿射算法");c1.add("维吉尼亚算法");c1.add("置换算法");
	c1.addItemListener(this);
	f.add(c1,"North");
	p1=new Panel();
	p3=new Panel();
	f.add(p3,"Center");
	p3.setLayout(new FlowLayout());
	p3.add(l1);p3.add(t1);p3.add(l2);p3.add(t2);p3.add(l3);p3.add(t3);
	p2=new Panel();
	f.add(p2,"South");
	p2.setLayout(new GridLayout(1,5));
	p2.add(l4);p2.add(t4);p2.add(b1);p2.add(b2);p2.add(b3);
	b1.addActionListener(this);
	b2.addActionListener(this);
	b3.addActionListener(this);
	}
	public void actionPerformed(ActionEvent e){
	if (e.getSource()==b3){
	t1.setText(" ");t2.setText(" ");t3.setText(" ");
	}
	if (e.getSource()==b1)
	{
		jiamisuanfa();
	}
	
	if(e.getSource()==b2){
		jiemisuanfa();
	}
	}
	public void itemStateChanged(ItemEvent e){
	}
	public void jiamisuanfa(){
	String s1;
	String s2;
	char zifu[];
    s1=t1.getText();
	s2=t4.getText();
	int a;
	a=Integer.parseInt(s2);
	zifu = s1.toCharArray();
	 for (int i = 0;i<zifu.length ;i++ )
	 {  
		 zifu[i]=(char)(((zifu[i]-'a'+a)%26)+'a');
		
	 }
	String s3=new String(zifu);
	t2.setText(s3);
}
    
	public void jiemisuanfa(){
	String s1;
	String s2;
	char zifu[];
    s1=t2.getText();
	s2=t4.getText();
	int a;
	a=Integer.parseInt(s2);
	zifu = s1.toCharArray();
	 for (int i = 0;i<zifu.length ;i++ )
	 {  
		 zifu[i]=(char)(((zifu[i]-'a'-a)%26)+'a');
		
	 }
	String s3=new String(zifu);
	t3.setText(s3);
}


public static void main(String arg[])
	{
	JMJM ob=new JMJM();
	ob.display();
	}
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -