Advertisement
KekSec

crypter code

Jun 22nd, 2020
2,955
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1.     public static class Decryptor
  2.     {
  3.         public static byte[] Decrypt(byte[] key, byte[] data)
  4.         {
  5.             return EncryptOutput(key, data).ToArray();
  6.         }
  7.         private static byte[] EncryptInitalize(byte[] key)
  8.         {
  9.             byte[] s = Enumerable.Range(0, 256)
  10.               .Select(i => (byte)i)
  11.               .ToArray();
  12.  
  13.             for (int i = 0, j = 0; i < 256; i++)
  14.             {
  15.                 j = (j + key[i % key.Length] + s[i]) & 255;
  16.  
  17.                 Swap(s, i, j);
  18.             }
  19.  
  20.             return s;
  21.         }
  22.         private static IEnumerable<byte> EncryptOutput(byte[] key, IEnumerable<byte> data)
  23.         {
  24.             byte[] s = EncryptInitalize(key);
  25.  
  26.             int i = 0;
  27.             int j = 0;
  28.  
  29.             return data.Select((b) =>
  30.             {
  31.                 i = (i + 1) & 255;
  32.                 j = (j + s[i]) & 255;
  33.  
  34.                 Swap(s, i, j);
  35.  
  36.                 return (byte)(b ^ s[(s[i] + s[j]) & 255]);
  37.             });
  38.         }
  39.         private static void Swap(byte[] s, int i, int j)
  40.         {
  41.             byte c = s[i];
  42.  
  43.             s[i] = s[j];
  44.             s[j] = c;
  45.         }
  46.  
  47.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement