Advertisement
Guest User

Untitled

a guest
Oct 14th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4. using Conquer_Online_Server.Network.Cryptography;
  5.  
  6. namespace Conquer_Online_Server.Network.AuthPackets
  7. {
  8. public class Authentication : Interfaces.IPacket
  9. {
  10. public string Username;
  11. public string Password;
  12. public string Server;
  13. public string Mac;
  14.  
  15. public Authentication()
  16. {
  17. }
  18. public void Deserialize(byte[] buffer)
  19. {
  20. if (buffer.Length == 312)
  21. {
  22. ushort length = BitConverter.ToUInt16(buffer, 0);
  23.  
  24. if (length == 312)
  25. {
  26.  
  27. ushort type = BitConverter.ToUInt16(buffer, 2);
  28. byte[] temp = new byte[16];
  29. if (type == 1542)
  30. {
  31. MemoryStream MS = new MemoryStream(buffer);
  32. BinaryReader BR = new BinaryReader(MS);
  33. BR.ReadUInt16();
  34. BR.ReadUInt16();
  35. Username = Encoding.Default.GetString(BR.ReadBytes(32));
  36. Username = Username.Replace("\0", "");
  37. BR.ReadBytes(37);
  38. byte[] PasswordArray = BR.ReadBytes(32);
  39. Password = Encoding.Default.GetString(PasswordArray);
  40. LoaderEncryption.Decrypt(PasswordArray);
  41. Password = Encoding.Default.GetString(PasswordArray);
  42. Password = Password.Replace("\0", "");
  43. BR.ReadBytes(31);
  44. Server = Encoding.Default.GetString(BR.ReadBytes(16));
  45. Server = Server.Replace("\0", "");
  46. //Console.WriteLine("password:" + Password);
  47. BR.Close();
  48. MS.Close();
  49. }
  50. }
  51. }
  52. }
  53.  
  54. public byte[] ToArray()
  55. {
  56. throw new NotImplementedException();
  57. }
  58. public void Send(Client.GameState client)
  59. {
  60. throw new NotImplementedException();
  61. }
  62. }
  63. }
  64.  
  65. //////////////////////////////////////////////////////
  66. using System;
  67. using System.Collections.Generic;
  68. using System.Linq;
  69. using System.Text;
  70.  
  71. namespace Conquer_Online_Server.Network.Cryptography
  72. {
  73. public class LoaderEncryption
  74. {
  75. private static byte[] Key =
  76. {
  77. 3,
  78. 6,
  79. 1,
  80. 3,
  81. 66,
  82. 33,
  83. 77,
  84. 44,
  85. 100,
  86. 221,
  87. 21,
  88. 254,
  89. 234,
  90. 212,
  91. 114,
  92. 141,
  93. 214,
  94. 12,
  95. 56,
  96. 99,
  97. 100,
  98. 7,
  99. 98,
  100. 187,
  101. 190,
  102. 77,
  103. 65,
  104. 55,
  105. 44,
  106. 43,
  107. 21,
  108. 99
  109. }; // idb
  110. private static byte[] Key2 =
  111. {
  112. 6,
  113. 4,
  114. 1,
  115. 7,
  116. 2,
  117. 33,
  118. 77,
  119. 66,
  120. 65,
  121. 44,
  122. 21,
  123. 254,
  124. 43,
  125. 212,
  126. 90,
  127. 44,
  128. 214,
  129. 12,
  130. 56,
  131. 99,
  132. 67,
  133. 7,
  134. 87,
  135. 99,
  136. 0,
  137. 77,
  138. 43,
  139. 11,
  140. 44,
  141. 22,
  142. 21,
  143. 99
  144. }; // idb
  145.  
  146. public static void Encrypt(byte[] arr)
  147. {
  148. int length = Key.Length;
  149. for (int i = 0; i < arr.Length; i++)
  150. {
  151. arr[i] ^= Key[i % length];
  152. arr[i] ^= Key[(i + 1) % length];
  153. }
  154. }
  155. public static void Decrypt(byte[] arr)
  156. {
  157. var len = Encoding.Default.GetString(arr).Replace("\0", "").Length;
  158. for (int i = 0; i < len; ++i)
  159. {
  160.  
  161. arr[i] ^= Key2[88 * i & 0x1F];
  162. arr[i] ^= Key[32 * i & 0x1C];
  163. }
  164. }
  165. }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement