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 »

Code for encrypting and decrypting Input String


Posted Date: 22 Oct 2008    Resource Type: Code Snippets    Category: Encryption
Author: Avadhesh Kumar TiwariMember Level: Silver    
Rating: 1 out of 5Points: 10



The sample C# code shown below demonstrates the functions to encrypt and decrypt the given data. If you want to encrypt Your data and futher want to decrypt it to use . You can use this Class...

The Class has two functions EnCrypt and DeCrypt...


public class EncryptionAndDecryption
{
const char CharacterToFill = '@';
static string Key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

static public string EnCrypt(string str)
{
int count;
int ctr;
int size = str.Length;
string R="";

for (count = 0; count < size; ++count)
{
ctr = (str[count] >> 2) & 0x3f;
R +=Key[ctr];
ctr = (str[count] << 4) & 0x3f;
if (++count < size)
ctr |= (str[count] >> 4) & 0x0f;

R += Key[ctr];
if (count < size)
{
ctr = (str[count] << 2) & 0x3f;
if (++count < size)
ctr |= (str[count] >> 6) & 0x03;

R += Key[ctr];
}
else
{
++count;
R += CharacterToFill;
}

if (count < size)
{
ctr = str[count] & 0x3f;
R += Key[ctr];
}
else
{
R += CharacterToFill;
}
}

return(R);
}

static public string DeCrypt(string str)
{
string R="";
int count;
char ctr;
char ctrNext;
int size = str.Length;

for (count = 0; count < size; ++count)
{
ctr = (char) Key.IndexOf(str[count]);
++count;
ctrNext = (char) Key.IndexOf(str[count]);
ctr = ((char)((ctr << 2) | ((ctrNext >> 4) & 0x3)));
R += ctr;
if (++count < size)
{
ctr = str[count];
if (CharacterToFill == ctr)
break;

ctr = (char) Key.IndexOf(ctr);
ctrNext = (char)(((ctrNext << 4) & 0xf0) | ((ctr >> 2) & 0xf));
R += ctrNext;
}

if (++count < size)
{
ctrNext = str[count];
if (CharacterToFill == ctrNext)
break;

ctrNext = (char) Key.IndexOf(ctrNext);
ctr = (char)(((ctr << 6) & 0xc0) | ctrNext);
R += ctr;
}
}
return(R);
}
}





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.
Encrypt input data and for further use Decrypt it  .  

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: Password Encription c#
Previous Resource: Oracle Function for Password encryption
Return to Discussion Resource Index
Post New Resource
Category: Encryption


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use