public interface ICryptoPlugin
byte[] Encrypt(string data);
string Decrypt(byte[] data);
public class SimpleCrypto : ICryptoPlugin
private string _secretKey;
public SimpleCrypto(string secretKey)
public string Decrypt(byte[] data)
string encryptedContent = Encoding.UTF8.GetString(data);
string decryptedContent = XOR(encryptedContent);
public byte[] Encrypt(string data)
string encryptedContent = XOR(data);
return Encoding.UTF8.GetBytes(encryptedContent);
public string XOR(string content)
StringBuilder resultBuffer = new StringBuilder();
for (int i = 0; i < content.Length; ++i)
uint charCode = (uint)content[i];
uint keyCode = (uint)_secretKey[i % _secretKey.Length];
resultBuffer.Append((char)(charCode ^ keyCode));
return resultBuffer.ToString();
public class SimpleCrypto1 : ICryptoPlugin
private string _secretKey;
StringBuilder resultBuffer = new StringBuilder();
public SimpleCrypto1(string secretKey)
public string Decrypt(byte[] data)
string encryptedContent = Encoding.UTF8.GetString(data);
string decryptedContent = XOR(encryptedContent);
public byte[] Encrypt(string data)
string encryptedContent = XOR(data);
return Encoding.UTF8.GetBytes(encryptedContent);
public string XOR(string content)
for (int i = 0; i < content.Length; ++i)
uint charCode = (uint)content[i];
uint keyCode = (uint)_secretKey[i % _secretKey.Length];
resultBuffer.Append((char)(charCode ^ keyCode));
return resultBuffer.ToString();
public class SimpleCrypto2 : ICryptoPlugin
private string _secretKey;
public SimpleCrypto2(string secretKey)
public string Decrypt(byte[] data)
public byte[] Encrypt(string data)
public byte[] XOR(string content)
byte[] bytes = new byte[content.Length];
for (int i = 0; i < content.Length; ++i)
bytes[i] = (byte)(content[i] ^ _secretKey[i % _secretKey.Length]);
public class SimpleCrypto3 : ICryptoPlugin
private string _secretKey;
byte[] bytes = new byte[1];
public SimpleCrypto3(string secretKey)
public string Decrypt(byte[] data)
public byte[] Encrypt(string data)
public byte[] XOR(string content)
if (bytes.Length < content.Length)
Array.Resize<byte>(ref bytes, content.Length);
for (int i = 0; i < content.Length; ++i)
bytes[i] = (byte)(content[i] ^ _secretKey[i % _secretKey.Length]);
public static void Main()
string str = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
ICryptoPlugin crypto = new SimpleCrypto("com.magmic.simple.hearts");
ICryptoPlugin crypto1 = new SimpleCrypto1("com.magmic.simple.hearts");
ICryptoPlugin crypto2 = new SimpleCrypto2("com.magmic.simple.hearts");
ICryptoPlugin crypto3 = new SimpleCrypto3("com.magmic.simple.hearts");
for (int i = 0; i < 1000; i++)
public static string ByteArrayToString(byte[] ba)
return BitConverter.ToString(ba).Replace("-","");