XOR-шифрование на C#

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;
 }
 }
}

Скачать пример

Поблагодарить автора

Оставить комментарий

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>