1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace DecryptPwd.Utils
- {
- public class FoxmailUtils
- {
- public static String Decrypt(int ver, String strHash)
- {
- String decodedPW = "";
- // 第一步:定义不同版本的秘钥
- int[] a;
- // fc0 的值是根据版本密钥,以字节为单位将16进制密文转成10进制,十进制之和求余。(x %=255;)
- int fc0;
- if (ver == 0) // Version 6
- {
- int[] v6a = { '~', 'd', 'r', 'a', 'G', 'o', 'n', '~' };
- a = v6a;
- fc0 = Convert.ToInt32("5A", 16); //90
- }
- else // Version 7
- {
- int[] v7a = { '~', 'F', '@', '7', '%', 'm', '$', '~' };
- a = v7a;
- fc0 = Convert.ToInt32("71", 16); // 113
- }
- // 第二步:以字节为单位将16进制密文转成10进制
- int size = strHash.Length / 2;
- int index = 0;
- int[] b = new int[size];
- for (int i = 0; i < size; i++)
- {
- b[i] = Convert.ToInt32(strHash.Substring(index, 2), 16);
- index = index + 2;
- }
- // 第三步:将第一个元素替换成与指定数异或后的结果
- int[] c = new int[b.Length];
- c[0] = b[0] ^ fc0;
- Array.Copy(b, 1, c, 1, b.Length - 1);
- // 第四步:不断扩容拷贝自身
- while (b.Length > a.Length)
- {
- int[] newA = new int[a.Length * 2];
- Array.Copy(a, 0, newA, 0, a.Length);
- Array.Copy(a, 0, newA, a.Length, a.Length);
- a = newA;
- }
- int[] d = new int[b.Length];
- for (int i = 1; i < b.Length; i++)
- {
- d[i - 1] = b[i] ^ a[i - 1];
- }
- int[] e = new int[d.Length];
- for (int i = 0; i < d.Length - 1; i++)
- {
- if (d[i] - c[i] < 0)
- {
- e[i] = d[i] + 255 - c[i];
- }
- else
- {
- e[i] = d[i] - c[i];
- }
- decodedPW += (char)e[i];
- }
- return decodedPW;
- }
- }
- }
|