Õâ¸öËã·¨¼òµ¥,¶øÇÒЧÂʸß,ÿ´Î¿ÉÒÔ²Ù×÷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¹«Ë¾µÄ±ÊÊÔÌ⣬¿¼²ìÁË´ó¸Åһǧ¶à¸öÃæÊÔµÄjava¹¤³ÌʦÒÔ¼°ÏîÄ¿¾Àí£¬²»¹ýÈ«¶ÔµÄÖ»Óв»µ½1.5%
ÔÚ×öÕâ¸öÌâµÄʱºòÇ밴˳Ðò×ö£¬²»Äܸıä˳Ðò£¬×öÇ°ÃæÌâʱ£¬²»Äܲ鿴ºóÃæµÄÌ⣬ͬÉÏÒ²²»Òª²é¿´ÏÂÃæµÄ»Ø¸´,²»Òª¸Ä±äÄãµÄ´ð°¸
¶àµÄÏȲ»Ëµ£¬Çë°ÑÏÂÃæµÄÌâ´ð°¸¸ø³ö
class Human{
static ......
Ìù×ÓÖв¿·ÖÔ´´úÂëÕª×ÔcsdnµÄһƪÌû×Ó£¬ ²Î¿¼ÁËËûÃǵÄÀí½â£¬ËµËµ×Ô¼ºµÄһЩ¼û½â£º
//Ô´´úÂ룺
class A {
public String show(D obj){
return ("A and D");
......