Sunday, May 5, 2013

Encryption and Decryption of string in C++


Encryption and Decryption of string
#include <stdio.h>
#include <string.h>

void encrypt(char str[],int key)
{
    unsigned int i;
    for(i=0;i<strlen(str);++i)
    {
          str[i] = str[i] - key;
    }
}

void decrypt(char str[],int key)
{
    unsigned int i;
    for(i=0;i<strlen(str);++i)
    {
          str[i] = str[i] + key;
    }
}
int main()
{
     char str[] = "smurffANDkdo";
     printf("Passwrod     = %s\n",str);
     encrypt(str,0xFACA);
     printf("Encrypted value = %s\n",str);     
     decrypt(str,0xFACA);
     printf("Decrypted value = %s\n",str);
     return 0;
}

1 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More