Bu yazımda xor şifrelemesinden bahsedeceğim.Basitce yazdığımız bir text veriyi xor algoritması ile encrypt edeceğiz ve daha sonrada şifrelediğimiz veriyi decrypt edeceğiz.Uygulama için yeni bir form açıp textbox ve bir adet buton ekliyoruz..Textbox ın multiline özelliğini aktif ediyoruz..(Etmeyebilirsiniz)[...]
[IMG SRC="http://img188.imageshack.us/img188/6413/referencesh.jpg" ALIGN="CENTER"]http://img188.imageshack.us/img188/6413/referencesh.jpg[/IMG]
Referanslarının ekli olduğundan emin olduktan sonra, kodlarımıza geçelim..
Formumuzun şekli;
[IMG SRC="http://img44.imageshack.us/img44/33/formi.jpg" ALIGN="CENTER"]http://img44.imageshack.us/img44/33/formi.jpg[/IMG]
CODE:
namespace XOREncryption
{
public partial class Form1 : Form
{
public Form1 (),
{
IntializeComponent();
}
private string XorText(string text, int key)
{
string newText ="";
for (int i =0; i < text.Length; i++)
{
int charValue = Convert.ToInt32(text[i]; // Karakterlerin Ascii değerini alıyoruz
charValue ^= key; // Xor değeri
newText += char.ConvertFromUtf32 (charValue); //Stringde karakterlerin Ascii değerini almıştık
//Aldığımız değeri Xor'a çeviriyoruz..
}
return newText;
}
private void btnEncrypt_Click(object sender, EventArgs e)
{
txtEditor.Text = XorText(txtEditor.Text, 354);
}
private void txtEditor_TextChanged(object sender, EventArgs e)
{
}
}
}
[IMG SRC="http://img3.imageshack.us/img3/1774/program1.jpg" ALIGN="CENTER"]http://img3.imageshack.us/img3/1774/program1.jpg[/IMG]
[IMG SRC="http://img44.imageshack.us/img44/2538/program2.jpg" ALIGN="CENTER"]http://img44.imageshack.us/img44/2538/program2.jpg[/IMG]
Oguzz
oguz@thecoders.net
11 Agustos 2009 22:14