You are on page 1of 26

Caesar Cipher Encryption

and Decryption Project


SUMMER INTERNSHIP REPORT

Submitted in partial fulfilment of requirements to

Summer Internship (CS-451)

IV/IV B.Tech CSE(VII Semester)

Submitted By

BONTHA SARATH CHANDRA ( Y20CS027 )

R.V.R & J.C. COLLEGE OF ENGINEERING

(Autonomous)

Approved by AICTE :: Affiliated to Acharya NagarjunaUniversity

Chowdavaram, GUNTUR – 522019,Andhra Pradesh, India

i
INTERNSHIP CERTIFICATE

ACKNOWLEDGEMENT

The Successful completion of any task would be incomplete without a proper

suggestions , guidance and environment.Combination of these three factors acts like

backbone to our project “Caesar Cipher Encryption and Decryption”.

i
i
We express our sincere thanks to DR. M. Sreelatha, Head of the Department of

Computer Science and Engineering for her encouragement and support to carry out

this Project Successfully.

We are very much thankful to Dr. Kolla Srinivas , Principal of R.V.R &J.C.

College of Engineering, Guntur for providing this supportive environment.

We are very thankful to Spypro Security Solutions , Vijayawada for providing this

supportive Environment.

Finally, we submit our reserves thanks to lab staff in Department of Computer

Science and Engineering and to all our friends for their cooperation during the

preparation.

Bontha Sarath Chandra (Y20CS027)

ABSTRACT

In a secret message, cryptography is more directed to the encrypted message while


steganography is more directed at the hidden message. However, both methods have
the same goal, namely the attempt to conceal the message. On the other side, it turns
i
i
i
out the use of cryptography can often be solved / translated by another person or
cryptanalyst. This is possible because usually a text message unreadable gives
someone suspicion that the text message contains a certain meaning for the owner of
the message. Thus, the cryptanalyst attempts to break the encrypted message. While
the use of steganography owner of the information is difficult to determine the
method or pattern to be formed in composing the message that will be hidden.This
project focuses on the implementation of the Caesar Cipher, a classic encryption
technique, for text encryption and decryption. Inspired by Julius Caesar's historical
use of this method to secure communications.The application includes features for
both manual and automatic encryption/decryption, allowing users to input text and
choose shift values. The implementation incorporates error handling to enhance
reliability. By providing a practical and interactive platform, the project serves as an
educational tool for individuals to gain hands-on experience with fundamental
cryptographic concepts, laying the groundwork for further exploration of more
advanced encryption techniques.

i
v
Contents PAGE NO
Title i
Certificate ii
Acknowledgement iii
Abstract iv
Contents v
List of figures vi
1. Introduction 1
1.1 Background 1
1.2 Problem Statement 1
1.3 Significant Work 2
2. System Analysis 3
2.1 Requirement Specification 3
2.1.1 Functional Requirements 3
2.1.2 System Requirements 3
2.1.3 Non-Functional Requirements 4
3. System Design 5
3.1 Architecture of the Proposed System 5
3.2 Flow of work 9
4. Implementation 11
5. Results 16
6. Conclusion and Future Work 18
7. Refrences 20

v
List of Figures

3.1.1 Character shift in Caesar Cipher Encryption 6

3.1.2 Encryption phase with shift n 7

3.1.3 Character shift in Caesar Cipher Decryption 8

3.1.4 Decryption phase with shift n 9

3.2.1 Caesar Cipher Flowchart 10

v
i
1. INTRODUCTION

1.1 Background

Cryptography, the science of securing communication, has evolved significantly over


millennia. The Caesar Cipher, attributed to Julius Caesar around 58 BCE, is one of
the earliest known encryption techniques. In this method, each letter in the plaintext is
shifted by a fixed number of positions down or up the alphabet. Despite its simplicity,
the Caesar Cipher played a crucial role in securing military communications during
ancient times.In the contemporary digital landscape, understanding the fundamentals
of encryption remains paramount. The Caesar Cipher serves as an ideal starting point
for individuals exploring cryptographic concepts. Its straightforward algorithm not
only introduces the concept of substitution ciphers but also lays the groundwork for
more complex encryption techniques.This project takes inspiration from the historical
application of the Caesar Cipher and aims to bridge the gap between ancient and
modern cryptography. By implementing a Python-based application, the project seeks
to provide a hands-on experience for users, allowing them to interact with and
comprehend the basic principles of encryption. Furthermore, the project opens the
door to discussions on the importance of key management, the evolution of
cryptographic algorithms, and the ongoing efforts in ensuring secure communication
in our interconnected world. As we delve into the implementation of the Caesar
Cipher, we simultaneously embark on a journey through the rich history and
contemporary relevance of cryptographic practices.

1.2 Problem Statement

In the realm of cryptographic education and practical understanding, there is a need


for an accessible and interactive platform that introduces users to fundamental
encryption principles. Many existing educational resources on cryptography lack

1
hands-on engagement, making it challenging for individuals to grasp the foundational
concepts. The Caesar Cipher, being a historic and simple encryption technique,
presents an excellent opportunity for learning, yet there is a scarcity of user-friendly
applications that allow for interactive exploration of this classical algorithm. This
project addresses the gap by proposing the development of a Python-based application
designed to make the Caesar Cipher accessible to users, providing a tangible and
engaging experience in understanding the basics of encryption. The problem at hand
is to create an intuitive platform that bridges the historical significance of the Caesar
Cipher with the modern need for practical, hands-on cryptographic learning.

1.3 Significance of work

The Caesar Cipher Encryption and Decryption Project hold substantial significance in
the realms of historical cryptography education and contemporary cybersecurity
awareness. Serving as a gateway for individuals venturing into the field of
cryptography, the project offers a hands-on and interactive experience with a classic
encryption technique. By focusing on the Caesar Cipher, famously employed by
Julius Caesar, the project not only imparts foundational cryptographic knowledge but
also connects modern learners with the historical roots of secure communication.

Moreover, the project contributes to cybersecurity awareness by emphasizing key


management concepts, a crucial aspect of secure communication. Beyond its
educational value, the project stands as a testament to the enduring relevance of
cryptographic principles, encouraging users to explore more advanced techniques and
providing a solid foundation for further studies in the dynamic field of cryptography.

2
2. SYSTEM ANALYSIS

2.1 REQUIREMENT SPECIFICATION


Requirements analysis, also called requirements engineering is
the process of determining user expectations for a new or modified
product. These features called requirements must be quantifiable, relevant
and detailed.
In software engineering, such requirements are often called
functional specifications. Requirements analysis is critical to the success or
failure of a systems or software project. The requirements should be
documented, actionable, measurable, testable, traceable, related to identified
business needs or opportunities, and defined to a level of detail sufficient for
system design.

2.1.1 Functional Requirements

• Execution time should be fast


• More Accurate
• User Friendly

2.1.2 System Requirements

Software Requirements

Operating System : windows XP, WINDOWS 7, 8.1,10 ,11

Coding language : PYTHON


Web Browser : GOOGLE CHROME

3
Hardware Requirements:

Personal computer with keyboard and mouse maintained with uninterrupted


power supply.
• Processor: Intel® core™ i5
• Installed Memory (RAM): 8.00 GB

• Hard Disc: 250GB SSD

2.1.3 Non-functional requirements:


Execution qualities:
Efficiency: The state or quality of being efficient, i.e., able to accomplish
something with the least waste of time and effort; competency in performance.

Evolution qualities:

Testability: The means by which the presence, quality, or genuineness of


anything is determined.

Extensibility: To enlarge the scope of to make more comprehensive, as


operations, influence etc.

Scalability: The ability of something, especially a computer system, to adapt to


increased demands.

4
3. SYSTEM DESIGN

3.1 Architecture of proposed system:

The Caesar Cipher

The Caesar Cipher, named after Julius Caesar of Ancient Rome.


Caesar Cipher is a type of substitution cipher where each letter of the original
(plaintext) message is substituted with another letter.

Encrypting with the Caesar Cipher

But how do we decide what letter is replaced by what? That’s where the key comes
into play. Found in almost every encryption algorithm, the key determines how the
data is encrypted.
In the Caesar cipher, the key is a number from 0 to 25, because there are 26 letters in
the alphabet. This means that for any given message, there are 26 different ways we
can encrpyt the message.
For each letter, the key determines which letter is replacing the current letter, by
counting down the alphabet. In the following example, let’s say we wanted to encrypt
the letter B with a key of 3, we would find the 3rd letter that appears after B - which is
C, D, then finally E.

5
Fig 3.1.1 Character shift in Caesar Cipher Encryption

In the Caesar cipher with a key of 3, A becomes D, B becomes E, C becomes F, and


so on...

This can easily be shown by lining up two alphabets, one on top of each other, with
the second alphabet starting at the letter shifted 3 letters down. This means that the
bottom row should be shifted to the left.

You might notice that the second row starts has the letters ABC right after Z. This
is because when you are shifting down the alphabet, if you reach the end (Z), it
will loop around to the beginning (A).
This type of visual makes it much more clear what letter should become what. If
we wanted to encrypt the word BILLY, we would simply take
each unique plaintext letter (top row) and find its matching ciphertext letter
(bottom row), or:

6
So we clearly see that:
 B becomes E
 I becomes L
 L become O
 Y becomes B

(Note that we only have to find unique letters, like the L because each L will always
turn into the same letter)

So the final ciphertext is ELOOB. Note that when we reach the end of the
alphabet, we keep counting starting with A, B, etc...

Fig 3.1.2 Encryption phase with shift n

Decrypting with the Caesar Cipher

Decrypting works in a very similar way - except this time, instead of counting
“down” the alphabet, you count “up”! As an example, let’s try to decrypt ELOOB
using a key of 3 - because we know the result should be our original plaintext,
BILLY.

7
Fig 3.1.3 Character shift in Caesar Cipher Decryption

Notice how this time, instead of shifting the bottom row to the left, now we are
shifting it to the right. We can then find our ciphertext letters (top
row) E,L,O,B and find their corresponding plaintext letters (bottom row).

We can now see that:

 E becomes B
 L becomes I
 O becomes L
 B becomes Y
Which gives us our original plaintext, BILLY.

8
Fig 3.1.4 Decryption phase with shift n

3.2 FLOW OF WORK

A cipher is a method that encrypts or disguises text. The undisguised text is called

“plaintext”, and the disguised text is called “ciphertext”. The process of transforming

plaintext to ciphertext is called “encryption”. The reverse is called “decryption”. In


the above scheme, each letter of the ciphertext substitutes for a letter of the plaintext,
this is called “substitution cipher”.

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 (Luciano, Dennis and Gordon Prichett,1987). Encryption of a letter by a shift
n can be described mathematically as (Wobst and Reinhard, 2001),

En(x) = (x+n) mod 26

Decryption is performed similarly,

Dn(x) = (x-n) mod 26

(There are different definitions for the modulo operation. In the above, the result
is in the range 0...25. I.e., if x+n or x-n are not in the range 0...25, we have to
subtract or add 26.)

9
The replacement remains the same throughout the message, so the cipher is
classed as a type of monoalphabetic substitution, as opposed to polyalphabetic
substitution.

MATHEMATICAL DESCRIPTION

First we translate all of our characters to numbers, 'a'=0, 'b'=1, 'c'=2, ... ,
'z'=25. We can now represent the caesar cipher encryption function, e(x), where x
is the character we are encrypting, as:

Where k is the key (the shift) applied to each letter. After applying this function
the result is a number which must then be translated back into a letter. The
decryption function is:

Fig 3.2.1 Caesar Cipher Flowchart

10
4. IMPLEMENTATION & TESTING

To begin, create a file called caesar.py, where caesar.py is the file name and
extension for our python file.
The purpose of this project is to explain an algorithm, walking you through the
algorithm, as well as highlighting thought processes behind good code design.
Please pay special attention and read through all the text, as it does provide some
strategies and insight into how you can write code.
In this project, we should be following along and building this step-by-step in
your preferred python IDE.
Let’s start with our encryption function. In this function, we’ll be taking
in key and message as arguments. The first thing we are going to do is to convert
the entire message to uppercase, which we can do using the .upper() string
method. Then we are going to create a variable called alpha that will hold the
alphabet as a long string as follows.

The system design refers to how computer can be used to encrypt and decrypt
messages in a way whereby people that are computer literate and those people that are
not computer literate can use it.

The system design consists of the following stages:-

User Input:The user interacts with the command line, providing input for either
encryption or decryption.For encryption, the user inputs the plaintext and specifies the
shift value.For decryption, the user inputs the ciphertext and either provides the
known shift value or opts for an automatic decryption based on patterns.

11
Data Validation:The input is validated to ensure it meets the required criteria (e.g.,
valid characters, proper format).Error handling is implemented to manage any invalid
inputs, providing feedback to the user.

Encryption Module:If the user opts for encryption, the plaintext and shift value are
passed to the encryption module.The Caesar Cipher algorithm is applied, shifting each
character in the plaintext according to the specified shift value.The encrypted text is
generated and stored for further processing.

Decryption Module:If the user opts for decryption, the ciphertext and shift value (if
known) are passed to the decryption module.The Caesar Cipher algorithm is applied
in reverse, shifting each character in the ciphertext to reveal the original plaintext.If
the shift value is unknown, an automatic decryption process may be employed based
on patterns in the ciphertext.

Output:The final output is displayed to the user via the command line.For encryption,
this is the resulting ciphertext.For decryption, this is the decrypted plaintext.

Key Management:Shift values used for encryption and decryption are handled
securely to maintain the confidentiality of the communication.

Encryption Function

12
def encrypt(key, message): Defines a function named encrypt that takes two
parameters - key (an integer representing the Caesar Cipher shift) and message (the
text to be encrypted).

message = message.upper(): Converts the entire input message to uppercase. This


ensures consistency in processing and handling of the alphabet, as the Caesar Cipher
traditionally operates on uppercase letters.

alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ": Defines the alphabet,


which serves as a reference for the encryption process.

result = "": Initializes an empty string result to store the encrypted message.

for letter in message: Initiates a loop to iterate through each character in the
standardized message.

new_key = (alpha.find(letter) + key) % len(alpha): Calculates the new index of the


letter in the alphabet after applying the Caesar Cipher shift. The % len(alpha) ensures
that the index wraps around if it exceeds the length of the alphabet.

result += get_cipherletter(new_key, alpha): Calls a helper function get_cipherletter


to obtain the encrypted letter based on the calculated index. The result is appended to
the result string.

result += letter: If the current character is not in the alphabet, it is a non-alphabetic


character. This character is preserved in the result string.

Final Result:

return result: The function returns the final encrypted result, which is a string
containing the encrypted version of the input message.

This encrypt function encapsulates the core logic of the Caesar Cipher encryption
process and can be used to encrypt messages with a specified shift key.

13
Decryption Function

def decrypt(key, message): Defines a function named decrypt that takes two
parameters - key (an integer representing the Caesar Cipher reverse shift) and
message (the text to be decrypted).

message = message.upper(): Converts the entire input message to uppercase. This


ensures consistency in processing and handling of the alphabet, as the Caesar Cipher
traditionally operates on uppercase letters.

alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ": Defines the alphabet,


which serves as a reference for the decryption process.

result = "": Initializes an empty string result to store the decrypted message.

for letter in message: Initiates a loop to iterate through each character in the
standardized message.

new_key = (alpha.find(letter) - key) % len(alpha): Calculates the new index of the


letter in the alphabet after applying the reverse Caesar Cipher shift. The % len(alpha)
ensures that the index wraps around if it goes below zero.

14
result += get_cipherletter(new_key, alpha): Calls a helper function get_cipherletter
to obtain the decrypted letter based on the calculated index. The result is appended to
the result string.

result += letter: If the current character is not in the alphabet, it is a non-alphabetic


character. This character is preserved in the result string.

return result: The function returns the final decrypted result, which is a string
containing the decrypted version of the input message.

This decrypt function complements the encrypt function, providing a complete set for
both encrypting and decrypting messages using the Caesar Cipher. It can be used to
decrypt messages that were previously encrypted with a specified shift key.

message = input("Enter your message: "): Prompts the user to input the message
they want to encrypt.

key = int(input("Enter your key: ")): Prompts the user to input the key (shift value)
they want to use for encryption and decryption. Converts the input to an integer.

cipher = encrypt(key, message): Calls the encrypt function with the user-provided
key and message, encrypting the input message.

print("Encrypted Message:", cipher): Prints the encrypted message.

plain = decrypt(key, cipher): Calls the decrypt function with the same key and the
encrypted message (cipher), decrypting the message.

print("Decrypted Message:", plain): Prints the decrypted message.

15
5. RESULTS

The Results section of the project report presents the outcomes and findings obtained
from the implementation and execution of the Caesar Cipher Encryption and
Decryption project. This section encompasses the practical applications of the
developed encryption and decryption functionalities, showcasing the effectiveness
and correctness of the algorithms. It includes demonstrations of the encryption
process applied to user-input messages, the resulting ciphertext, and subsequent
successful decryption. Additionally, any observed patterns or insights regarding the
chosen shift values are discussed. The Results section serves to validate the
functionality of the implemented Caesar Cipher, providing tangible evidence of its
successful application to user-provided messages. It also may include any
performance metrics, user feedback, or comparisons with expected outcomes,
contributing to a comprehensive understanding of the project's practical implications.

The output of the Caesar Cipher Encryption and Decryption project is a tangible
demonstration of the successful implementation and execution of the cryptographic
functionalities developed within the project scope. The results include the encrypted

16
and decrypted versions of user-provided messages, showcasing the practical
application of the Caesar Cipher algorithm. Each output provides a direct illustration
of the transformation process undergone by the user's input, offering clear evidence of
the encryption and subsequent decryption phases. The ciphertext generated from the
encryption process serves as a testament to the security provided by the algorithm,
while the successfully decrypted messages affirm the correctness and reliability of the
implemented decryption algorithm.

17
6. CONCLUSION AND FUTURE WORK

The completion of the Caesar Cipher Encryption and Decryption project marks a
successful endeavor in bridging historical cryptographic principles with modern
implementation. The project has demonstrated the practical application of the Caesar
Cipher algorithm through a user-friendly Python-based application. The encryption
and decryption functionalities have been validated, showcasing the robustness and
correctness of the implemented algorithms. The project not only serves as an
educational tool for users to gain hands-on experience with classical encryption
techniques but also highlights the relevance of historical ciphers in contemporary
contexts. The user-friendly interface, combined with error handling mechanisms,
contributes to a seamless and engaging user experience. The project's success in
achieving its objectives underscores the importance of foundational cryptographic
understanding and paves the way for further exploration into advanced encryption
methodologies.

While the current project provides a solid foundation for understanding the Caesar
Cipher, there are several avenues for future enhancements and extensions:

Integration of Advanced Algorithms:

Explore the integration of more sophisticated encryption algorithms, such as the


Vigenère Cipher or substitution ciphers with varying key lengths, to offer users
exposure to a broader range of cryptographic techniques.

Multilingual Support:

Extend the project to support multiple languages, enabling users to apply encryption
and decryption to texts in languages beyond English.

Enhanced User Interface:

Improve the user interface by incorporating graphical elements or developing a


standalone application, enhancing the overall user experience.

18
Cryptanalysis Features:

Implement cryptanalysis features to analyze the security aspects of the Caesar Cipher,
identifying vulnerabilities and showcasing potential attacks.

Key Management Improvements:

Enhance key management mechanisms to include more advanced key distribution and
management strategies, reflecting real-world cryptographic practices.

Educational Resources:

Develop educational resources, such as tutorials or documentation, to accompany the


project and provide users with in-depth insights into cryptographic concepts and the
significance of secure communication.

Performance Optimization:

Optimize the algorithms for larger datasets, ensuring efficient execution and
responsiveness, especially when dealing with extensive text inputs.

Integration with Other Tools:

Explore integration with other cryptographic tools or libraries, fostering a


collaborative ecosystem for users interested in exploring a broader range of
cryptographic applications.

19
7. REFERENCES

1.Wobst, Reinhard (2001), “Cryptology Unlocked”. Wiley. p. 19. ISBN 978-0-470-


06064-3.

2.Reinke, Edgar C. (December 1992), "Classical Cryptography". The


ClassicalJournal58

3.Pieprzyk, Josef; Thomas Hardjono; Jennifer Seberry (2003), Fundamentals


ofComputer Security. Springer. p. 6. ISBN 3-540-43101-2.

4.Singh and Simon (2000), The Code Book.


http://en.wikipedia.org/wiki/Singh_Simon Anchor. pp. 14–20. ISBN 0-385-49532-3.

5.Kashih Goyal and Supriya Kinger (2013), “Modified Ceasar Cipher for Better
Security Enhancement” published in International Journal of Computer Applications
(0975-8887)(IJCA)” Volume 73-No.3, July 2013.

6.Alexander Poltorak (2014), "Mezuzah and Astrology".

http://www.chabad.org/library/article_cdo/aid/312102/jewish/Mezuzah-and-
Astrology.htm.

7.Cipher Research Laboratories (2006), “A Brief History of Cryptography”. 24


January, 2006).

8.O.P Verma, Ritu Agarwal, DhiraDafouti and Shobha Tyagi (2011), “Performance
Analysis of Data Encryption Algorithms” IEEE Delhi Technological University India,
2011.

9.Gary C. Kessler (2013), “An Overview of cryptography”.

10.Leyden, John (2006), "Mafia boss undone by clumsy crypto".

20

You might also like