-
-
[求助]这段C#算法代码可逆吗?代码很短
-
发表于:
2016-10-18 10:49
4713
-
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
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!