搜狗网络评测 java 移位编码解码
2011-09-19 21:58
375 查看
搜狗网络评测 java 移位编码解码
2011-09-09 12:47
很遗憾的是,我当晚没有做出来,第二天早上才搞清楚的,交了白卷:
// 注意:a^(a^b) = b
public class Test {
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) {
byte a = (byte) ((in[i] ^ seed) >>> 5); // in[i]与seed异或后,把最低八位的高三位右移变成低3位
byte b = (byte) (((((int) in[i]) << 20) ^ seed) >>> (20 - 3)); // in[i]与seed的第21位开始异或后,把异或结果右移17位,即把异或后in[i]的低五位变成了高五位
a &= 0x7; // 取出a的低3三 即 异或结果的高三位
b &= 0xf8; // 取出b的高五位 即 异或结果的低五位
out[i] = (byte) (a | b); // 或预算后结果,其实是异或结果把高三位和低五位互换位置
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;
for (int i = 0; i < len; ++i) {
// fill the code here
byte a = (byte) ((in[i] & 0x07) << 5); // 把密文的第三位变成高三位
byte b = (byte) ((in[i] & 0xf8) >>> 3); // 把密文的高五位变成低五位
a = (byte) (a ^ seed); // 求出加密异或前in[i]的高三位
a &= 0xe0; // 求出加密异或前in[i]的高三位
b = (byte) (((((int)b) << 20) ^ seed) >>> 20); // 求出加密异或前in[i] 的低五位
b &= 0x1f; // 求出加密异或前in[i] 的低五位 注意:要和seed的第21位开始异或
out[i] = (byte) (a | b); // 重组高三位和低五位得到一个完整的byte
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"));
}
}
运行结果:搜狗浏览器是目前速度最快、最稳定、最安全、功能最强大的“双核”浏览器!!!!!
相关文章推荐
- java base64编码和解码
- 黑马程序员---Java 编码解码的案例及特殊类RandomAccessFile
- java base64 编码解码工具
- java中的url 编码(Encoder)与解码(Decoder)
- Java实现二维码QRCode的编码和解码(http://java9988.iteye.com/blog/2001432)
- 在Java中正确解码用Javascript:escape()编码的中文字符
- java中的URLEncoder.encode对应JS中用decodeURIComponent,js和java编码,解码
- Java实现二维码QRCode的编码和解码
- java中文乱码解决之道(五)-----java是如何编码解码的
- java实现Base64编码解码
- java 中String编码和byte 解码 总结
- Java中如何进行BASE64编码和解码
- Java实现二维码QRCode的编码和解码
- java unicode编码与解码
- Js编码和Java后台解码
- Java实现二维码QRCode的编码和解码
- java中含有中文字符的编码和解码
- Java中JSON格式的解码与编码(1)
- java.net.URLEncode编码 与 URLDecode解码问题
- Java之IO(六)编码和解码