August 18, 2018

Monoalphabetic Cipher in C (Encryption & Decryption)

Mono Alphabetic Cipher

C Program:

#include<stdio.h>
#include<conio.h>
#include<string.h>
#define pf printf
#define sf scanf
char dc[26]="XDGSZANYOBTMJCEVFHKWPLQURI";
char ec[26]="abcdefghijklmnopqrstuvwxyz";
void e(char*);
void d(char*);
void main(){
char *p;
clrscr();
pf("\n\nEnter plain text:");
sf("%s",p);
pf("\nAfter Encryption:\n-----------------\n");
e(p);
pf("\n%s",p);
pf("\nAfter Decryption:\n-----------------\n");
d(p);
pf("\n%s",p);
getch();
}
void e(char *p){
int l=0;
while(*(p+l) != '\0'){
*(p+l)=dc[*(p+l)-97];
l++;
}
}
void d(char *p){
int l=0;
while(*(p+l) != '\0'){
int i;
for(i=0;i<26;i++){
if(dc[i]==*(p+l))
break;
}
*(p+l)=ec[i];
l++;
}
}

post written by: Author

Related Posts

2 comments:

Note: Only a member of this blog may post a comment.