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

📄 caser.txt

📁 这是密码学软件源码,一个小程序的源码,caser密码
💻 TXT
字号:
import java.awt.*;
import java.awt.event.*;
import java.util.*;

 public class Caser 
{
	 public static void main(String args[])
	 {
	 	new caser1();
	 }
} 
 class caser1 implements ItemListener,ActionListener 
 {
 		int key,statues=0 ;
 		String s,t;
 		Frame fr=new Frame();
		Label L1=new Label("明文:                                                                           ",Label.LEFT);
		Label L2=new Label("密文:",Label.LEFT );
		CheckboxGroup Ch=new CheckboxGroup();
		Checkbox c1=new Checkbox("加密",true,Ch);
		Checkbox c2=new Checkbox("解密",false,Ch);
		Label L3=new Label("密钥  :");
		Button b1=new Button("清空");
		Button b2=new Button("加/解密");
		TextArea mingwen=new TextArea(6,50);
		TextArea miwen=new TextArea(6,50);
		TextField password=new TextField(20);
		Dialog dialog=new Dialog(fr,"凯撒密码");
		
 	caser1()
	{
		dialog.addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent e)
			{
				System.exit(0);
			}
		});
		c1.addItemListener(this);
		
		c2.addItemListener(this);
		
		dialog.setLayout(new FlowLayout(FlowLayout.LEFT,5,10));
	 	dialog.add(L1);
	 	dialog.add(c1);
		dialog.add(c2);
		dialog.add(mingwen);
		
		dialog.add(L2);
		dialog.add(miwen);
		dialog.add(L3);
		dialog.add(password);
		dialog.add(b1);
		b1.addActionListener(this);
		b2.addActionListener(this);
		dialog.add(b2); 
		dialog.pack();
		dialog.setSize(400,420);
		dialog.setVisible(true);
	}
	static String caserKey(String str,int key )
 	{
 	 	int len=str.length();
 	 	int statue=1;
 		char a[]=new char[len];
 		a=str.toCharArray();
 		for(int i=0;i<len;i++)
 		{
 	 	 if((a[i]<'a'&&a[i]>'Z'||a[i]>'z'||a[i]<'A')) statue=2;
 	 
 		}
 	 	if(statue==1)
 		{
 			for(int i=0;i<len;i++)
 			{
 				if(a[i]>='a'&&a[i]<='z')
 				a[i]=(char)('a'+(a[i]-'a'+key%26+26)%26);
 				if(a[i]>='A'&&a[i]<='Z')
 				a[i]=(char)('A'+(a[i]-'A'+key%26+26)%26);
 			}
 			
 		}
 		
 		else
 		{
 			for(int i=0;i<len;i++)
 			{
 				a[i]=(char)(a[i]+key);
 			}
 		}
 		String result=new String(a);
 		return result;	 
 		
 		
 	}
public void itemStateChanged(ItemEvent e)
	{
		
		if(e.getSource()==c2) 
		{	 
			statues=1;
		}
		if(e.getSource()==c1)
		{	 
			statues=0;
		}
	} 
public void actionPerformed(ActionEvent e) 
{
	if(e.getSource() == b1)
	{
	mingwen.setText("");	
	miwen.setText("");
	password.setText("");
	}
	if(e.getSource()==b2)
	{
	 	if(statues==0){
	 		s=mingwen.getText();
			key=Integer.parseInt(password.getText());
			t=caserKey(s ,key); 
			miwen.setText(t);
			}
		if(statues==1)
		{
			s=miwen.getText();
			key= Integer.parseInt(password.getText());
			t=caserKey(s,-key);
			mingwen.setText(t);
		}
	}
}
}	
	

		
		      
		

⌨️ 快捷键说明

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