For doing a simple cryptography we have write a simple code in Windows Form View of Visual Studio.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int key;
int[] data = new int[8] { 0, 0, 0, 0, 0, 0, 0, 0 };
private void button1_Click(object sender, EventArgs e)
{
int dno;
dno = Convert.ToInt16(textBox1.Text);
key = Convert.ToInt16(textBox2.Text);
int rem;
int[] a = new int[8] { 0, 0, 0, 0, 0, 0, 0, 0 };
int i = 7;
while (dno > 0)
{
rem = dno % 2;
dno /= 2;
a[i] = rem;
i--;
}
int rem2;
int j = 7;
while (key > 0)
{
rem2 = key % 2;
key /= 2;
a2[j] = rem2;
j--;
}
{
if (a[k] == a2[k])
{
data[k] = 0;
}
else
{
data[k] = 1;
}
}
//Applying NOR
for (int l = 0; l <= 7; l++)
{
if (data[l] == 1)
{
data[l] = 0;
}
else
{
data[l] = 1;
}
}
//Applying Shifting
int m = 0;
int temp = 0;
temp = data[m];
while (m <= 6)
{
data[m] = data[m + 1];
m++;
}
data[m] = temp;
// 2nd Time Shifting
m = 0;
temp = data[m];
while (m <= 6)
{
data[m] = data[m + 1];
m++;
}
data[m] = temp;
temp = data[m];
while (m <= 6)
{
data[m] = data[m + 1];
m++;
}
data[m] = temp;
string ds = "";
for (int d = 0; d <= 7; d++)
{
ds += Convert.ToString(data[d]);
}
textBox3.Text = ds;
}
private void button2_Click(object sender, EventArgs e)
{
int a;
int temp;
//Applying Back Shiffting's...
for (int i = 0; i <= 2; i++)
{
a = 7;
temp = data[a];
while (a >= 1)
{
data[a] = data[a - 1];
a--;
}
data[a] = temp;
}
{
if (data[l] == 1)
{
data[l] = 0;
}
else
{
data[l] = 1;
}
}
//Applying XOR
for (int k = 0; k <= 7; k++)
{
if (data[k] == a2[k])
{
data[k] = 0;
}
else
{
data[k] = 1;
}
}
for (int f = 7, k = 1; f >= 0; f--)
{
s += data[f] * k;
k *= 2;
}
textBox4.Text = Convert.ToString(s);
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Cryptografhy
{public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int key;
//Data And key is Global
int[] a2 = new int[8] { 0, 0, 0, 0, 0, 0, 0, 0 };int[] data = new int[8] { 0, 0, 0, 0, 0, 0, 0, 0 };
private void button1_Click(object sender, EventArgs e)
{
int dno;
dno = Convert.ToInt16(textBox1.Text);
key = Convert.ToInt16(textBox2.Text);
int rem;
int[] a = new int[8] { 0, 0, 0, 0, 0, 0, 0, 0 };
int i = 7;
while (dno > 0)
{
rem = dno % 2;
dno /= 2;
a[i] = rem;
i--;
}
int rem2;
int j = 7;
while (key > 0)
{
rem2 = key % 2;
key /= 2;
a2[j] = rem2;
j--;
}
//Applying XOR
for (int k = 0; k <= 7; k++){
if (a[k] == a2[k])
{
data[k] = 0;
}
else
{
data[k] = 1;
}
}
//Applying NOR
for (int l = 0; l <= 7; l++)
{
if (data[l] == 1)
{
data[l] = 0;
}
else
{
data[l] = 1;
}
}
//Applying Shifting
int m = 0;
int temp = 0;
temp = data[m];
while (m <= 6)
{
data[m] = data[m + 1];
m++;
}
data[m] = temp;
// 2nd Time Shifting
m = 0;
temp = data[m];
while (m <= 6)
{
data[m] = data[m + 1];
m++;
}
data[m] = temp;
//Applying 3rd Shifting
m = 0;temp = data[m];
while (m <= 6)
{
data[m] = data[m + 1];
m++;
}
data[m] = temp;
string ds = "";
for (int d = 0; d <= 7; d++)
{
ds += Convert.ToString(data[d]);
}
textBox3.Text = ds;
}
private void button2_Click(object sender, EventArgs e)
{
int a;
int temp;
//Applying Back Shiffting's...
for (int i = 0; i <= 2; i++)
{
a = 7;
temp = data[a];
while (a >= 1)
{
data[a] = data[a - 1];
a--;
}
data[a] = temp;
}
//Applying NOR
for (int l = 0; l <= 7; l++){
if (data[l] == 1)
{
data[l] = 0;
}
else
{
data[l] = 1;
}
}
//Applying XOR
for (int k = 0; k <= 7; k++)
{
if (data[k] == a2[k])
{
data[k] = 0;
}
else
{
data[k] = 1;
}
}
//Applying Conversion
int s = 0;for (int f = 7, k = 1; f >= 0; f--)
{
s += data[f] * k;
k *= 2;
}
textBox4.Text = Convert.ToString(s);
}
}
}
0 comments:
Post a Comment