日期:2014-05-20  浏览次数:20728 次

补完一个java的加密解密程序

public class Test { 


public static void encode(byte[] in, byte[] out, int password) 

int len = in.length; 

int seed = password ^ 0x37d23f33; 
for (int i = 0 ; i < len; ++i) { 
byte a = (byte)( ( in[i] ^ seed ) >>> 4 ); 
byte b = (byte)( ( ( ((int)in[i]) << 15 ) ^ seed ) >>> (15-4) ); 
a &= 0xf; 
b &= 0xf0; 
out[i] = (byte)(a | b); 
seed = (seed * 7321 + out[i]); 




public static void decode(byte[] in, byte[] out, int password) 

int len = in.length; 

int seed = password ^ 0x37d23f33; 
for (int i = 0 ; i < len; ++i) { 
// fill the code here 


public static void main(String [] args) throws Exception 

int password = 0xc7b25752; 
byte[] buf1 = {-70, 6, 123, -70, -106, 39, -91, -38, 53, 46, -43, -16, -45, -53, -48, 25, -66, 113, -34, 99, 39, 84, 79, 5, 18, -107, -62, -110, 119, -35, 68, -11, -40, -106, -33, 78, 18, 56, }; 
byte[] buf2 = new byte[buf1.length]; 
decode(buf1, buf2, password); 
System.out.println(new String(buf2, "GBK")); 



}

------解决方案--------------------
最近怎么老是有人问这样类似的问题
http://topic.csdn.net/u/20110908/16/36c546d7-e820-4e5d-863b-6e8d22c53475.html

http://topic.csdn.net/u/20110908/12/a852b3a1-fb14-41b3-9776-41c93c62706e.html

Java code
public static void decode(byte[] in, byte[] out, int password)  {  
    int len = in.length;  

    int seed = password ^ 0x37d23f33;  
    for (int i = 0 ; i < len; ++i) {  
        byte a = (byte)(in[i] & 0xf);
        byte b = (byte)(in[i] & 0xf0);
        a = (byte)(((a << 4) ^ seed) & 0xf0);
        b = (byte)((((((int)b) << (15-4)) ^ seed) >> 15) & 0xf);
        out[i] = (byte)(a | b);
        seed = (seed * 7321 + in[i]);
    }  
}