Sunday, May 20, 2018

Caesar Cipher Encryption - Decryption Program

/* Program to implement Caesar Cipher encryption and decryption technique.
*/

#include<iostream>
using namespace std;
int main()
{
int i;
char message[100], ch;
    cout<<"\nEnter the message for encryption: ";
    cin.getline(message,100);
    for(i=0;message[i]!='\0';++i)
{
        ch=message[i];
        if(ch>='a'&&ch<='z')
{
            ch=ch+3;
            if(ch>'z')
{
                ch=ch-'z'+'a'-1;
            }
            message[i]=ch;
        }
        else if(ch>='A'&&ch<='Z')
{
            ch=ch+3;
            if(ch>'Z')
{
                ch=ch-'Z'+'A'-1;
            }
            message[i]=ch;
        }
    }
    cout<<"Encrypted message: "<<message<<'\n'<<'\n';

char message1[100], ch1;
    cout<<"Enter the message for decryption: ";
    cin.getline(message1,100);
    for(i=0;message1[i]!='\0';++i)
{
        ch1=message1[i];
        if(ch1>='a'&&ch1<='z')
{
            ch1=ch1-3;
            if(ch1<'a')
{
                ch1=ch1+'z'-'a'+1;
            }
            message1[i]=ch1;
        }
        else if(ch1>='A'&&ch1<='Z')
{
            ch1=ch1-3;
            if(ch1>'a')
{
                ch1=ch1+'Z'-'A'+1;
            }
            message1[i]=ch1;
        }
    }
    cout<<"Decrypted message: "<<message1<<'\n'<<'\n';
    return 0;
}



OUTPUT SCREEN:



No comments:

Post a Comment

Project on Library Management System (C++)

=> The project titled Library Management system is Library management software for monitoring and controlling the transactions in a lib...