首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

求解,该如何解决

2012-01-23 
求解完成代码,并给出最后结果public class Test {public static void encode(byte[] in, byte[] out, int

求解
完成代码,并给出最后结果
public class Test {

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

int seed = password ^ 0xd6445ad8;
for (int i = 0; i < len; ++i) {
byte a = (byte) ((in[i] ^ seed) >>> 3);
byte b = (byte) (((((int) in[i]) << 13) ^ seed) >>> (13 - 5));
a &= 0x1f;
b &= 0xe0;
out[i] = (byte) (a | b);
seed = ((seed ^ out[i]) * 5393887 + out[i]);
}
}

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

int seed = password ^ 0xd6445ad8;
for (int i = 0; i < len; ++i) {
  //填上代码
}
}

public static void main(String[] args) throws Exception {
int password = 0xea154884;
byte[] buf1 = { -110, -65, -125, 82, -38, -15, 77, -14, 88, 32, -5,
122, 83, 86, 69, 74, 46, 53, -62, -89, 59, 18, 86, 78, 26, 41, };
byte[] buf2 = new byte[buf1.length];
decode(buf1, buf2, password);
System.out.println(new String(buf2, "GBK"));
}

}


[解决办法]
就是要解密回来吧
根据加密代码反过来实现就可以了

Java code
public static void decode(byte[] in, byte[] out, int password) {    int len = in.length;    int seed = password ^ 0xd6445ad8;    for (int i = 0; i < len; ++i) {        byte a = (byte)(in[i] & 0x1f);        byte b = (byte)(in[i] & 0xe0);        a = (byte)(((a << 3) ^ seed) & 0xf8);        b = (byte)((((((int)b) << (13-5)) ^ seed) >> 13) & 0x07);        out[i] = (byte) (a | b);        seed = ((seed ^ in[i]) * 5393887 + in[i]);    }} 

热点排行