首先说明本题目的原意:以下程序是GBK编码和解码程序,根据编码过程encode(),将解码过程decode()补充完整。写出输出结果,输出结果是一句话。
public class Test {
public static void encode(byte[] in, byte[] out, int password)
{
int len = in.length;
int seed = password ^ 0x2c8f7672;
for (int i = 0 ; i < len; ++i) {
byte a = (byte)( ( in[i] ^ seed ) >>> 2 );
byte b = (byte)( ( ( ((int)in[i]) << 10 ) ^ seed ) >>> (10-6) );
a &= 0x3f;
b &= 0xc0;
out[i] = (byte)(a | b);
seed = (((seed << 7) ^ seed ^ out[i]) + 536513);
}
}
public static void decode(byte[] in, byte[] out, int password)
{
int len = in.length;
int seed = password ^ 0x2c8f7672;
for (int i = 0 ; i < len; ++i) {
//……
}
}
public static void main(String [] args) throws Exception
{
int password = 0xa15ab37a;
byte[] buf1 = {-80, -86, -85, 77, 23, -94, 2, 77, 111, -35, -60, 68, -62, -128, -113, 27, 84, 11, 0, 61, 13, -43, 56, -50, 39, 55, -99, 114, -28, 104, -65, 91, 66, -97, 52, 80, -109, -6, 11, 29, -14, 98, -16, -95, 38, 37, 122, -75, 72, -54, -56, -86, -112, -28, };
byte[] buf2 = new byte[buf1.length];
decode(buf1, buf2, password);
System.out.println(new String(buf2, "GBK"));
}
}
在//……填写适当的代码,然后运行,打印出结果。