Information Security Worksheeet 1 20BCS8085

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

`

INFORMATION SECURITY
WORKSHEET’S

Submitted To: Submitted By:


Professor Shefali Goyal Esha Kaushal
UID-20BCS8085
Section -19BCS_IS_15
Group- B
Worksheet-1.1
AIM:- Write a code for Caesar Cipher.

THEORY:-
 Caesar Cipher is also known as a shift cipher.
 It is a type of symmetric-key cryptography.
 It follows the mono-alphabetic cipher, being a part of the substitution cipher.

Plain: abcdefghijklmnopqrstuvwxyz

Cipher: DEFGHIJKLMNOPQRSTUVWXYZABC

To encipher a message, simply look up each letter of the message in the "plain"
line and write down the corresponding letter in the "cipher" line. To decipher, do
the reverse.

Plaintext: the quick brown fox jumps over the lazy dog

Cipher text: WKH TXLFN EURZQ IRA MXPSV RYHU WKH ODCB GRJ

The encryption can also be represented using modular arithmetic by first


transforming the letters into numbers, according to the scheme, A = 0, B = 1,..., Z
= 25.

Steps for designing and using a Caesar cipher

 Choose a value to shift the alphabet by.


 Make a table where the top row contains letters in standard alphabetical order,
and the bottom row is the new shifted alphabet.
 Encode the message by exchanging each letter in the message with the
equivalent shifted letter.
 Make sure that the message’s intended recipient knows the shifting scheme
you used to encode the message so they can decode it.
 To decrypt a message encoded with a Caesar cipher, simply take the value of
26 minus the shift value, and apply that new value to shift the encoded
message back to its original form.

CODE:-

#include<bits/stdc++.h>

using namespace std;

int main()

char plain[10], cipher[10];

intkey,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:-

 Learnt to code for Caesar Cipher.


 Caesar Cipher technique is the simple and easy method of encryption
technique.
 It is simple type of substitution cipher.
 Each letter of plain text is replaced by a letter with some fixed number of
positions down with alphabet.

You might also like