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 相关文章推荐
php动态生成JavaScript代码
Mar 09 PHP
使用PHP提取视频网站页面中的FLASH地址的代码
Apr 17 PHP
PHP JSON 数据解析代码
May 26 PHP
php防止SQL注入详解及防范
Nov 12 PHP
PHP反射机制用法实例
Aug 28 PHP
PHP动态页生成静态页的3种常用方法
Nov 13 PHP
PHP获取当前完整URL地址的函数
Dec 21 PHP
php+mysqli数据库连接的两种方式
Jan 28 PHP
PHP中set_include_path()函数相关用法分析
Jul 18 PHP
Laravel接收前端ajax传来的数据的实例代码
Jul 20 PHP
PHP编程实现微信企业向用户付款的方法示例
Jul 26 PHP
定位地理位置PHP判断员工打卡签到经纬度是否在打卡之内
May 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
php 验证码实例代码
2010/06/01 PHP
使用php验证复选框有效性的示例
2013/11/13 PHP
PHP aes (ecb)解密后乱码问题
2015/06/22 PHP
php遍历、读取文件夹中图片并分页显示图片的方法
2016/11/15 PHP
Laravel框架Request、Response及Session操作示例
2019/05/06 PHP
定时器(setTimeout/setInterval)调用带参函数失效解决方法
2013/03/26 Javascript
jquery实现手风琴效果实例代码
2013/11/15 Javascript
jquery插件推荐浏览器嗅探userAgent
2014/11/09 Javascript
jQuery中click事件用法实例
2014/12/26 Javascript
Jquery把获取到的input值转换成json
2017/05/15 jQuery
使用Angular-CLI构建NPM包的方法
2018/09/07 Javascript
React如何实现浏览器打印部分内容详析
2019/05/19 Javascript
为nuxt项目写一个面包屑cli工具实现自动生成页面与面包屑配置
2019/09/29 Javascript
[01:13:59]LGD vs Mineski Supermajor 胜者组 BO3 第三场 6.5
2018/06/06 DOTA
[58:32]EG vs Liquid 2018国际邀请赛小组赛BO2 第一场 8.18
2018/08/19 DOTA
python获取beautifulphoto随机某图片代码实例
2013/12/18 Python
基于Python pip用国内镜像下载的方法
2018/06/12 Python
Python代码块批量添加Tab缩进的方法
2018/06/25 Python
Python实现EXCEL表格的排序功能示例
2019/06/25 Python
Python中os模块功能与用法详解
2020/02/26 Python
Python爬虫与反爬虫大战
2020/07/30 Python
python爬虫中PhantomJS加载页面的实例方法
2020/11/12 Python
Vans荷兰官方网站:美国南加州的原创极限运动潮牌
2018/01/23 全球购物
伦敦剧院及景点门票:Encore Tickets
2018/07/01 全球购物
美国高级音响品牌:Master&Dynamic
2018/07/05 全球购物
Perfume’s Club中文官网:西班牙美妆在线零售品牌
2020/08/24 全球购物
医学院学生求职简历的自我评价
2013/10/24 职场文书
安全承诺书范文
2014/03/26 职场文书
学习考察心得体会
2014/09/04 职场文书
民事辩护词范文
2015/05/21 职场文书
捐书仪式主持词
2015/07/04 职场文书
教师素质教育心得体会
2016/01/19 职场文书
接触艺术对孩子学习思维有益
2019/08/06 职场文书
导游词之南京中山陵
2019/11/27 职场文书
我对PyTorch dataloader里的shuffle=True的理解
2021/05/20 Python
python对文档中元素删除,替换操作
2022/04/02 Python