StringObfucator.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using System.Text;
  3. namespace I2.Loc
  4. {
  5. public class StringObfucator
  6. {
  7. public static string Encode(string NormalString)
  8. {
  9. string result;
  10. try
  11. {
  12. string regularString = StringObfucator.XoREncode(NormalString);
  13. result = StringObfucator.ToBase64(regularString);
  14. }
  15. catch (Exception)
  16. {
  17. result = null;
  18. }
  19. return result;
  20. }
  21. public static string Decode(string ObfucatedString)
  22. {
  23. string result;
  24. try
  25. {
  26. string normalString = StringObfucator.FromBase64(ObfucatedString);
  27. result = StringObfucator.XoREncode(normalString);
  28. }
  29. catch (Exception)
  30. {
  31. result = null;
  32. }
  33. return result;
  34. }
  35. private static string ToBase64(string regularString)
  36. {
  37. byte[] bytes = Encoding.UTF8.GetBytes(regularString);
  38. return Convert.ToBase64String(bytes);
  39. }
  40. private static string FromBase64(string base64string)
  41. {
  42. byte[] array = Convert.FromBase64String(base64string);
  43. return Encoding.UTF8.GetString(array, 0, array.Length);
  44. }
  45. private static string XoREncode(string NormalString)
  46. {
  47. string result;
  48. try
  49. {
  50. char[] stringObfuscatorPassword = StringObfucator.StringObfuscatorPassword;
  51. char[] array = NormalString.ToCharArray();
  52. int num = stringObfuscatorPassword.Length;
  53. int i = 0;
  54. int num2 = array.Length;
  55. while (i < num2)
  56. {
  57. array[i] = (array[i] ^ stringObfuscatorPassword[i % num] ^ (char)((byte)((i % 2 != 0) ? (-i * 51) : (i * 23))));
  58. i++;
  59. }
  60. result = new string(array);
  61. }
  62. catch (Exception)
  63. {
  64. result = null;
  65. }
  66. return result;
  67. }
  68. public static char[] StringObfuscatorPassword = "ÝúbUu\u0010\u008b¸CÁ§*4\u0013PÚ©-᩾@T6D\u0089l\u000f±\u0091ÒWâuzÅm4GÐó\u0019Ø$=Í g,¥Q\u0083\të®iKEß r¡\u0019\u009f×6\u00160Ít \u00904öÃ\u0093~^«\u001cy\u0003:\u0090\u0096Èd\u0010\u008f1\u001a<Q\u008f\u0099ÛÝúbUu\u0010\u008b¸CÁ§*4\u0013PÚ©-᩾@T6D\u0089l\u000f±\u0091ÒWâuzÅm4GÐó\u0019Ø$=Í g,¥Q\u0083\të®iKEß r¡\u0019\u009f×6\u00160Ít \u00904öÃ\u0093~^«\u001cy\u0003:\u0090\u0096Èd".ToCharArray();
  69. }
  70. }