Advertisement
yesh666

Encryption.c

Jun 3rd, 2022
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<string.h>
  4. #include<ctype.h>
  5. void main()
  6. {
  7.     char pwd[20];
  8.     char alpha[26]="abcdefghijklmnopqrstuvwxyz";
  9.     int num[20],i,n,key;
  10.     //clrscr();
  11.     printf("\nEnter the password:");
  12.     scanf("%s",&pwd);
  13.     n=strlen(pwd);
  14.     for(i=0;i<n;i++)
  15.         num[i]=toascii(tolower(pwd[i]))-'a';
  16.     printf("\nEnter the key:");
  17.     scanf("%d",&key);
  18.     for(i=0;i<n;i++)
  19.         num[i]=(num[i]+key)%26;
  20.     for(i=0;i<n;i++)
  21.         pwd[i]=alpha[num[i]];
  22.     printf("\nThe key is:%d",key);
  23.     printf("\nEncrypted text is:%s",pwd);
  24.     for(i=0;i<n;i++)
  25.     {
  26.         num[i]=(num[i]-key)%26;
  27.         if(num[i]<0)
  28.             num[i]=26+num[i];
  29.         pwd[i]=alpha[num[i]];
  30.     }
  31.     printf("\nDecrypted text is:%s",pwd);
  32.     getch();
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement