TEA¼ÓÃÜËã·¨java°æ
Õâ¸öËã·¨¼òµ¥,¶øÇÒЧÂʸß,ÿ´Î¿ÉÒÔ²Ù×÷8¸ö×Ö½ÚµÄÊý¾Ý,¼ÓÃܽâÃܵÄKEYΪ16×Ö½Ú,¼´°üº¬4¸öintÊý¾ÝµÄintÐÍÊý×é,¼ÓÃÜÂÖÊýӦΪ8µÄ±¶Êý,Ò»°ã±È½Ï³£ÓõÄÂÖÊýΪ64,32,16,ÍÆ¼öÓÃ64ÂÖ.
Ô´´úÂëÈçÏÂ:
/** *//**
* TeaËã·¨
* ÿ´Î²Ù×÷¿ÉÒÔ´¦Àí8¸ö×Ö½ÚÊý¾Ý
* KEYΪ16×Ö½Ú,ӦΪ°üº¬4¸öintÐÍÊýµÄint[]£¬Ò»¸öintΪ4¸ö×Ö½Ú
* ¼ÓÃܽâÃÜÂÖÊýӦΪ8µÄ±¶Êý£¬ÍƼö¼ÓÃÜÂÖÊýΪ64ÂÖ
* */
public class Tea {
//¼ÓÃÜ
public byte[] encrypt(byte[] content, int offset, int[] key, int times){//timesΪ¼ÓÃÜÂÖÊý
int[] tempInt = byteToInt(content, offset);
int y = tempInt[0], z = tempInt[1], sum = 0, i;
int delta=0x9e3779b9; //ÕâÊÇËã·¨±ê×¼¸øµÄÖµ
int a = key[0], b = key[1], c = key[2], d = key[3];
for (i = 0; i £¼ times; i++) {
sum += delta;
y += ((z£¼£¼4) + a) ^ (z + sum) ^ ((z£¾£¾5) + b);
z += ((y£¼£¼4) + c) ^ (y + sum) ^ ((y£¾£¾5) + d);
}
tempInt[0]=y;
tempInt[1]=z;
return intToByte(tempInt, 0);
}
//½âÃÜ
public byte[] decrypt(byte[] encryptContent, int offset, int[] key, int times){
int[] tempInt = byteToInt(encryptContent, offset);
int y = tempInt[0], z = tempInt[1], sum = 0xC6EF3720, i;
int delta=0x9e3779b9; //ÕâÊÇËã·¨±ê×¼¸øµÄÖµ
int a = key[0], b = key[1], c = key[2], d = key[3];
for(i = 0; i £¼ times; i++) {
z -= ((y£¼£¼4) + c) ^ (y + sum) ^ ((y£¾£¾5) + d);
y -= ((z£¼£¼4) + a) ^ (z + sum) ^ ((z£¾£¾5) + b);
sum -= delta;
}
tempInt[0] = y;
tempInt[1] = z;
return intToByte(tempInt, 0);
}
//byte[]ÐÍÊý¾Ýת³Éint[]ÐÍÊý¾Ý
private int[] byteToInt(byte[] content, int offset){
int[] result = new int[content.length £¾£¾ 2]; //³ýÒÔ2µÄn´Î·½ == ÓÒÒÆnλ ¼´ content.length / 4 == content.length £¾£¾ 2
for(int i = 0, j = offset; j £¼ content.length; i++, j += 4){
result[i] = transform(content[j + 3]) | transform(content[j + 2]) £¼£¼ 8 |
transform(content[j + 1]) £¼£¼ 16 | (int)content[j] £¼£¼ 24;
}
return result;
}
//int[]ÐÍÊý¾Ýת³Ébyte[]ÐÍÊý¾Ý
private byte[] intToByte(int[] content, int offset){
byte[] result = new byte[content.length £¼£¼ 2]; //³ËÒÔ2µÄn´Î·½ == ×óÒÆnλ ¼´ conte
Ïà¹ØÎĵµ£º
JAVA·´Éä»úÖÆ
¸ÅÊö
¡¡¡¡ÓÐʱºòÎÒÃÇ˵ij¸öÓïÑÔ¾ßÓкÜÇ¿µÄ¶¯Ì¬ÐÔ£¬ÓÐʱºòÎÒÃÇ»áÇø·Ö¶¯Ì¬ºÍ¾²Ì¬µÄ²»Í¬¼¼ÊõÓë×÷·¨¡£ÎÒÃÇÀÊÀÊÉϿڶ¯Ì¬°ó¶¨£¨dynamic binding£©¡¢¶¯Ì¬Á´½Ó£¨dynamic linking£©¡¢¶¯Ì¬¼ÓÔØ£¨dynamic loading£©µÈ¡£È»¶ø“¶¯Ì¬”Ò»´ÊÆäʵûÓоø¶Ô¶øÆÕ±éÊÊÓõÄÑϸñ¶¨Ò壬ÓÐʱºòÉõÖÁÏñ¶ÔÏóµ¼Ïòµ±³õ±»µ¼Èë±à³ ......
Java6 ½Å±¾ÒýÇæ(ÓÃJavaµ÷ÓÃJS½Å±¾)µ÷ÓÃjs
import java.io.FileNotFoundException;
import java.io.FileReader;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
&n ......
ÔÚʵÏÖsingletonģʽʱ£¬ÎÒÃÇÓÐÒÔϼ¸ÖÖ·½·¨¡£ 1. public static final ×ֶμÓÉÏprivate µÄ¹¹Ô캯Êý¡£ public class Singleton{
public static final Singleton INSTANCE = new Singleton();
......
Ìù×ÓÖв¿·ÖÔ´´úÂëÕª×ÔcsdnµÄһƪÌû×Ó£¬ ²Î¿¼ÁËËûÃǵÄÀí½â£¬ËµËµ×Ô¼ºµÄһЩ¼û½â£º
//Ô´´úÂ룺
class A {
public String show(D obj){
return ("A and D");
......
public class DES {
// ÉùÃ÷³£Á¿×Ö½ÚÊý×é
private static final int[] IP = {
58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, 62, 54,
......