
using System;
using System.Text;
namespace XORcrypt
{
class Program
{
static void Main(string[] args)
{
string text = "hello, world";
int key = 123;
string encText = XorCrypt(text, key);
string normText = XorCrypt(encText, key);
Console.WriteLine("Encoded string: {0}", encText);
Console.WriteLine("Decoded string: {0}", normText);
Console.ReadKey();
}
static string XorCrypt(string text, int key)
{
string newText = "";
for (int i = 0; i < text.Length; i++)
{
// Получаем ASCII-код символа
int charValue = Convert.ToInt32(text[i]);
// XOR-им символ
charValue ^= key;
// Преобразуем результат обратно в строку
newText += char.ConvertFromUtf32(charValue);
}
return newText;
}
}
}
Скачать пример