We are using Data Structure for Encryption / Decryption the Code . Class named Cypher in which we introduce a 'char' and 'int' for input but we convert it by using the user given char to it ascii number .
There are many functions we will discuss them one by one .
'Code()' This function is used to convert the given paragraph from user to the encrypted code .
'Display()' This function is used to convert the Encrypted code to normal meaning full paragraph it is a Decryption function .
'Ask()' This Function takes input from user and return the input to the class .
"^" This is used for Exit the program
"<" This is used for Decrypt
">" This is used for Encrypt
But You Have to Write the Whole paragraph with first alphabet Capital letter .
'insert_at_end()' Function inserts the string to node of every character .
****************************************************************************************************************************************************************************************************************
#include<iostream>
#include<conio.h>
using namespace std;
class node{
char data;
int outs;
node* next;
node* pre;
public:
node(){
data=' ';
next=NULL;
pre=NULL;
}
char get_d(){
return data;
}
int get_o(){
return outs;
}
node* get_nxt(){
return next;
}
node* get_pre(){
return pre;
}
void set_d(char d){
data=d;
}
void set_o(int o){
outs=o;
}
void set_nxt(node* n){
next=n;
}
void set_pre(node* p){
pre=p;
}
};
class Cypher{
node* head;
int n;
public:
Cypher(){
n=1;
head=NULL;
}
void code(){
int ascii;
node* temp=head;
cout<<"Encrypted Code :"<<endl;
cout<<endl;
while(temp!=NULL){
if(temp->get_o()>64 && temp->get_o()<91){
cout<<" ";
if(temp->get_o()==65){
ascii=90;
}
else{
ascii=(temp->get_o()-n);
}
}
else{
if(temp->get_o()==97){
ascii=122;
}
else{
ascii=(temp->get_o()-n);
}
}
char ch = char(ascii);
cout<<ch;
temp=temp->get_nxt();
}
exit(0);
}
void display(){
int ascii;
node* tf=head;
cout<<"Real Message :"<<endl;
cout<<endl;
while(tf!=NULL){
if(tf->get_d()>64 && tf->get_d()<91){
cout<<" ";
if(tf->get_o()==90){
ascii=65;
}
else{
ascii=(tf->get_o()+n);
}
}
else{
if(tf->get_o()==122){
ascii=97;
}
else{
ascii=(tf->get_o()+n);
}
}
char ch = char(ascii);
cout<<ch;
tf=tf->get_nxt();
}
exit(0);
}
char ask(){
char val;
cin>>val;
if(val=='^'){
exit(0);
}
if(val=='<'){
cout<<endl;
display();
}
if(val=='>'){
cout<<endl;
code();
}
return val;
}
void insert_at_start(){
char val;
val=ask();
if(head==NULL){
node* newnode = new node();
newnode->set_d(val);
newnode->set_o(val);
newnode->set_nxt(head);
head=newnode;
}
}
void insert_at_end(){
char val;
if(head==NULL){
insert_at_start();
}
else{
val=ask();
node* newnode = new node();
newnode->set_d(val);
newnode->set_o(val);
node* temp=head;
while(temp->get_nxt()!=NULL){
temp=temp->get_nxt();
}
temp->set_nxt(newnode);
newnode->set_pre(temp);
}
}
};
int main(){
Cypher convert;
cout<<"Press '^' to end the program "<<endl;
cout<<"Press '<' to show Real Message "<<endl;
cout<<"Press '>' to Show INCRUPTED Message "<<endl;
cout<<"Note : Every Word Should Be In Capital Form Same As This "<<endl;
cout<<endl;
cout<<"start writting Message "<<endl;
cout<<endl;
while(1){
convert.insert_at_end();
}
return 0;
}
***************************************************************************************************************************************************************************************************************
OUTPUT:
Encrypt
Decrypt
Comments
Post a Comment