AIM: Implement data encryption and data decryption.

Theory:

Data encryption standard was widely adopted by the industry in security products. Plain text is encrypted in blocks of 64 bits yielding 64 bits of cipher text. The algorithm which is parameterized by a 56 bit key has 19 distinct stages. The first stage is a key independent transposition and the last stage is exactly inverse of the transposition. The remaining stages are functionally identical but are parameterized by different functions of the key. The algorithm has been designed to allow decryption to be done with the same key as encryption

Program:

 

#include<stdio.h>

#include<string.h> 

#include<ctype.h>

void main()

{

 char pwd[20];

 char alpha[26]=”abcdefghijklmnopqrstuvwxyz”;

 int num[20],i,n,key;

 printf(“\nEnter the password:”);

 scanf(“%s”,&pwd); 

 n=strlen(pwd);

 for(i=0;i<n;i++)

 num[i]=toascii(tolower(pwd[i]))-‘a’;

 printf(“\nEnter the key:”); 

 scanf(“%d”,&key); 

 for(i=0;i<n;i++)

 num[i]=(num[i]+key)%26; 

 for(i=0;i<n;i++)

 pwd[i]=alpha[num[i]]; 

 printf(“\nThe key is:%d”,key);

 printf(“\nEncrypted text is:%s”,pwd); 

 for(i=0;i<n;i++)

 {

 

 num[i]=(num[i]-key)%26;

 if(num[i]<0)

 num[i]=26+num[i];

 pwd[i]=alpha[num[i]];

 }

 printf(“\nDecrypted text is:%s”,pwd);

 

 

Output:

output-of-des