You are on page 1of 25

A Project Report

on

MESSAGE AND IMAGE ENCRYPTION AND DECRYPTION

Submitted in partial fulfilment of the requirement for the award of the

certificate of

PYTHON PROGRAMMING

SUBMITTED TO:
Mr. Mayur Dev Sewak
General Manager, Operations
Eisystems Services
Ms. Mallika Srivastava
Trainer, Data Science & Analytics Domain
Eisystems Services

SUBMITTED BY:

Mohd Farman

1
index

Serial no. Page no.

1 Cover Page
1
2 Acknowledge 3

3 Python 4

4 Encrypt and Decrypt 5


message and image using
python
Decryption 6

5 Abstract 9

6 Objective 10

7 Details of process 11

8 System requirement 18

9 Data flow diagram 19

10 The Ou 23

11 Summary 24

12 References 25

2
ACKNOWLEDGE

I would like to acknowledge the contributions of the following people without whose help
and guidance this report would not have been completed. I acknowledge the counsel and
support of our training coordinator, Ms. Mallika Srivastava Trainer, Data Science & Analytics
Domain Eisystems Services with respect and gratitude, whose expertise, guidance, support,
encouragement, and enthusiasm has made this report possible. Their feedback vastly
improved the quality of this report and provided an enthralling experience. I am indeed
proud and fortunate to be supported by her.
This acknowledgement will remain incomplete if I fail to express our deep sense of
obligation to my parents and God for their consistent blessings and encouragement.

3
Introduction

Python –The New Generation Language

Python is a widely used general-purpose, high level programming language. It was initially
designed by Guido van Rossum in 1991 and developed by Python Software Foundation. It
was mainly developed for an emphasis on code readability, and its syntax allows
programmers to express concepts in fewer lines of code. Python is dynamically typed and
garbage-collected. It supports multiple programming paradigms, including procedural,
object-oriented, and functional programming. Python is often described as a "batteries
included" language due to its comprehensive standard library.

Features

• Interpreted

In Python there is no separate compilation and execution steps like C/C++. It directly run
the program from the source code. Internally, Python converts the source code into an
intermediate form called bytecodes which is then translated into native language of specific
computer to run it.

• Platform Independent

Python programs can be developed and executed on the multiple operating system
platform. Python can be used on Linux, Windows, Macintosh, Solaris and many more.

• Multi- Paradigm

Python is a multi-paradigm programming language. Object-oriented programming and


structured programming are fully supported, and many of its features support functional
programming and aspectoriented programming .

• Simple

Python is a very simple language. It is a very easy to learn as it is closer to English language.
In python more emphasis is on the solution to the problem rather than the syntax.

• Rich Library Support

Python standard library is very vast. It can help to do various things involving regular
expressions, documentation generation, unit testing, threading, databases, web browsers,
CGI, email, XML, HTML, WAV files, cryptography, GUI and many more.

• Free and Open Source

4
Firstly, Python is freely available. Secondly, it is open-source. This means that its source
code is available to the public. We can download it, change it, use it, and distribute it. This is
called FLOSS (Free/Libre and OpenSource Software). As the Python community, we’re all

headed toward one goal- an ever-bettering Python.

Encrypt and Decrypt message and image using python

Encryption is the act of encoding a message so that only the intended users can see it. We
encrypt data because we don’t want anyone to see or access it.
We will use the cryptography library to encrypt a file. The cryptography library uses a
symmetric algorithm to encrypt the file. In the symmetric algorithm, we use the same key to
encrypt and decrypt the file. The fernet module of the cryptography package has inbuilt
functions for the generation of the key, encryption of plain text into cipher text, and
decryption of cipher text into plain text using the encrypt() and decrypt() methods
respectively. The fernet module guarantees that data encrypted using it cannot be further
manipulated or read without the key.

Encryption
It is nothing but a simple process in which we convert our data or information into secret
code to prevent it from unauthorized access and keep it private and secure.
First, we will select an image, and then we will convert that image into a byte array due to
which the image data will be totally converted into numeric form, and then we can easily
apply the XOR operation to it. Now, whenever we will apply the XOR function on each value
of the byte array then the data will be changed due to which we will be unable to access it.
But we should remember one thing here our encryption key plays a very important role
without that key we can not decrypt our image. It acts as a password to decrypt it.
The below program depicts the basic approach to encryption:
# Assign values
data = 1281
key = 27

# Display values
print('Original Data:', data)
print('Key:', key)

5
# Encryption
data = data ^ key

print('After Encryption:', data)

# Decryption
data = data ^ key
print('After Decryption:', data)

Output:

Original Data: 1281


Key: 27
After Encryption: 1306
After Decryption: 1281

Decryption
It is nothing but a process of converting our encrypted data into a readable form. Here
we will again apply the same XOR operation on an encrypted image to decrypt it. But always
remember that our encryption key and decryption key must be the same.
Executable Code for Decryption:

# try block to handle the exception


try:

# take path of image as a input


path = input(r'Enter path of Image : ')

# taking decryption key as input


key = int(input('Enter Key for encryption of Image : '))

# print path of image file and decryption key that we are using

6
print('The path of file : ', path)
print('Note : Encryption key and Decryption key must be same.')

print('Key for Decryption : ', key)

# open file for reading purpose


fin = open(path, 'rb')

# storing image data in variable "image"


image = fin.read()
fin.close()

# converting image into byte array to perform decryption easily on numeric data
image = bytearray(image)

# performing XOR operation on each value of bytearray


for index, values in enumerate(image):
image[index] = values ^ key

# opening file for writing purpose


fin = open(path, 'wb')

# writing decryption data in image


fin.write(image)
fin.close()
print('Decryption Done...')

except Exception:
print('Error caught : ', Exception.__name__)

7
Output:

Enter path of Image : C:\Users\lenovo\Pictures\Instagram\enc.png


Enter Key for Decryption of Image : 22
The path of file : C:\Users\lenovo\Pictures\Instagram\enc.png
Note : Encryption key and Decryption key must be same.
Key for Decryption : 22
Decryption done...

8
Abstract

In this project we have created a Python programming Project named “Message and Image
Encryption and Decryption”. An Image Encryption Decryption is an image processing
application created in python with tkinter gui and OpenCv library.
In this application user can select an image and can encrypt that image to gray scale image
and can even decrpyt also.
The purpose of encryption is confidentiality concealing the content of the message by
translating it into a code.
Also after encrypting and decrypting user can also save the edited image anywhere in the
local system.
Also there is option to reset to the original image.

9
Objectives
The main objective of our project is to provide security of the message and image-based
data with the help of suitable key and protect the message and image from illegal copying
and distribution

10
Detail of process

Introduction

Python Message and Image Encryption Decryption Project

In this digital era, the need for security is increasing rapidly. Complying with this requirement,
the encryption & decryption algorithms were devised.

Now, we will build a project that can encode and decode a message. Let’s start by getting to
know more about this project.

Message and Image Encryption Decryption Project in Python


Encoding is the process of converting text into an incognizable language and the reverse
process in decoding. In this project, we will be using the Tkinter module and base64 module
to do the required operations.

1.The user first enters the message and key


2.And choose one of the encode or decode options
3.Based on the choice the corresponding operation is done
4.It is to be noted that the same key used for encryption needs to be used during the
decryption.
Project Prerequisites

To build this project, the developer needs to have good knowledge of the Tkinter module and
Python. It is also advised to have some idea on encryption & decryption.

Python Message Encryption Decryption Project File Structure


Steps for building the python message encryption decryption project:

1. Installing the required modules


2. Importing the modules

11
3. Writing function for encryption
4. Writing function for decryption

5. Creating the window


6. Adding the input and output components
7. Adding the buttons and their functions

1. Installing the required modules


The base64 is available by default. If it is not you can install is using the command

pip install base64

The Tkinter module needs to be installed. You can install this module by using the following
command.

pip install tkinter

2. Importing the modules


The first step is to import the required modules. Here we will be using the tkinter module for
building the GUI and the base64 module for encryption and decryption purposes.

3. Writing function for encryption

12
Code Explanation:
a. ord(): This function gives the corresponding ASCII values of a given character.

b. chr(): This function gives the corresponding character to the given ASCII value.
c. append(): Adds the elements to the end of the list
d. ord(msg[i]) + ord(list_key)) % 256 : This gives the remainder of division of addition of
ord(message[i]) and ord( key_c) with 256 and passes that remainder to chr() function
e. base64.urlsafe_b64encode(): This helps in encoding the string using url and file system safe
alphabets into the binary form.

4. Writing function for decryption

Code Explanation:
a. base64.urlsafe_b64decode(): This helps in decoding the binary string using url and file
system safe alphabets into the normal form of strings.
b. ord(): This function gives the corresponding ASCII values of a given character
c. chr(): This function gives the corresponding character to the given ASCII value
d. 256 + ord(message[i]) – ord(key_c)) % 256 : This gives the remainder of addition of 256 with
subtraction of ord(message[i]) – ord( key_c) and then division with 256 and passes that
remainder to chr() function

e. append(): Adds the elements to the end of the list

13
5. Creating the window

Code Explanation:
a. geometry(): It sets the length and width of the project window.
b. configure(): It sets the background color of the screen
c. title(): It displays the title on the top of the python message encryption-decryption project
window.

6. Adding the input and output components

14
Code Explanation:

a. The message and key hold the values in the entries that hold the input message key. And
mode checks which radio button is pressed for encryption/decryption. Output values hold the
value shown in the Result entry after doing the operation.
b. Frame(): It creates a rectangular object that holds various widgets on the screen
c. place(): This is used to place the widgets in a specified location based on coordinates or
relative to the parent component
d. Label(): This creates a label that can be used to show information
e. Entry(): This widget is used to take input from the user
f. Radiobutton(): These help in choosing one of the given options

15
7. Adding the buttons and their functions

Code Explanation:
a. The result() function

i. it takes the message, key, and the mode that are inputted by the user
ii. Then based on the mode, calls one of the encryption() or decryption() functions
iii. Shows the output in the Result field
iv. If no mode is selected, shows the message to select one of the either

16
b. Button(): This creates a button with mentioned color, text, etc. and the command
parameter represents the function that is to be executed on clicking the button

c. place(): This is used to place the widgets in a specified location based on coordinates or
relative to the parent component

d. mainloop(): This makes sure the screen runs in a loop till it is manually closed by the user

17
System Requirement
For user:

Browsers:
Google Chrome (recommended), Internet Explorer, Mozilla Firefox, Safari, Micro-softedge,
Opera, Vivaldi, etc.
Gamil account
High Speed Internet Connection
For Developers:
Operating system:
-Windows: XP/Vista/7/8/8.1/10 or late
–OSX: Snow leopard 10.6.3 or later Ubuntu, Debian, Fedora, Cent OS or Suse Linux

18
Data Flow Diagram

19
Input/output

20
21
The Output of Python Message Encryption Decryption Project
Fig1. The image of output of python encryption

22
Fig2. The image of output of python decryption

It can be observed that when the output of encryption of mohd farman is given as input to
decryption, the output is mohd farman.

23
Summary
In this project, we successfully built the python message encryption decryption system using
the Tkinter and base4 modules.

24
References

 https://www.youtube.com/

 https://www.javatpoint.com/

 https://youtu.be/rxkGItX5gGE

 https://projectgurukul.org/python-message-encryption-decryption-project/

 https://www.greekforgreek.com/

25

You might also like