mono alphabetic Cipher substitution technique
AIM:
To implement a program for encrypting a plain text and decrypting a cipher text using
mono alphabetic Cipher substitution technique.
CODE:
#include<iostream>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void encryption();
void decryption();
char pt[50],ct[50],ch;
char alpha[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char sub[26]={'q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m'};
int i,j;
using namespace std;
int main()
{
int choice;
cout<<"****Monoalphabetic Cipher Technique***";
cout<<"\n\n1. Encryption \t2. Decryption";
cout<<"\nEnter your choice: ";
cin>>choice;
switch(choice)
{
case 1: //Encryption
encryption();
break;
case 2: //Decryption
decryption();
break;
default: //Wrong Input
cout<<"\nIncorrect choice. Try again!!";
break;
}
cout<<"\n\nThank You.";
getch();
}
void encryption()
{
cout<<"\nEnter plain text: ";
cin>>pt;
for(i=0;i<strlen(pt);i++)
{
ch = pt[i];
for(j=0;j<26;j++)
{
if(alpha[j]==ch)
{
ct[i]=sub[j];
// break;
}
}
}
ct[i]='\0';
cout<<"\nThe cipher text is: ";
for(i=0;i<strlen(pt);i++)
cout<<ct[i];
}
void decryption()
{
cout<<"\nEnter cipher text: ";
cin>>ct;
for(i=0;i<strlen(ct);i++)
{
ch=ct[i];
for(j=0;j<26;j++)
{
if(sub[j]==ch)
{
pt[i]=alpha[j];
break;
}
}
}
pt[i]='\0';
cout<<"\nThe plain text is: ";
for(i=0;i<strlen(ct);i++)
cout<<pt[i];
}
OUTPUT:-
To implement a program for encrypting a plain text and decrypting a cipher text using
mono alphabetic Cipher substitution technique.
CODE:
#include<iostream>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void encryption();
void decryption();
char pt[50],ct[50],ch;
char alpha[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char sub[26]={'q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m'};
int i,j;
using namespace std;
int main()
{
int choice;
cout<<"****Monoalphabetic Cipher Technique***";
cout<<"\n\n1. Encryption \t2. Decryption";
cout<<"\nEnter your choice: ";
cin>>choice;
switch(choice)
{
case 1: //Encryption
encryption();
break;
case 2: //Decryption
decryption();
break;
default: //Wrong Input
cout<<"\nIncorrect choice. Try again!!";
break;
}
cout<<"\n\nThank You.";
getch();
}
void encryption()
{
cout<<"\nEnter plain text: ";
cin>>pt;
for(i=0;i<strlen(pt);i++)
{
ch = pt[i];
for(j=0;j<26;j++)
{
if(alpha[j]==ch)
{
ct[i]=sub[j];
// break;
}
}
}
ct[i]='\0';
cout<<"\nThe cipher text is: ";
for(i=0;i<strlen(pt);i++)
cout<<ct[i];
}
void decryption()
{
cout<<"\nEnter cipher text: ";
cin>>ct;
for(i=0;i<strlen(ct);i++)
{
ch=ct[i];
for(j=0;j<26;j++)
{
if(sub[j]==ch)
{
pt[i]=alpha[j];
break;
}
}
}
pt[i]='\0';
cout<<"\nThe plain text is: ";
for(i=0;i<strlen(ct);i++)
cout<<pt[i];
}
OUTPUT:-
Comments
Post a Comment