Advertisement
KekSec

crypter code #2

Jun 22nd, 2020
3,473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Security.Cryptography;
  6. using System.Text;
  7. using System.Drawing;
  8.  
  9. public static class Encrypt
  10. {
  11.  
  12.     static byte[] KEY = null;
  13.     static byte[] IV = null;
  14.     static byte[] payload = null;
  15.  
  16.     private static byte[] EncryptBytes(IEnumerable<byte> bytes)
  17.     {
  18.         //The ICryptoTransform is created for each call to this method as the MSDN documentation indicates that the public methods may not be thread-safe and so we cannot hold a static reference to an instance
  19.         using (var r = Rijndael.Create())
  20.         {
  21.             using (var encryptor = r.CreateEncryptor(KEY, IV))
  22.             {
  23.                 return Transform(bytes, encryptor);
  24.             }
  25.         }
  26.     }
  27.     private static byte[] DecryptBytes(IEnumerable<byte> bytes)
  28.     {
  29.         //The ICryptoTransform is created for each call to this method as the MSDN documentation indicates that the public methods may not be thread-safe and so we cannot hold a static reference to an instance
  30.         using (var r = Rijndael.Create())
  31.         {
  32.             using (var decryptor = r.CreateDecryptor(KEY, IV))
  33.             {
  34.                 return Transform(bytes, decryptor);
  35.             }
  36.         }
  37.     }
  38.     private static byte[] Transform(IEnumerable<byte> bytes, ICryptoTransform transform)
  39.     {
  40.         using (var stream = new MemoryStream())
  41.         {
  42.             using (var cryptoStream = new CryptoStream(stream, transform, CryptoStreamMode.Write))
  43.             {
  44.                 foreach (var b in bytes)
  45.                     cryptoStream.WriteByte(b);
  46.             }
  47.  
  48.             return stream.ToArray();
  49.         }
  50.     }
  51.     public static class Encryption_Class
  52.     {
  53.         public static string Encrypt(string key, string data)
  54.         {
  55.             Encoding unicode = Encoding.Unicode;
  56.  
  57.             return Convert.ToBase64String(Encrypt(unicode.GetBytes(key), unicode.GetBytes(data)));
  58.         }
  59.  
  60.         public static string Decrypt(string key, string data)
  61.         {
  62.             Encoding unicode = Encoding.Unicode;
  63.  
  64.             return unicode.GetString(Encrypt(unicode.GetBytes(key), Convert.FromBase64String(data)));
  65.         }
  66.  
  67.         public static byte[] Encrypt(byte[] key, byte[] data)
  68.         {
  69.             return EncryptOutput(key, data).ToArray();
  70.         }
  71.  
  72.         public static byte[] Decrypt(byte[] key, byte[] data)
  73.         {
  74.             return EncryptOutput(key, data).ToArray();
  75.         }
  76.  
  77.         private static byte[] EncryptInitalize(byte[] key)
  78.         {
  79.             byte[] s = Enumerable.Range(0, 256)
  80.               .Select(i => (byte)i)
  81.               .ToArray();
  82.  
  83.             for (int i = 0, j = 0; i < 256; i++)
  84.             {
  85.                 j = (j + key[i % key.Length] + s[i]) & 255;
  86.  
  87.                 Swap(s, i, j);
  88.             }
  89.  
  90.             return s;
  91.         }
  92.  
  93.         private static IEnumerable<byte> EncryptOutput(byte[] key, IEnumerable<byte> data)
  94.         {
  95.             byte[] s = EncryptInitalize(key);
  96.  
  97.             int i = 0;
  98.             int j = 0;
  99.  
  100.             return data.Select((b) =>
  101.             {
  102.                 i = (i + 1) & 255;
  103.                 j = (j + s[i]) & 255;
  104.  
  105.                 Swap(s, i, j);
  106.  
  107.                 return (byte)(b ^ s[(s[i] + s[j]) & 255]);
  108.             });
  109.         }
  110.  
  111.         private static void Swap(byte[] s, int i, int j)
  112.         {
  113.             byte c = s[i];
  114.  
  115.             s[i] = s[j];
  116.             s[j] = c;
  117.         }
  118.     }
  119.  
  120.  
  121.  
  122. }
  123.  
  124. namespace ThanatosCrypt
  125. {
  126.     class Program
  127.     {
  128.  
  129.         public static int FindBytes(byte[] src, byte[] find)
  130.         {
  131.             if (src == null || find == null || src.Length == 0 || find.Length == 0 || find.Length > src.Length) return -1;
  132.             for (int i = 0; i < src.Length - find.Length + 1; i++)
  133.             {
  134.                 if (src[i] == find[0])
  135.                 {
  136.                     for (int m = 1; m < find.Length; m++)
  137.                     {
  138.                         if (src[i + m] != find[m]) break;
  139.                         if (m == find.Length - 1) return i;
  140.                     }
  141.                 }
  142.             }
  143.             return -1;
  144.         }
  145.         public static byte[] ReplaceBytes(byte[] src, byte[] search, byte[] repl)
  146.         {
  147.             if (repl == null) return src;
  148.             int index = FindBytes(src, search);
  149.             if (index < 0) return src;
  150.             byte[] dst = new byte[src.Length - search.Length + repl.Length];
  151.             Buffer.BlockCopy(src, 0, dst, 0, index);
  152.             Buffer.BlockCopy(repl, 0, dst, index, repl.Length);
  153.             Buffer.BlockCopy(src, index + search.Length, dst, index + repl.Length, src.Length - (index + search.Length));
  154.             return dst;
  155.         }
  156.         public static string generateicon() {
  157.             int width = 50;
  158.             int height = 50;
  159.             Bitmap bitmap = new Bitmap(width, height);
  160.             Random rand = new Random();
  161.             for (int y = 0; y < height - 1; y++)
  162.             {
  163.                 for (int x = 0; x < width - 1; x++)
  164.                 {
  165.                     int r = rand.Next(256);
  166.                     int g = rand.Next(256);
  167.                     int b = rand.Next(256);
  168.                     bitmap.SetPixel(x, y, Color.FromArgb(r, g, b));
  169.                 }
  170.             }
  171.             IntPtr HIcon = bitmap.GetHicon();
  172.             Icon newIcon = Icon.FromHandle(HIcon);
  173.  
  174.             string finalpath = Path.GetTempPath() + "randomicon.ico";
  175.  
  176.             FileStream oFileStream = new System.IO.FileStream(finalpath, FileMode.CreateNew);
  177.             newIcon.Save(oFileStream);
  178.             oFileStream.Close();
  179.             return finalpath;
  180.         }
  181.         static void Main(string[] args)
  182.         {
  183.  
  184.             Console.WriteLine("Random icon location: " + generateicon());
  185.             Console.Write("Input file to crypt: ");
  186.             string input = Console.ReadLine().Replace("\r", "").Replace("\n", "");
  187.             Console.WriteLine();
  188.             Console.Write("Output file: ");
  189.             string output = Console.ReadLine().Replace("\r", "").Replace("\n", "");
  190.             File.WriteAllBytes(output, Encrypt.Encryption_Class.Encrypt(Encoding.ASCII.GetBytes("DSNVLUOHFWE"), File.ReadAllBytes(input)));
  191.  
  192.         }
  193.     }
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement