FoxmailUtils.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace DecryptPwd.Utils
  7. {
  8. public class FoxmailUtils
  9. {
  10. public static String Decrypt(int ver, String strHash)
  11. {
  12. String decodedPW = "";
  13. // 第一步:定义不同版本的秘钥
  14. int[] a;
  15. // fc0 的值是根据版本密钥,以字节为单位将16进制密文转成10进制,十进制之和求余。(x %=255;)
  16. int fc0;
  17. if (ver == 0) // Version 6
  18. {
  19. int[] v6a = { '~', 'd', 'r', 'a', 'G', 'o', 'n', '~' };
  20. a = v6a;
  21. fc0 = Convert.ToInt32("5A", 16); //90
  22. }
  23. else // Version 7
  24. {
  25. int[] v7a = { '~', 'F', '@', '7', '%', 'm', '$', '~' };
  26. a = v7a;
  27. fc0 = Convert.ToInt32("71", 16); // 113
  28. }
  29. // 第二步:以字节为单位将16进制密文转成10进制
  30. int size = strHash.Length / 2;
  31. int index = 0;
  32. int[] b = new int[size];
  33. for (int i = 0; i < size; i++)
  34. {
  35. b[i] = Convert.ToInt32(strHash.Substring(index, 2), 16);
  36. index = index + 2;
  37. }
  38. // 第三步:将第一个元素替换成与指定数异或后的结果
  39. int[] c = new int[b.Length];
  40. c[0] = b[0] ^ fc0;
  41. Array.Copy(b, 1, c, 1, b.Length - 1);
  42. // 第四步:不断扩容拷贝自身
  43. while (b.Length > a.Length)
  44. {
  45. int[] newA = new int[a.Length * 2];
  46. Array.Copy(a, 0, newA, 0, a.Length);
  47. Array.Copy(a, 0, newA, a.Length, a.Length);
  48. a = newA;
  49. }
  50. int[] d = new int[b.Length];
  51. for (int i = 1; i < b.Length; i++)
  52. {
  53. d[i - 1] = b[i] ^ a[i - 1];
  54. }
  55. int[] e = new int[d.Length];
  56. for (int i = 0; i < d.Length - 1; i++)
  57. {
  58. if (d[i] - c[i] < 0)
  59. {
  60. e[i] = d[i] + 255 - c[i];
  61. }
  62. else
  63. {
  64. e[i] = d[i] - c[i];
  65. }
  66. decodedPW += (char)e[i];
  67. }
  68. return decodedPW;
  69. }
  70. }
  71. }