62,616
社区成员
发帖
与我相关
我的任务
分享
public class Test {
public static void encode(byte[] in, byte[] out, int password) {
int len = in.length;
int seed = password ^ 0x3e1e25e6;
for (int i = 0; i < len; ++i) {
byte a = (byte) ((in[i] ^ seed) >>> 3);
byte b = (byte) (((((int) in[i]) << 18) ^ seed) >>> (18 - 5));
a &= 0x1f;
b &= 0xe0;
out[i] = (byte) (a | b);
seed = (seed * 84723701 ^ seed ^ out[i]);
}
}
public static void decode(byte[] in, byte[] out, int password) {
int len = in.length;
int seed = password ^ 0x3e1e25e6;
for (int i = 0; i < len; ++i) {
// fill the code here
}
}
public static void main(String[] args) throws Exception {
int password = 0xfdb4d0e9;
byte[] buf1 = { -5, 9, -62, -122, 50, 122, -86, 119, -101, 25, -64,
-97, -128, 95, 85, 62, 99, 98, -94, 76, 12, 127, 121, -32,
-125, -126, 15, 18, 100, 104, -32, -111, -122, 110, -4, 60, 57,
21, 36, -82, };
byte[] buf2 = new byte[buf1.length];
decode(buf1, buf2, password);
System.out.println(new String(buf2, "GBK"));
}
}
public static void decode(byte[] in, byte[] out, int password)
{
int len = in.length;
int seed = password ^ 0x3e1e25e6;
for (int i = 0; i < len; ++i)
{
// fill the code here
byte a = (byte) ((in[i]<<3)^seed);
byte b = (byte) (((int)in[i]<<13^seed)>>18);
a &= 0xf8;
b &= 0x07;
out[i] = (byte)(a | b);
seed = (seed * 84723701 ^ seed ^ in[i]);
}
}
byte a = (byte) (in[i] & 0x1f);
byte b = (byte) (in[i] & 0xe0);
a = (byte) (((a <<3) ^ seed) & 0xe0);
b = (byte) ((((((int) b) << (18 - 5)) ^ seed) >> 18) & 0x1f);
out[i] = (byte) (a | b);
seed = (seed * 84723701 ^ seed ^ in[i]);