package sougou; public class Test { // 原理:a^(a^b) = b public static void encode(byte[] in, byte[] out, int password) { int len = in.length; int seed = password ^ 0xb1c07965; for (int i = 0; i < len; ++i) { // in[i]与seed异或后,向右移动3位,高三位右移变成低3位,有效位范围:第0位到第2位 //总的看来,只剩下原来字节的第5位到第7位,放到现在字节a的第0位到第2位 byte a = (byte) ((in[i] ^ seed) >>> 5); // in[i]与seed异或后,向右移动3位,高三位右移变成低3位,把原来的高5位置0 // in[i]与seed的第21位开始异或后,把异或结果右移17位,即把异或后in[i]的低五位变成了高五位
//每一次都要改变seed,改变后的seed只依赖于前一个in[i]和常量48475829(最前头seed是依赖于0xb1c07965和password) seed = ((seed ^ in[i]) * 48475829 + in[i]); } } public static void decode(byte[] in, byte[] out, int password) { int len = in.length; int seed = password ^ 0xb1c07965;//最前头seed是依赖于0xb1c07965和password for (int i = 0; i < len; ++i) { // fill the code here //-------------------------------------------------------------------------------------------- // //可以利用字节变量a中第5位到第7位临时存放第0位到第2位,b中第0位到第4位临时存放第3位到第7位
a = (byte) (a ^ seed); // 还原 a &= 0xe0; //无效位再次置0,因为有可能,经过异或之后变成1了 b = (byte) (((((int) b) << 20) ^ seed) >>> 20); // 还原 b &= 0x1f; ////无效位再次置0,因为有可能,经过异或之后变成1了
package sougou;
public class Test {
// 原理:a^(a^b) = b
public static void encode(byte[] in, byte[] out, int password) {
int len = in.length;
int seed = password ^ 0xb1c07965;
for (int i = 0; i < len; ++i) {
// in[i]与seed异或后,向右移动3位,高三位右移变成低3位,有效位范围:第0位到第2位
//总的看来,只剩下原来字节的第5位到第7位,放到现在字节a的第0位到第2位
byte a = (byte) ((in[i] ^ seed) >>> 5); // in[i]与seed异或后,向右移动3位,高三位右移变成低3位,把原来的高5位置0
// in[i]与seed的第21位开始异或后,把异或结果右移17位,即把异或后in[i]的低五位变成了高五位
//--------------------------------------------------------------------------------------------------
//1.先将8个二进制位扩展为32个二进制位,高24位补0:有效位范围:第0位到第7位
//2.将32个二进制位向左移动二十位,低位补0,有效位范围:第20位到第27位
//3.异或,有效位范围:第20位到第27位
//4.向右移动17位高位补0,有效位范围:第3位到第10位
//5.先将32个二进制位向下强制转为8个二进制位,只剩下低8位,有效位范围:第3位到第7位
//总的看来,只剩下原来字节的第0位到第4位,放到现在字节b的第3位到第7位
byte b = (byte) (((((int) in[i]) << 20) ^ seed) >>> (20 - 3));
//---------------------------------------------------------------------------------------------------
//16进制的0x7相当于二进制的00000111,与a中的8个二进制为进行"按位与"操作,相当于将a中的第3位到第7位置0
//a中的第3位到第7位存放的是无效位,也就是将无效位置0, 有效位范围:第0位到第2位不受影响
a &= 0x7; //
//----------------------------------------------------------------------------------------------------
//16进制的0xf8相当于二进制的11111000,与b中的8个二进制为进行"按位与"操作,相当于将b中的第0位到第2位置0
//b中的第0位到第2位存放的是无效位,也就是将无效位置0 有效位范围:第3位到第7位不受影响
b &= 0xf8;
//---------------------------------------------------------------------------------------------------
//a与b进行"按位或"操作 ,
//a中的无效位(第3位到第7位)已经为0,所以结果的第3位到第7位是由b中的第3位到第7位决定
//b中的无效位(第0位到第2位)已经为0,所以结果的第0位到第2位是由a中的第0位到第2位决定
//总的看来;又是将a中5位有效位,和b中3位有效位组合在一起,组成8位有效位
out[i] = (byte) (a | b);
//--------------------------------------------------------------------------------------------------------
//---原来的in[i]与seed先异或再循环右移5位。变为out[i],----------
//每一次都要改变seed,改变后的seed只依赖于前一个in[i]和常量48475829(最前头seed是依赖于0xb1c07965和password)
seed = ((seed ^ in[i]) * 48475829 + in[i]);
}
} public static void decode(byte[] in, byte[] out, int password) {
int len = in.length;
int seed = password ^ 0xb1c07965;//最前头seed是依赖于0xb1c07965和password
for (int i = 0; i < len; ++i) {
// fill the code here
//--------------------------------------------------------------------------------------------
//
//可以利用字节变量a中第5位到第7位临时存放第0位到第2位,b中第0位到第4位临时存放第3位到第7位
//第3位到第7位置0,左移5位,a中第5位到第7位是有效位
byte a = (byte) ((in[i] & 0x07) << 5); // 把密文的第三位变成高三位
//第0位到第2位置0,右移3位,b中第0位到第4位是有效位
byte b = (byte) ((in[i] & 0xf8) >>> 3); // 把密文的高五位变成低五位
//---------------------------------------------------------------------------------------------
a = (byte) (a ^ seed); // 还原
a &= 0xe0; //无效位再次置0,因为有可能,经过异或之后变成1了
b = (byte) (((((int) b) << 20) ^ seed) >>> 20); // 还原
b &= 0x1f; ////无效位再次置0,因为有可能,经过异或之后变成1了
out[i] = (byte)(a | b); //将临时变量中的数据串接,保存到out[i],这是真实的数据来了,
//每一次循环seed是不一样的,利用真实数据out[i]和常量48475829求出seed
seed = ((seed ^ out[i]) * 48475829 + out[i]);
}
} public static void main(String[] args) throws Exception {
int password = 0x38431c82;
byte[] buf1 = { -103, 121, -6, 20, -50, -107, -30, -122, -8, 13, 118,
54, -117, -84, -17, -75, 45, -7, 116, -13, -63, -27, -124, -26,
-75, 108, 80, -87, 47, -122, -44, 117, -16, 29, 21, 104, -15,
109, -60, -16, -114, -30, 109, -38, 46, -47, -2, 19, 5, -112,
-108, 33, 15, -25, 55, -58, -14, 73, 59, 38, -29, 58, -14, 80,
-23, 28, 102, -2, 44, -90, -59, 24, 37, -37, 18, -47, 87, 23, };
byte[] buf2 = new byte[buf1.length];
decode(buf1, buf2, password); System.out.println(new String(buf2, "GBK"));
}
}
/*output:
搜狗浏览器是目前速度最快、最稳定、最安全、功能最强大的“双核”浏览器!!!!!
*/
*/
思路跟上面的一摸一样package sougou2;
public class Test {
public static void encode(byte[] in, byte[] out, int password) {
int len = in.length;
int seed = password ^ 0x9e4d5bc1;
for (int i = 0; i < len; ++i) {
byte a = (byte) ((in[i] ^ seed) >>> 2);//有效位剩余6位
byte b = (byte) (((((int) in[i]) << 12) ^ seed) >>> (12 - 6));//有效位剩余2位
a &= 0x3f;//取低6位
b &= 0xc0;//取高2位
out[i] = (byte) (a | b);//串接:循环右移2位
seed = (seed * 7321 ^ seed ^ out[i]);
}
} public static void decode(byte[] in, byte[] out, int password) {
int len = in.length;
int seed = password ^ 0x9e4d5bc1; for (int i = 0; i < len; ++i) {
// fill the code here
//--------------------------------------------------------------------------------------------
//想办法循环左移2位
byte a = (byte) ((in[i] & 0x3f) << 2); ////有效位剩余6位
byte b = (byte) ((in[i] & 0xc0) >>> 6); // //有效位剩余2位
//---------------------------------------------------------------------------------------------
a = (byte) (a ^ seed); // 还原
a &= 0xfc; //无效位再次置0,因为有可能,经过异或之后变成1了
b = (byte) (((((int) b) << 12) ^ seed) >>> 12); // 还原
b &= 0x03; ////无效位再次置0,因为有可能,经过异或之后变成1了
out[i] = (byte) (a | b); //将临时变量中的数据串接,保存到out[i],这是真实的数据来了,
seed = (seed * 7321 ^ seed ^ in[i]);
}
} public static void main(String[] args) throws Exception {
int password = 0x9ddb6e7d;
byte[] buf1 = { 29, 11, 94, -88, -120, -59, -45, 124, 64, -109, -44,
87, 12, -92, -18, 76, -11, -88, 126, -44, 72, 85, -16, -84, 73,
-34, -15, 104, -114, 112, -4, -47, 25, 52, 6, -80, 124, 41, 34,
-55, -99, 31, 12, -1, -28, 49, 124, -7, -18, 105, -42, -105, 1,
50, };
byte[] buf2 = new byte[buf1.length];
decode(buf1, buf2, password);
System.out.println(new String(buf2, "GBK"));
}}
/*output:
搜狗高速浏览器技术水平在市场上一直处于领先地位!!!!
*/