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

时间:2021-05-28

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

packagelockunlock;

importJava.awt.*;
importjava.awt.event.*;
importjava.Applet.*;
importjavax.Swing.*;
importjava.util.*;
publicclassLockUnlockextendsJApplet{
privatebooleanisStandalone=false;
//Getaparametervalue
publicStringgetParameter(Stringkey,Stringdef){
returnisStandalone?System.getProperty(key,def):
(getParameter(key)!=null?getParameter(key):def);
}

//Constructtheapplet
publicLockUnlock(){
}
//Initializetheapplet
publicvoidinit(){
try{
jbInit();
}
catch(Exceptione){
e.printStackTrace();
}
}
//Componentinitialization
privatevoidjbInit()throwsException{
contentPane=(JPanel)this.getContentPane();
jLabel1.setText("String");
jLabel1.setBounds(newRectangle(35,36,57,21));
contentPane.setLayout(null);
this.setSize(newDimension(400,300));
jLabel2.setText("Stringlength");
jLabel2.setBounds(newRectangle(29,73,69,22));
jTextField1.setText("");
jTextField1.setBounds(newRectangle(108,40,166,17));
jTextField2.setText("");
jTextField2.setBounds(newRectangle(107,72,56,21));
jButton1.setBounds(newRectangle(30,236,137,27));
jButton1.setText("Exercise3");
jButton1.addActionListener(newLockUnlock_jButton1_actionAdapter(this));
jButton2.setBounds(newRectangle(218,237,131,27));
jButton2.setText("Exercise4");
jButton2.addActionListener(newLockUnlock_jButton2_actionAdapter(this));
jTextField3.setText("");
jTextField3.setBounds(newRectangle(106,105,58,21));
jLabel3.setText("MoShu");
jLabel3.setBounds(newRectangle(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);

}
//GetAppletinformation
publicStringgetAppletInfo(){
return"AppletInformation";
}
//Getparameterinfo
publicString[][]getParameterInfo(){
returnnull;
}
//Mainmethod
publicstaticvoidmain(String[]args){
LockUnlockapplet=newLockUnlock();
applet.isStandalone=true;
JFrameframe=newJFrame();
//EXIT_ON_CLOSE==3
frame.setDefaultCloseOperation(3);
frame.setTitle("AppletFrame");
frame.getContentPane().add(applet,BorderLayout.CENTER);
applet.init();
applet.start();
frame.setSize(400,320);
Dimensiond=Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((d.width-frame.getSize().width)/2,(d.height-frame.getSize().height)/2);
frame.setVisible(true);
}

//staticinitializerforsettinglook&feel
static{
try{
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
catch(Exceptione){
}
}
//DeclareDataMember
intindex;

//-----------------------------------------------------
JPanelcontentPane;
JLabeljLabel1=newJLabel();
JLabeljLabel2=newJLabel();
JTextFieldjTextField2=newJTextField();
JTextFieldjTextField1=newJTextField();
JButtonjButton1=newJButton();
JButtonjButton2=newJButton();
JTextFieldjTextField3=newJTextField();
JLabeljLabel3=newJLabel();

//----------------------N!------------------------------
publicintfunction(intN){
if(N==1)
return1;
else{
returnN*function(N-1);
/*不是RETURNfunction(N-1);
而是N*function(N-1);*/
}
}
//-----------用递归法求一个串的全排列-----------------------
publicvoidArrange(Stringprefix,Stringsuffix,int[]Array){
StringnewPrefix,newSuffix;
intnumOfChars=suffix.length();
if(numOfChars==1){
Array[index]=Integer.parseInt(prefix+suffix);
index++;
}
else{
for(inti=1;i<=numOfChars;i++){
newSuffix=suffix.substring(1,numOfChars);
newPrefix=prefix+suffix.charAt(0);
Arrange(newPrefix,newSuffix,Array);
suffix=newSuffix+suffix.charAt(0);
}
}
}
//----------ArrangeFromtheMintotheMax------------------

//-------------------Findtheaimnumber----------------------
publicintFindAim(intaim,int[]Array){
booleanisFound=false;
intlocation=0;
intlength=Array.length;
for(inti=0;i<length;i++){
if(Array[i]==aim){
location=i;
isFound=true;
}
}
if(isFound)
returnlocation;
else
System.out.println("NotFound");
returnlocation;

}

//------------------CreatString-------------------------------
publicStringCreatString(intlength){
StringBufferBufString=newStringBuffer();
for(inti=1;i<=length;i++){
BufString.append(i);
}
returnBufString.toString();
}
//-----------OutPutResult--------------------
publicvoidOutPutResult1(){
index=0;//clearto0
StringAimString,prefix;
AimString=jTextField1.getText();
intLength=AimString.length();
StringstrLength=String.valueOf(Length);
intAim=Integer.parseInt(AimString);

int[]EachArrange=newint[this.function(Length)];
jTextField2.setText(strLength);
prefix="";//MakeanemptyString
if(AimString.length()>2&&
AimString.length()<9&&AimString!=""){
Arrange(prefix,AimString,EachArrange);
//RankForArrange(EachArrange);
Arrays.sort(EachArrange);
Stringresult=String.valueOf(FindAim(Aim,EachArrange));
jTextField3.setText(result);
}
else{
System.out.println("YourStringistooshort");
}
}

//----------Outputresult2---------------------
publicvoidOutPutRestlt2(){
index=0;//Letindexcomebackto0
StringstrLength,strMoShu,
AimString,prefix,suffix;
intLength,MoShu,limit;
strLength=jTextField2.getText();
strMoShu=jTextField3.getText();
Length=Integer.parseInt(strLength);
MoShu=Integer.parseInt(strMoShu);
limit=function(Length);
int[]EachArrange=newint[this.function(Length)];
if(Length>2&&Length<9&&
strLength!=""&&strMoShu!=""
&&MoShu<limit){
prefix="";
suffix=CreatString(Length);
Arrange(prefix,suffix,EachArrange);
Arrays.sort(EachArrange);
StringstrResult=String.valueOf(EachArrange[MoShu]);
jTextField1.setText(strResult);
}
else
System.out.println("InputOufMoShu,Tryagain");
}

voidjButton1_actionPerformed(ActionEvente){
this.OutPutResult1();
}

voidjButton2_actionPerformed(ActionEvente){
this.OutPutRestlt2();
}
//-----------------------------------------------------------

}

classLockUnlock_jButton1_actionAdapterimplementsjava.awt.event.ActionListener{
LockUnlockadaptee;

LockUnlock_jButton1_actionAdapter(LockUnlockadaptee){
this.adaptee=adaptee;
}
publicvoidactionPerformed(ActionEvente){
adaptee.jButton1_actionPerformed(e);
}
}

classLockUnlock_jButton2_actionAdapterimplementsjava.awt.event.ActionListener{
LockUnlockadaptee;

LockUnlock_jButton2_actionAdapter(LockUnlockadaptee){
this.adaptee=adaptee;
}
publicvoidactionPerformed(ActionEvente){
adaptee.jButton2_actionPerformed(e);
}
}

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章