C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Encryption »

Bit Wise Encryption & decryption


Posted Date: 21 May 2008    Resource Type: Code Snippets    Category: Encryption
Author: vivekMember Level: Bronze    
Rating: 1 out of 5Points: 10



//encryption

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

namespace LabMaster
{
public partial class encryption : Form
{
public encryption()
{
InitializeComponent();
}

int p = 0;
float b;
char t;



private void btns_Click(object sender, EventArgs e)
{



string str = txts.Text.Trim();

string[] s = new string[str.Length];
s = str.Split(' ');
string we = "";
char[] c = new char[str.Length];
for (int k = 0; k < s.Length; k++)
{

string q = s[k];
for (int j = 0; j < q.Length; j++)
{
c = q.ToCharArray();
int a = (int)c[j];
//mathamatical
a = a + 25500;
//assign
if (a % 2 == 0)
a = a + 202;
else
a = a + 200;
//bitwise conversion
if (p == k)
{
b = a / 255;
System.Math.Floor(b);
t = (char)b;
we = we + t.ToString();
a = a % 255;
t = (char)a;
we = we + t.ToString();


}
else
{
we = we + " ";
b = a / 255;
System.Math.Floor(b);
t = (char)b;
we = we + t.ToString();
a = a % 255;
t = (char)a;
we = we + t.ToString();
}

p = k;
}

}

txts.Text = string .Empty ;
txts.Text = we;



FileStream f1 = new FileStream("E:\\LabMaster\\LabMaster\\folders\\a.txt", FileMode.Truncate, FileAccess.Write);
StreamWriter w = new StreamWriter(f1);
w.Write(we);
w.Flush();
w.Close();
f1.Close();
}
}
}

//Decryption

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

namespace LabMaster
{
public partial class decryption : Form
{
int t; int r = 0;
string add,we;
public decryption()
{
InitializeComponent();
StreamReader sr = File.OpenText("E:\\LabMaster\\LabMaster\\folders\\a.txt");
while (sr.Peek() != -1)
{
string ina = sr.ReadLine();
add += ina;

}
char[] c = new char[add.Length];
string[] sre = add.Split(' ');
int o = (sre.Length) ;
for (int j = 0; j < o;j++ )
{
int temp=0;
string sd = sre[j];
c = sd.ToCharArray();

for (int i = 0; i < (c.Length - 1);i++ )
{

temp = 0;
r = 0;
r = (int)c[i];
i = i + 1;

t = (int)c[i];

//bit converction
r = (r * 255) + t;
temp = temp + r;
if (i==1 || i % 2 == 1)
{
r = r - 25500;
if (r % 2 == 0)
{
r = r - 202;


char ew = (char)r;
we = we + ew.ToString();
}
else
{
r = r - 200;


char ew = (char)r;
we = we + ew.ToString();
}
}

}
we = we + " ";
}
txtc.Text = we;
FileStream f1 = new FileStream("E:\\LabMaster\\LabMaster\\folders\\a1.txt", FileMode.Truncate, FileAccess.Write);
StreamWriter w = new StreamWriter(f1);
w.Write(we);
w.Flush();
w.Close();
f1.Close();
}
}
}



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Generating MD5 for a string
Previous Resource: Password Encryption And Decryption
Return to Discussion Resource Index
Post New Resource
Category: Encryption


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use