You are on page 1of 3

NAME: HIMANSHI SUBJECT-INORMATION SECURITY LAB

SECTION: 19 IS 15-B DATE-13/02/2022


UID-20BCS8112

PRACTICAL 1: PERFORM THE PRACTICAL OF CEASAR CIPHER.


OBJECTIVE: CAESAR CIPHER IS BASICALLY USED FOR ENCRYPTION AND DECRYPTION AND
FOR DATA SECURITY. IN THIS, WE HAVE TO GIVE THE VALUE OF KEY AND WITH THAT KEY
ONE IS ABLE TO ENCRYPT AND DECRYPT THE DATA.
FOR EXAMPLE: I WANT TO ENCRYPT THE MESSAGE: HIMANSHI USING KEY=3, THEN AFTER
ENCRYPTION THE TEXT WILL BE: KLPDQVKL
This is also known as SYMMETRIC KEY CRYPTOGRAHY.
DECRYPTION IS ALSO PRFORMED SIMILARLY.
CODE FOR ENCRYPTION AND DECRYPTION:
#include<bits/stdc++.h>
using namespace std;

int main()

char plain[10], cipher[10];

int key,i,length;

int result;

cout<<"Enter the plain text"<<endl;

cin>> plain;
cout<<"enter the key value"<<endl;

cin>>key;

cout<<plain<<endl;

cout<< "encrypted text: "<<endl ;

for(i = 0, length = strlen(plain); i < length; i++)

cipher[i]=plain[i] + key;

if (isupper(plain[i]) && (cipher[i] > 'Z')) cipher[i] = cipher[i] - 26;

if (islower(plain[i]) && (cipher[i] > 'z')) cipher[i] = cipher[i] - 26;

cout<<cipher[i];

cout<<"\n AFTER DECRYPTION ";

for(i=0;i<length;i++)

{
plain[i]=cipher[i]-key;
if(isupper(cipher[i])&&(plain[i]<'A'))
plain[i]=plain[i]+26;
if(islower(cipher[i])&&(plain[i]<'a'))
plain[i]=plain[i]+26;
cout<<plain[i];
}
}
}
OUTPUT:

LEARNING OUTCOMES:
A Caesar cipher is very easy to design, but also very easy to decode. To crack a Caesar code, a
decoder could simply go through every possible shift of the alphabet (all 2626 of them) and see if
any sensible message appears

You might also like