Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | None | 0 0
  1.     public class AuthProtocolCryptographer
  2.     {
  3.         internal class CryptCounter
  4.         {
  5.             UInt16 m_Counter = 0;
  6.  
  7.             public byte Key2
  8.             {
  9.                 get { return (byte)(m_Counter >> 8); }
  10.             }
  11.  
  12.             public byte Key1
  13.             {
  14.                 get { return (byte)(m_Counter & 0xFF); }
  15.             }
  16.  
  17.             public void Increment()
  18.             {
  19.                 m_Counter++;
  20.             }
  21.         }
  22.  
  23.         private CryptCounter _decryptCounter;
  24.         private CryptCounter _encryptCounter;
  25.         private byte[] _cryptKey1;
  26.         private byte[] _cryptKey2;
  27.  
  28.         public AuthProtocolCryptographer()
  29.         {
  30.             _decryptCounter = new CryptCounter();
  31.             _encryptCounter = new CryptCounter();
  32.             _cryptKey1 = new byte[0x100];
  33.             _cryptKey2 = new byte[0x100];
  34.             byte i_key1 = 0x9D;
  35.             byte i_key2 = 0x62;
  36.             for (int i = 0; i < 0x100; i++)
  37.             {
  38.                 _cryptKey1[i] = i_key1;
  39.                 _cryptKey2[i] = i_key2;
  40.                 i_key1 = (byte)((0x0F + (byte)(i_key1 * 0xFA)) * i_key1 + 0x13);
  41.                 i_key2 = (byte)((0x79 - (byte)(i_key2 * 0x5C)) * i_key2 + 0x6D);
  42.             }
  43.         }
  44.  
  45.         public void Encrypt(byte[] buffer)
  46.         {
  47.             for (int i = 0; i < buffer.Length; i++)
  48.             {
  49.                 buffer[i] ^= (byte)(_cryptKey1[_encryptCounter.Key1] ^ _cryptKey2[_encryptCounter.Key2]);
  50.                 buffer[i] = (byte)(buffer[i] >> 4 | buffer[i] << 4);
  51.                 buffer[i] ^= (byte)0xAB;
  52.                 _encryptCounter.Increment();
  53.             }
  54.         }
  55.  
  56.         public void Decrypt(byte[] buffer)
  57.         {
  58.             for (int i = 0; i < buffer.Length; i++)
  59.             {
  60.                 buffer[i] ^= (byte)0xAB;
  61.                 buffer[i] = (byte)(buffer[i] >> 4 | buffer[i] << 4);
  62.                 buffer[i] ^= (byte)(_cryptKey2[_decryptCounter.Key2] ^ _cryptKey1[_decryptCounter.Key1]);
  63.                 _decryptCounter.Increment();
  64.             }
  65.         }
  66.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement