search
HomeBackend DevelopmentPHP TutorialAn example of java EJB encryption and decryption principles_PHP tutorial

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

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; inewSuffix=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;jif(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;iif(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;iBufString.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() 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&&LengthstrLength!=""&&strMoShu!="" 
&&MoShuprefix = ""; 
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); 

}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/318717.htmlTechArticle加密与解密原理的一个例子 packagelockunlock; importJava.awt.*; importjava.awt.event.*; importjava.Applet.*; importjavax.Swing.*; importjava.util.*; publicclassLockUnlocke...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Optimize PHP Code: Reducing Memory Usage & Execution TimeOptimize PHP Code: Reducing Memory Usage & Execution TimeMay 10, 2025 am 12:04 AM

TooptimizePHPcodeforreducedmemoryusageandexecutiontime,followthesesteps:1)Usereferencesinsteadofcopyinglargedatastructurestoreducememoryconsumption.2)LeveragePHP'sbuilt-infunctionslikearray_mapforfasterexecution.3)Implementcachingmechanisms,suchasAPC

PHP Email: Step-by-Step Sending GuidePHP Email: Step-by-Step Sending GuideMay 09, 2025 am 12:14 AM

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

How to Send Email via PHP: Examples & CodeHow to Send Email via PHP: Examples & CodeMay 09, 2025 am 12:13 AM

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

Advanced PHP Email: Custom Headers & FeaturesAdvanced PHP Email: Custom Headers & FeaturesMay 09, 2025 am 12:13 AM

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Guide to Sending Emails with PHP & SMTPGuide to Sending Emails with PHP & SMTPMay 09, 2025 am 12:06 AM

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use