首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

搜狗的一路关于加密解密的在线测评题目

2012-10-13 
搜狗的一道关于加密解密的在线测评题目是一个信息编码的程序,阅读其encode部分,并补全其decode部分?最后运

搜狗的一道关于加密解密的在线测评题目

是一个信息编码的程序,阅读其encode部分,并补全其decode部分?
最后运行程序,会打印出的一句话。这句话就是我们要求的答案。

?

题目源码如下:

?

?

public class Test { /** * 加密过程 * @param in * @param out * @param password */    public static void encode(byte[] in, byte[] out, int password) {         int len = in.length;         int seed = password ^ 0x8c357ca5;         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]) << 16) ^ seed) >>> (16 - 3)); //把异或后的值存放在b的高5位            a &= 0x7; //0x7:0000 0111;将a中未存储有效数的位清零            b &= 0xf8; //0xf8:1111 1000;将b中未存储有效数的位清零            out[i] = (byte) (a | b);             seed = (seed * 3687989 ^ seed ^ in[i]);         }     } /** *  * @param in * @param out * @param password */    public static void decode(byte[] in, byte[] out, int password) {         int len = in.length;         int seed = password ^ 0x8c357ca5;         for (int i = 0; i < len; ++i) {         //补全代码....                }     }     public static void main(String[] args) throws Exception {         int password = 0xe87dd9d3;         //要输出的汉字符号对应的编码,一个汉字符号占用两个字节        byte[] buf1 = { 29, -16, 96, 43, -85, 25, -96, 83, 13, 66, -109, 49, -111, 0, 60, -101, 99, -86, -38, 86, -35,                 48, 23, 83, -102, 25, 73, -116, -101, -88, -5, 14, -14, -112, 87, -87, 2, 108, -58, 40, 56, 12, 108,                 77, 83, 38, 20, -114};         byte[] buf2 = new byte[buf1.length];         decode(buf1, buf2, password);         System.out.println("结果:"+new String(buf2, "GBK"));     } } 
?

需要补全的代码如下:

?

?

byte a = (byte)(((in[i] & 0x7) << 5) ^ seed);//把值存放到a的高3位        byte b = (byte)(((((((int)in[i]) & 0xF8 ) << (16 - 3))) ^ seed) >>> 16); //把值存放到b的低5位        a &= 0xe0;  //0xe0:1110 0000;将a中未存储有效数的位清零        b &= 0x1f;  //0x1f:0001 1111;将b中未存储有效数的位清零        out[i] = (byte)(a | b);        seed = (seed * 3687989 ^ seed ^ out[i]); 
?

?

运行结果:

?

结果:搜狗输入法支持各种炫酷的皮肤,彰显个性的你!!!

?

热点排行