java EJB 加密与解密原理的一个例子


Posted in PHP onJanuary 11, 2008

加密与解密原理的一个例子

package lockunlock; 

import Java.awt.*; 
import java.awt.event.*; 
import java.Applet.*; 
import javax.Swing.*; 
import java.util.*; 
public class LockUnlock extends JApplet { 
private boolean isStandalone = false; 
//Get a parameter value 
public String getParameter(String key, String def) { 
return isStandalone ? System.getProperty(key, def) : 
(getParameter(key) != null ? getParameter(key) : def); 

//Construct the applet 
public LockUnlock() { 

//Initialize the applet 
public void init() { 
try { 
jbInit(); 

catch(Exception e) { 
e.printStackTrace(); 


//Component initialization 
private void jbInit() throws Exception { 
contentPane = (JPanel) this.getContentPane(); 
jLabel1.setText("String"); 
jLabel1.setBounds(new Rectangle(35, 36, 57, 21)); 
contentPane.setLayout(null); 
this.setSize(new Dimension(400, 300)); 
jLabel2.setText("String length"); 
jLabel2.setBounds(new Rectangle(29, 73, 69, 22)); 
jTextField1.setText(""); 
jTextField1.setBounds(new Rectangle(108, 40, 166, 17)); 
jTextField2.setText(""); 
jTextField2.setBounds(new Rectangle(107, 72, 56, 21)); 
jButton1.setBounds(new Rectangle(30, 236, 137, 27)); 
jButton1.setText("Exercise 3"); 
jButton1.addActionListener(new LockUnlock_jButton1_actionAdapter(this)); 
jButton2.setBounds(new Rectangle(218, 237, 131, 27)); 
jButton2.setText("Exercise 4"); 
jButton2.addActionListener(new LockUnlock_jButton2_actionAdapter(this)); 
jTextField3.setText(""); 
jTextField3.setBounds(new Rectangle(106, 105, 58, 21)); 
jLabel3.setText("MoShu"); 
jLabel3.setBounds(new Rectangle(36, 106, 86, 18)); 
contentPane.add(jLabel1, null); 
contentPane.add(jButton2, null); 
contentPane.add(jButton1, null); 
contentPane.add(jLabel3, null); 
contentPane.add(jTextField2, null); 
contentPane.add(jLabel2, null); 
contentPane.add(jTextField3, null); 
contentPane.add(jTextField1, null); 


//Get Applet information 
public String getAppletInfo() { 
return "Applet Information"; 

//Get parameter info 
public String[][] getParameterInfo() { 
return null; 

//Main method 
public static void main(String[] args) { 
LockUnlock applet = new LockUnlock(); 
applet.isStandalone = true; 
JFrame frame = new JFrame(); 
//EXIT_ON_CLOSE == 3 
frame.setDefaultCloseOperation(3); 
frame.setTitle("Applet Frame"); 
frame.getContentPane().add(applet, BorderLayout.CENTER); 
applet.init(); 
applet.start(); 
frame.setSize(400,320); 
Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); 
frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2); 
frame.setVisible(true); 

//static initializer for setting look & feel 
static { 
try { 
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); 

catch(Exception e) { 


//Declare DataMember 
int index; 

//----------------------------------------------------- 
JPanel contentPane; 
JLabel jLabel1 = new JLabel(); 
JLabel jLabel2 = new JLabel(); 
JTextField jTextField2 = new JTextField(); 
JTextField jTextField1 = new JTextField(); 
JButton jButton1 = new JButton(); 
JButton jButton2 = new JButton(); 
JTextField jTextField3 = new JTextField(); 
JLabel jLabel3 = new JLabel(); 

//----------------------N!------------------------------ 
public int function(int N){ 
if(N==1) 
return 1; 
else{ 
return N*function(N-1); 
/*不是RETURN function(N-1); 
而是 N*function(N-1);*/ 


//-----------用递归法求一个串的全排列----------------------- 
public void Arrange(String prefix,String suffix,int[] Array){ 
String newPrefix,newSuffix; 
int numOfChars =suffix.length(); 
if(numOfChars==1){ 
Array[index]=Integer.parseInt(prefix+suffix); 
index++; 

else{ 
for(int i=1; i<=numOfChars;i++){ 
newSuffix=suffix.substring(1,numOfChars); 
newPrefix=prefix+suffix.charAt(0); 
Arrange(newPrefix,newSuffix,Array); 
suffix=newSuffix+suffix.charAt(0); 



//----------Arrange From the Min to the Max------------------ 
/*public void RankForArrange(int[] Array){ 
int bottom=Array.length-1 ; 
int temp; 
for(int i=bottom;i>0;i--){ 
for(int j=0;j<i;j++){ 
if(Array[j]>Array[j+1]){ 
temp =Array[j]; 
Array[j] =Array[j+1]; 
Array[j+1]=temp; 




*/ 
//-------------------Find the aim number---------------------- 
public int FindAim(int aim,int[] Array){ 
boolean isFound=false; 
int location=0; 
int length=Array.length ; 
for(int i=0;i<length;i++){ 
if(Array[i]==aim){ 
location=i; 
isFound =true; 


if(isFound) 
return location; 
else 
System.out.println("Not Found"); 
return location; 
/*在if里return 不行吗?*/ 

//------------------Creat String------------------------------- 
public String CreatString(int length){ 
StringBuffer BufString=new StringBuffer(); 
for(int i=1;i<=length;i++){ 
BufString.append(i) ; 

return BufString.toString(); 

//-----------OutPut Result-------------------- 
public void OutPutResult1(){ 
index = 0; //clear to 0 
String AimString, prefix; 
AimString = jTextField1.getText(); 
int Length = AimString.length(); 
String strLength = String.valueOf(Length); 
int Aim = Integer.parseInt(AimString); 
/* 方法.parseInt才是转换为int类型 
而不是.getInteger*/ 
int[] EachArrange = new int[this.function(Length)]; 
jTextField2.setText(strLength); 
prefix = ""; //Make an empty String 
if (AimString.length() > 2 && 
AimString.length() < 9 && AimString != "") { 
Arrange(prefix, AimString, EachArrange); 
//RankForArrange(EachArrange); 
Arrays.sort(EachArrange); 
String result = String.valueOf(FindAim(Aim, EachArrange)); 
jTextField3.setText(result); 

else { 
System.out.println("Your String is too short"); 

//----------Out put result 2--------------------- 
public void OutPutRestlt2(){ 
index=0;//Let index come back to 0 
String strLength, strMoShu, 
AimString, prefix,suffix; 
int Length, MoShu,limit; 
strLength = jTextField2.getText(); 
strMoShu = jTextField3.getText(); 
Length = Integer.parseInt(strLength); 
MoShu = Integer.parseInt(strMoShu); 
limit = function(Length); 
int[] EachArrange = new int[this.function(Length)]; 
if (Length > 2&&Length<9&& 
strLength!=""&&strMoShu!="" 
&&MoShu<limit) { 
prefix = ""; 
suffix =CreatString(Length); 
Arrange(prefix, suffix, EachArrange); 
Arrays.sort(EachArrange); 
String strResult=String.valueOf(EachArrange[MoShu]); 
jTextField1.setText(strResult); 

else 
System.out.println("Input Ouf MoShu, Try again") ; 

void jButton1_actionPerformed(ActionEvent e) { 
this.OutPutResult1(); 

void jButton2_actionPerformed(ActionEvent e) { 
this.OutPutRestlt2(); 

//----------------------------------------------------------- 

class LockUnlock_jButton1_actionAdapter implements java.awt.event.ActionListener { 
LockUnlock adaptee; 

LockUnlock_jButton1_actionAdapter(LockUnlock adaptee) { 
this.adaptee = adaptee; 

public void actionPerformed(ActionEvent e) { 
adaptee.jButton1_actionPerformed(e); 

class LockUnlock_jButton2_actionAdapter implements java.awt.event.ActionListener { 
LockUnlock adaptee; 

LockUnlock_jButton2_actionAdapter(LockUnlock adaptee) { 
this.adaptee = adaptee; 

public void actionPerformed(ActionEvent e) { 
adaptee.jButton2_actionPerformed(e); 

}

PHP 相关文章推荐
Apache2 httpd.conf 中文版
Dec 06 PHP
php开发工具之vs2005图解
Jan 12 PHP
php入门教程 精简版
Dec 13 PHP
通过5个php实例细致说明传值与传引用的区别
Aug 08 PHP
PIGCMS 如何关闭聊天机器人
Feb 12 PHP
列举PHP的Yii 2框架的开发优势
Jul 03 PHP
利用PHP绘图函数实现简单验证码功能的方法
Oct 18 PHP
php把时间戳转换成多少时间之前函数的实例
Nov 16 PHP
php使用 readfile() 函数设置文件大小大小的方法
Aug 11 PHP
PHP实现的多进程控制demo示例
Jul 22 PHP
PHP如何使用JWT做Api接口身份认证的实现
Feb 03 PHP
php redis setnx分布式锁简单原理解析
Oct 23 PHP
apache rewrite_module模块使用教程
Jan 10 #PHP
支持php4、php5的mysql数据库操作类
Jan 10 #PHP
让PHP支持页面回退的两种方法
Jan 10 #PHP
php下使用SMTP发邮件的代码
Jan 10 #PHP
ZF等常用php框架中存在的问题
Jan 10 #PHP
逐步提升php框架的性能
Jan 10 #PHP
在PHP中使用Sockets 从Usenet中获取文件
Jan 10 #PHP
You might like
地摊中国 - 珍藏老照片
2020/08/18 杂记
php下实现在指定目录搜索指定类型文件的函数
2008/10/03 PHP
PHP中auto_prepend_file与auto_append_file用法实例分析
2014/09/22 PHP
php中使用gd库实现下载网页中所有图片
2015/05/12 PHP
php获取一定范围内取N个不重复的随机数
2016/05/28 PHP
greybox——不开新窗口看新的网页
2007/02/20 Javascript
Jquery ajaxsubmit上传图片实现代码
2010/11/04 Javascript
javascript中数组中求最大值示例代码
2013/12/18 Javascript
简单谈谈javascript中的变量、作用域和内存问题
2015/08/30 Javascript
通过Tabs方法基于easyUI+bootstrap制作工作站
2016/03/28 Javascript
通过sails和阿里大于实现短信验证
2017/01/04 Javascript
浅谈js中startsWith 函数不能在任何浏览器兼容的问题
2017/03/01 Javascript
JSONP跨域请求
2017/03/02 Javascript
vue+web端仿微信网页版聊天室功能
2019/04/30 Javascript
Python3.6使用tesseract-ocr的正确方法
2018/10/17 Python
python json.loads兼容单引号数据的方法
2018/12/19 Python
Python设计模式之抽象工厂模式原理与用法详解
2019/01/15 Python
python实现年会抽奖程序
2019/01/22 Python
python 设置输出图像的像素大小方法
2019/07/04 Python
Python获取命令实时输出-原样彩色输出并返回输出结果的示例
2019/07/11 Python
python中使用np.delete()的实例方法
2021/02/01 Python
加拿大当代时尚服饰、配饰和鞋类专业零售商和制造商:LE CHÂTEAU
2017/10/06 全球购物
英国鹦鹉店:Parrot Essentials
2018/12/03 全球购物
远程调用的原理
2014/07/05 面试题
中文教师求职信
2014/02/22 职场文书
乡镇平安建设汇报材料
2014/08/25 职场文书
计生办班子群众路线教育实践活动个人对照检查材料思想汇报
2014/10/04 职场文书
2014年物业公司工作总结
2014/11/22 职场文书
公务员政审个人总结
2015/02/12 职场文书
学生逃课检讨书
2015/02/17 职场文书
认真学习保证书
2015/02/26 职场文书
2015年检察院个人工作总结
2015/05/20 职场文书
2015年预防青少年违法犯罪工作总结
2015/05/22 职场文书
2016年幼儿园庆六一开幕词
2016/03/04 职场文书
mysql 如何获取两个集合的交集/差集/并集
2021/06/08 MySQL
如何利用 CSS Overview 面板重构优化你的网站
2021/10/24 HTML / CSS