首页
社区
课程
招聘
[求助]这段C#算法代码可逆吗?代码很短
2016-10-18 10:49 4211

[求助]这段C#算法代码可逆吗?代码很短

2016-10-18 10:49
4211
        internal static byte[] FromHexString(string s)
        {
            if ((s != null) ? ((s.Length % 2) > 0) : true)            
                return null;
            
            List<byte> list = new List<byte>();
            for (int i = 0; i < s.Length; i += 2)
            {
                byte num2;
                if (byte.TryParse(s.Substring(i, 2), NumberStyles.HexNumber, (IFormatProvider)null, out num2))
                {
                    list.Add(num2);
                }
            }
            return list.ToArray();
        }

        internal static bool Validate(string email, string unlockCode)
        {            
            email = email.ToLower();
            byte[] buffer = FromHexString(unlockCode); //将unlockCode转为byte数组
            if ((buffer == null) || (buffer.Length <= 2))
            {
                return false;
            }
            List<byte> source = new List<byte>();
            for (int j = 0; j < (buffer.Length - 2); j++)
            {
                source.Add(buffer[j]); //把unlockCode放入source
            }
            source.AddRange(MD5.Create().ComputeHash(Encoding.ASCII.GetBytes($"{email}@2016"))); //把计算email的哈希放入source
            //然后将source中的行序号与value相乘后全部累加  再与unlockCode比较是否相等
            return (((ushort)(source.Select<byte, int>((t, i) => ((i + 1) * t)).Sum() & 0xffff)) == BitConverter.ToUInt16(buffer, buffer.Length - 2));
        }


----------------------------------
上述代码Validate方法,Email 已知,求出unlock code

[培训]《安卓高级研修班(网课)》月薪三万计划,掌握调试、分析还原ollvm、vmp的方法,定制art虚拟机自动化脱壳的方法

收藏
点赞0
打赏
分享
最新回复 (6)
雪    币: 188
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
hystat 2016-10-18 10:53
2
0
这个算法很微妙,微妙之处在于: Email + Unlock code = Unlock code
雪    币: 222
活跃值: (1866)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
lhglhg 1 2016-10-18 11:17
3
0
只验证Unlock code
后2位
雪    币: 188
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
hystat 2016-10-18 11:28
4
0
后两位没用到吧
雪    币: 293
活跃值: (232)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
瀚海云烟 1 2016-10-18 12:29
5
0
其实很简单不要想复杂了,只要最后打印
(ushort)(source.Select<byte, int>((t, i) => ((i + 1) * t)).Sum() & 0xffff) 的值替换 unlockCode 最后两位就行了,但是高低位要互换因为你懂的

return 之前打印即可
    ushort itv = (ushort)(source.Select<byte, int>((t, i) => ((i + 1) * t)).Sum() & 0xffff);
    buffer[buffer.Length - 2] = (byte)itv;
    buffer[buffer.Length - 1] = (byte)(itv>>8);

    for (int i = 0; i < buffer.Length; i++)
    {
        Console.Write("{0:X2}", buffer.GetValue(i));
    }
    Console.WriteLine("");
雪    币: 6528
活跃值: (2573)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
Kisesy 2016-10-18 12:33
6
0
123@abc.com,  ABBACDEFDD814C 这个行吗
雪    币: 188
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
hystat 2016-10-18 14:37
7
0
你真的很厉害,我还是没搞明白,但代码测试确实可以用。
游客
登录 | 注册 方可回帖
返回