求解
完成代码,并给出最后结果
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]);
}
}