C program for Encryption and Decryption of string - Code

Latest

programs

Sunday, October 30, 2011

C program for Encryption and Decryption of string




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;
}

No comments:

Post a Comment