# 求相助，搜狗网申在线测试题

www.MyException.Cn  网友分享于：2013-12-08  浏览：152次

2011-09-12 17:09 0人阅读 评论(0) 收藏 编辑 删除

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

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];
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 ^ 0x2c8f7672;
for (int i = 0 ; i < len; ++i) {
//……
byte a = (byte)( (in[i] << 2)^ seed) ;
byte b = (byte)( ( ( ((int)in[i]) >>> 4 ) ^ seed ) << 10 );
a &= 252;
b &= 3;
out[i] = (byte)(a | b);
seed = (((seed << 7) ^ seed ^ in[i]) + 536513);
}
}
------解决方案--------------------

int len = in.length;

int seed = password ^ 0x2c8f7672;
for (int i = 0 ; i < len; ++i) {
byte a = (byte)(in[i] & 0x3f);
byte b = (byte)(in[i] & 0xc0);
a = (byte)(((a << 2) ^ seed) & 0xfc);
b = (byte)((((((int)b) << (10-6)) ^ seed) >> 10) & 0x03);
out[i] = (byte)(a | b);
byte a = (byte)( ( in[i] ^ seed ) >>> 2 );
seed = (((seed << 7) ^ seed ^ in[i]) + 536513);
}
}```