public class Test {
public static void encode(byte[] in, byte[] out, int password)
{
int len = in.length;
int seed = password ^ 0×3810860;
for (int i = 0 ; i < len; ++i) {
/**
*因为JVM中涉及byte、short、char类型的运算操作首先会把这些值转换成int类型,
* 然后对int类型的值进行运算,所以需要把运算结果强制转换成byte类型
*/
byte a = (byte)( ( in[i] ^ seed ) >>> 5 );//把异或后的值存放在a的低3位
byte b = (byte)( ( ( ((int)in[i]) << 20 ) ^ seed ) >>> (20-3) );//把异或后的值存放在b的高5位
a &= 0×7;//0×7:0000 0111;将a中未存储有效数的位清零
b &= 0xf8;//0xf8:1111 1000;将b中未存储有效数的位清零
out[i] = (byte)(a | b);
seed = ((seed ^ out[i]) * 7321 + out[i]);
}
}
public static void decode(byte[] in, byte[] out, int password)
{
int len = in.length;
int seed = password ^ 0×3810860;
for (int i = 0 ; i < len; ++i) {
// fill the code here
}
}
public static void main(String [] args) throws Exception
{
int password = 0x808d0625;
byte[] buf1 = {-36, -108, -73, 95, 56, 80, -103, -49, 59, -52, -30, 70, -93, 88, 110, -128, 88, -42, 1, 114, -117, -67, -84, 55, 24, -107, -97, -51, 60, -117, 113, 38, 110, -103, -70, 100, 54, -126, };
byte[] buf2 = new byte[buf1.length];
decode(buf1, buf2, password);
System.out.println(new String(buf2, “GBK”));
}
} Continue reading »
近期评论