关于搜狗在线测评上面的题目详解
2011-09-29 11:25
211 查看
前几天在投递了搜狗Java开发工程师。需要搞一个在线测评,出了一道题目,是程序填空题
要求观察程序,补全decode,输出一句话:
思前想后,发现规律。这就是一系列的移位,我们要做的就是反过来再移一次。先看看encode方法,然后再去实现decode。方法如下:
最后输出的结果是:听歌从搜狗音乐搜索开始!!!
要求观察程序,补全decode,输出一句话:
public class Test { public static void encode(byte[] in, byte[] out, int password) { int len = in.length; int seed = password ^ 0x1963f9c; for (int i = 0 ; i < len; ++i) { byte a = (byte)( ( in[i] ^ seed ) >>> 2 ); byte b = (byte)( ( ( ((int)in[i]) << 13 ) ^ seed ) >>> (13-6) ); a &= 0x3f; b &= 0xc0; out[i] = (byte)(a | b); seed = (((seed << 7) ^ seed ^ in[i]) + 5393887); } } public static void decode(byte[] in, byte[] out, int password) { int len = in.length; int seed = password ^ 0x1963f9c; for (int i = 0 ; i < len; ++i) { byte a = (byte)(in[i] & 0x3f); byte b = (byte)(in[i] & 0xc0); a = (byte)(((a << 2) ^ seed) & 0xfc); b = (byte)((((((int)b) << (13-6)) ^ seed) >>13) & 0x03); out[i] = (byte)(a | b); seed = (((seed << 7) ^ seed ^ out[i]) + 5393887); } } public static void main(String [] args) throws Exception { int password = 0x99b90094; byte[] buf1 = {113, 87, 1, -29, 55, -5, 65, 13, -85, 78, 50, 23, -33, -29, 73, 117, -97, 106, 77, -17, -107, -62, -110, -126, -15, 32, -48, -128, }; byte[] buf2 = new byte[buf1.length]; decode(buf1, buf2, password); System.out.println(new String(buf2, "GBK")); } }
思前想后,发现规律。这就是一系列的移位,我们要做的就是反过来再移一次。先看看encode方法,然后再去实现decode。方法如下:
public static void decode(byte[] in, byte[] out, int password) { int len = in.length; int seed = password ^ 0x1963f9c; for (int i = 0 ; i < len; ++i) { byte a = (byte)(in[i] & 0x3f); byte b = (byte)(in[i] & 0xc0); a = (byte)(((a << 2) ^ seed) & 0xfc); b = (byte)((((((int)b) << (13-6)) ^ seed) >>13) & 0x03); out[i] = (byte)(a | b); seed = (((seed << 7) ^ seed ^ out[i]) + 5393887); } }
最后输出的结果是:听歌从搜狗音乐搜索开始!!!
相关文章推荐
- 搜狗在线测评题目信息编码与解码
- PAT上面一道关于“月饼”的题目的解法
- 搜狗的在线测评
- 关于搜狗网上测评试题的解法(GBK的)。
- 搜狗一道java题目 关于对象 synchronized 关键字作用在 int, integer
- 搜狗在线测评(加密解密)
- 求职在线测评题目
- 关于URLConnection参数详解
- 关于Hibernate的配置文件参数详解
- 关于vi和vim的区别及命令详解
- 关于索引的B tree B-tree B+tree B*tree 详解结构图( 二)
- 关于查找 “选修了全部课程的学生姓名”题目的理解
- 宽带路由器中关于IP带宽控制功能的详解
- 关于mysql中一些有趣的题目
- 关于指针与数组的相关例题详解
- 35. Search Insert Position题目和答案详解
- 关于使用详解ASP.NET StateService
- 关于NopCommerce3.6版用户登录详解
- 关于ThinkPHP中的异常处理详解
- 关于Java的Classpath详解