How to Crypt Data simple and very efficient …

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace WindowsFormsApplication10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}
string unicodeString = “”;
Byte[] encodedBytes = new Byte[] { };
ASCIIEncoding ascii = new ASCIIEncoding();

Byte[] decodeBytes = new Byte[] { };

string decodedString = “”;
string set = “”;
char[] check;
Byte byteValue = 0;
// int app = 0;
string s = “”;
//char[] go;

private void button1_Click(object sender, EventArgs e)
{
textBox2.Text = “”;

// char[] alpha = new char[]{‘a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’,’i’,’j’,’k’,’l’,’m’,’n’,’o’,’p’,’q’,’r’,’s’,’t’,’u’,’v’,’w’,’x’,’y’,’z’};
// string s=””;

try
{

unicodeString = textBox1.Text;
unicodeString = unicodeString.ToLower();
encodedBytes = ascii.GetBytes(unicodeString);
int length = unicodeString.Length;

foreach (Byte b in encodedBytes)
{
//decodeBytes[0] =  (Byte)(b+5);
set += (b + 5).ToString();
// app += (int)(b + 5);
byteValue = (Byte)(b + length);
if (byteValue >= 123)
{
byteValue = (Byte)(byteValue – 26);

}
// s = System.Text.ASCIIEncoding.ASCII.GetString(encodedBytes);
//label1.Text=byteValue.ToString();
decodeBytes = BitConverter.GetBytes(byteValue);
s = ascii.GetString(decodeBytes);
//s += decodeBytes.ToString();

check = s.ToCharArray();

//check [] = set;

//if (check[a] == ‘%’)
//   check[a] = ‘ ‘;

//textBox2.Text += check[a];

//string.replac(decodeString,””);
// decodedString =  Regex.Replace(s, “[^a-zA-Z0-9]”, ” “, RegexOptions.Compiled);
// decodedString = decodedString.replace(“[^a-zA-Z0-9]”, “_”);
Regex re = new Regex(“[;\\\\/:*?\”<>|&%#’]”);
//

decodedString = re.Replace(s, ” “);

textBox2.Text += decodedString;

}

// foreach (Byte z in byteValue)
{

//   decodedString += z.ToString();
}

//decodeBytes = Encoding.ASCII.GetBytes(set);

//decodedString = ascii.GetString(byteValue);
//string s = System.Text.ASCIIEncoding.ASCII.GetString(decodeBytes);
// label2.Text = decodeBytes.ToString();

}
catch (FormatException)
{

textBox1.Text = “Invalid value”;

}
catch
{

textBox1.Text = “Wrong input”;
}
}

private void button2_Click(object sender, EventArgs e)
{
textBox3.Text = “”;
unicodeString = textBox1.Text;
unicodeString = unicodeString.ToLower();
encodedBytes = ascii.GetBytes(unicodeString);
int length = unicodeString.Length;

foreach (Byte b in encodedBytes)
{
//decodeBytes[0] =  (Byte)(b+5);
set += (b – 5).ToString();
// app += (int)(b + 5);
byteValue = (Byte)(b – length);
if (byteValue <= 96)
{
byteValue = (Byte)(byteValue + 26);

}
// s = System.Text.ASCIIEncoding.ASCII.GetString(encodedBytes);
//label1.Text = byteValue.ToString();
decodeBytes = BitConverter.GetBytes(byteValue);
s = ascii.GetString(decodeBytes);
//s += decodeBytes.ToString();

check = s.ToCharArray();

//check [] = set;

//if (check[a] == ‘%’)
//   check[a] = ‘ ‘;

//textBox2.Text += check[a];

//string.replac(decodeString,””);
// decodedString =  Regex.Replace(s, “[^a-zA-Z0-9]”, ” “, RegexOptions.Compiled);
// decodedString = decodedString.replace(“[^a-zA-Z0-9]”, “_”);
Regex re = new Regex(“[;\\\\/:*?\”<>|&%#0-9’A-Z]”);
//

decodedString = re.Replace(s, ” “);

textBox3.Text += decodedString;
}

}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s