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

Encryption and

Decryption by
using Block and
Ceaser Cypher

Abu bakar Dawood

Mts 32 Syn A

Submitted to:
Ma’m Uzma Akbar

Dated: May 1, 2011


2

Table of Contents Page #

1 Introduction 3

2 Methodology 3

3 Experimentation 4

4 Experimental Result 7

5 Conclusion 7

6 Abstract 7
3

1. Introduction
The concept of encryption and decryption can be basically used in the fields where there is
needed some encoding for the communication of highly confidential documents or messages.
The block cypher converts the entered data in to the form so that the number are mixed in such
a way that there is the next sixth character after the first .
While the Ceaser cypher is rather more complicated as compared to the block cypher. In this
type the program asks the user to enter the shift that is the number upto which the phrase
should be jumped. If the number entered is 1 then the program will print ‘b’ instead of ‘a’.
The program was designed purely for this purpose and the objective is that this program can
easily encode the words either in upper case or the lower case and can also work efficiently
even if they are intermixed.

2. Methodology
The problem of Block Cypher can be handled by using nested FOR loops the outer initializing
from 0 and working under the condition if the variable works less than and equal to 5 while the
nested loop initializes from the 0 and works if the variables varies equal and less than 35. The
variables in the first loop increases by 1 while in the nested the loop increases by 6.
The output is written inside the nested loop and the is as follow
Array[variable in the first loop +variable in the second loop].
Hence the output is in the form such that the sixth letter is printed after the first.
The decryption can be done in the same way.

The problem in the Ceaser Cypher can be handled by using the ASCII codes.
The user enters the data that is to be encrypted and then adds the Shift number in the ASCII
codes that is also the user defined. The character of that ASCII number is printed and hence it is
in the encrypted form.
If the ASCII codes for the lower case letters exceed by 122 then 26 are subtracted from the ASCII
hence the appropriate character is printed.
Similarly for Decoding the shift parameter is subtracted from the ASCII and if the ASCII falls by 97
after subtraction then 26 is added to get the appropriate number.

3. Experimentation
#include<iostream.h> // header file
void main() // main program starts
{ char ch; // defining the characters
int a,b,c, result,shift,r; //initialinzing the integer
for(int i=1;;i++) //starting the for loop
{
unsigned char input[37]={0}; //initializing the string
unsigned char caeser[37]={0}; //initializing the string
char encrypt[37]={0}; //initializing the string
cout<<endl<<endl;
cout<<" Enter the operation you want to perform "<<endl; //prompt
4

cout<<" If you want to encrypt the input then press 1 "<<endl; //for the encryption the input should be 1
cout<<" If you want to decrypt the input then press 2 "<<endl; //for the decryption the input should be 2
cout<<" If you want to exit then press 3 "<<endl; // to exit the input should be 3
cin>>a; // the input
if (a==1) //condition if the input is 1
{
cout<<" Select the cypher you want to use "<<endl; // the selection of the cypher
cout<<" 1 for Block cypher "<<endl; // to use block cyphe fot the encrytion input should be 1
cout<<" 2 for caeser cypher "<<endl; // to use the caeser cypher for the encryption input should be 2
cout<<" 3 to exit "<<endl; // the input should be 3 to return to the main menu
cin>>b; // the input
if (b==1) // the condition if the input is 1
{
cout<<" Enter the phrase "<<endl; // prompt
unsigned char input[37]={0}; // the declaration of the string
cin>>input; // taking the input into the string
for(int i=0;i<=5;i++) // the for loopfor the output of the string
{
for(int j=0;j<=35;j=j+6) //nested for loop fot the output of the string
{
cout<<input[i+j]<<"|"; // the output of the string
}
cout<<endl;
}
cout<<endl;
cout<<endl;
for(int g=0;g<=5;g++) // the for loop for the output of the string
{
for(int j=0;j<=35;j=j+6) //nested for loop fot the output of the string
{
cout<<input[g+j]; // the output of the string
}
}
cout<<endl<<endl;
cout<<" Enter 'E' to return to the main menu "<<endl; //prompt to return to the main menu
cin>>ch; // the input
if(ch!='E') //the condition if the input is not equal to the 'E'
{
cout<<" The program is ending "<<endl; // output if the input is not equal to 'E'
break; // the break statement
}
}
if (b==2) // the condition for the selection of caeser encryption
{
cout<<" Enter the phrase to be encrypted "<<endl; // prompt
unsigned char input[37]; // the declaration of the string
cin>>input; // the input to the string
cout<<" Enter the shift you want "<<endl; // prompt for the shift
cin>>shift; // the input to the shift
for (int i=0;i<36;i++) // for loop for the output of the string
{
int c;
r=(int)input[i];
result=(int)input[i]+shift; // the ascii of the decrypted letter
if ((96<r)&&(r<123)) // the condition if ascii is inbetween 97 and 122
{
if (result>=122) // the condition if the result is greater than 122
{
c=result%122; // the remainder of 122
cout<<(char)(97+c); // the result of the program
}
else
{
cout<<(char)(result); // the result
}
}
5

else if ((64<r)&&(r<91)) // the condition if ascii is inbetween 97 and 122


{
if ((64<result)&&(result<90)) // if the result is in between 64 and 90
{
cout<<(char)(result); // the print
}
else
if (result>90) // the condition if the result is greater than 90
{
cout<<(char)(result-26); // the print out
}
}
}
cout<<endl;
cout<<" Enter 'E' to return to the main menu "<<endl; // the prompt to return to the main menu
cin>>ch; //the input
if(ch!='E') // the condition if the input is not equal to the 'E'
{
cout<<" The program is ending "<<endl; // output if the input is not equal to 'E'
break; // the break statement
}
}
if (b==3) // the condition if the input is 3
{
cout<<" The program is ending "<<endl; // the output if th condition is 3
break; // the break statement
}
}
if (a==2) // if the option for the decryption is used
{
cout<<" Select the cypher you want to use "<<endl; //prompt
cout<<" 1 for decryption by block cypher "<<endl; //1 for the decryption by the block cypher
cout<<" 2 for decryption by caeser cypher "<<endl; //2 for the decryption by the caeser cypher
cout<<" 3 to exit "<<endl; // 3 to exit
cin>>c;
if (c==1) // if the block cyher is used for the decryption
{
cout<<" Enter the encrypted phrase "<<endl; // the prompt
cin>>encrypt;// input
cout<<" The decrypted phrase is :"<<endl<<endl;
for(int i=0;i<=5;i++) // the for loop for the output of the string
{
for(int j=0;j<35;j=j+6) // the for loop for the output of the string
{
cout<<encrypt[i+j]; // the output of the decrypted phrase
}
}
cout<<endl<<endl;
cout<<" Enter 'E' to return to the main menu "<<endl; // the prompt to return to the main menu
cin>>ch; // the input
if(ch!='E') // if the input is not equal to 'E'
{
cout<<" The program is ending "<<endl; // output if the input is not equal to 'E'
break; // break
}
}
if (c==2) // the condition if the caeser cypher is used for the decryption
{
cout<<" Enter the encrypted phrase "<<endl; // prompt
cin>>caeser; //input
cout<<" Enter the shift parameter "<<endl; //prompt
cin>>shift; //input
for(int j=0;j<=35;j++) // for loop for the output of the string
{
int c;
r=(int)caeser[j];
6

result=(int)caeser[j]-shift; // the ascii of the decrypted letter

if ((96<r)&&(r<123)) // the condition if ascii is inbetween 97 and 122


{
if (result<97)
{
cout<<(char)(result+26); // output
}
else if (result>=122)
{
c=result%122;
cout<<(char)(97+c);
}
else
{
cout<<(char)(result);
}
}
else if ((64<r)&&(r<91))
{
if (result<65)
{
cout<<(char)(result+26);
}
else if ((64<result)&&(result<90))
{
cout<<(char)(result);
}
else
if (result>=90)
{
cout<<(char)(result-26);
}
}
}
cout<<endl;
cout<<endl;
cout<<" Enter 'E' to return to the main menu "<<endl; // the prompt to return to the main menu
cin>>ch; // the input
if(ch!='E') // if the input is not equal to 'E'
{
cout<<" The program is ending "<<endl; // output if the input is not equal to 'E'
break; // break
}
}
if (c==3)
{
cout<<" The program is terminating "<<endl;
break;
}
}
if (a==3) // condition if the input is 3
{
cout<<" The program is exiting "<<endl;
break; // the break statement
}
}
}
7

4. Experimental Results
When the program was used then the result were in accordance with the given task.
When the phrase of 36 characters was entered then the result was the encrypted either in block
or caeser cypher according to the will of the user.
Similarly when then encrypted code was entered in then the result of the program was to
decode that one and that was easily done by it according to the requirements of the project.

5. Conclusion
The conclusion this project report is that I have deliberately performed this task and I am happy
that it is working perfectly in accordance with the cited requirements of the project.
The objective of the program the encryption and decryption of the phrases is very useful for the
communication of highly confidential documents and hence it the initial step for the
development of other useful programs like this.

Abstract:
The poblem being handled in the project is the encryption and decrytion of the entered phrases
by using the Block and the Caeser cyphers. There were some problems while making this project like the
printind of ASCII codes when we needed to print the characters. And also the logic being used in the
Caeser Cypher. Block Cypher was encrypted and decrypted by using nested for loops while the caeser
problem was solved by using the ascii codes and the shift being added or subtracted into the ascii codes
according to the encryption or the decryption. Moreover another major problem the printing of the
Upper case and the lower case letters seperately as both of them got entangled with one another and
this problem took a long time to be eradicated.

You might also like