搜狗2012校园招聘自测题

搜狗2012年校园招聘的在线自测题,每人只有三次机会,每次的内容不同,但是原理一致,其实就是根据一段字符串的加密写出解密算法,分析出原文内容,下为Java代码:
public class Test {

	public static void encode(byte[] in, byte[] out, int password) {
		int len = in.length;

		int seed = password ^ 0x1e1ec1cb;
		for (int i = 0; i < len; ++i) {
			byte a = (byte) ((in[i] ^ seed) >>> 4);
			byte b = (byte) (((((int) in[i]) << 13) ^ seed) >>> (13 - 4));
			a &= 0xf;
			b &= 0xf0;
			out[i] = (byte) (a | b);
			seed = ((seed ^ out[i]) * 608347 + out[i]);
		}
	}

	public static void decode(byte[] in, byte[] out, int password) {
		int len = in.length;

		int seed = password ^ 0x1e1ec1cb;
		for (int i = 0; i < len; ++i) {

			// 想办法循环左移4位
			byte a = (byte) ((in[i]) << 4); // //有效位剩余4位
			byte b = (byte) ((in[i]) >>> 4); // //有效位剩余4位

			a = (byte) (a ^ seed); // 还原
			a &= 0xf0; // 无效位再次置0,因为有可能,经过异或之后变成1了
			b = (byte) (((((int) b) << 13) ^ seed) >>> 13); // 还原
			b &= 0xf; // //无效位再次置0,因为有可能,经过异或之后变成1了

			out[i] = (byte) (a | b);
			seed = ((seed ^ in[i]) * 608347 + in[i]);
		}
	}

	public static void main(String[] args) throws Exception {
		int password = 0xd397e77b;
		byte[] buf1 = { 39, 0, -50, 112, 92, 125, -77, 27, 89, 117, -6, -120,
				-70, 26, -102, -12, -115, 2, 15, -51, 87, -110, 10, -85, -77,
				-120, 22, -94, -120, 88, 88, 26, 106, 121, -85, -79, 84, -12,
				-96, -70, -36, -84, };
		byte[] buf2 = new byte[buf1.length];
		decode(buf1, buf2, password);
		System.out.println(new String(buf2, "GBK"));
	}
}

运行结果如下:

搜狗云输入法是一款领先的概念性产品!!!!


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值