0% found this document useful (0 votes)
40 views19 pages

Computer - Project - Encrypting and Decrypting

The document discusses encrypting and decrypting data in Python. It describes using the Tkinter and base64 libraries to build an app that allows a user to enter a message and key to encode or decode text. Functions are defined to encode and decode using a Vigenère cipher algorithm. The source code provided implements the encryption/decryption app.

Uploaded by

Malathi S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views19 pages

Computer - Project - Encrypting and Decrypting

The document discusses encrypting and decrypting data in Python. It describes using the Tkinter and base64 libraries to build an app that allows a user to enter a message and key to encode or decode text. Functions are defined to encode and decode using a Vigenère cipher algorithm. The source code provided implements the encryption/decryption app.

Uploaded by

Malathi S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

TITLE – Encrypting and Decrypting of data in Python

Student Name : Vilina Selvakani

Roll No. :

Class : XII

1
School Logo

CERTIFICATE

Name : Vilina Selvakani


Roll No. :
Class : XII
School : Geetanjali Olympiad School
This is certified to be the bonafide work of the student in the
Computer Science Project during the academic year 2023-24.

Teacher in charge Signature:

Examiner’s Signature:

Principal’s Signature:

School Seal:

2
Date:

ACKNOWLEDGEMENT

I would like to express my deepest appreciation to all those who


provided me with the possibility to complete this project. I would
like to thank my Computer teacher _____________, whose
valuable guidance has helped me complete this project. His / Her
suggestions and instructions have served as a major contributor
towards the completion of the project.

I take this opportunity to thank our head of the institution,


________, who was always supportive and helpful in fulfilling all
our academic requirements.

Last but not the least; I would like to thank all my classmates who
have helped me to complete this project.

3
TABLE OF CONTENTS

• Introduction to Python 6
• About the Project 7
• Source code 10
• Output 16
• Bibliography / References 18

4
AIM

This objective of this project is to encode and decode messages


using a common key. This project will be built using the Tkinter
and base64 library.

In this project, users have to enter the message to encode or


decode. Users have to select the mode to choose the encoding
and decoding process. The same key must be used to process the
encoding and decoding for the same message.

5
INTRODUCTION to PYTHON

Python is an interpreted, object-oriented high-lever programing


language with dynamic semantics. Its high-level built in data
structures, combined with dynamic typing and dynamic binding,
make it very attractive for Rapid Application Development, as
well as for use as a scripting or glue language to connect existing
components together. You can use Python for developing desktop
GUI applications, websites and web applications. Python’s
simple, easy to learn syntax emphasizes readability and therefor
reduces the cost of program maintenance. Python supports
modules and packages, which encourages program standard
library are available in source or binary form without charge for
all major platforms, and can be freely distributed.

6
About the Project

Encryption and Decryption, a type of cryptography, refers to the


process of scrambling information so that the observer cannot
detect the data.

At present, there are many encryption and decryption especially


in the communication system provided in a variety of
application.

Encryption and decryption is particularly impacted in the field of


military communications and reliable security data to protection
for transmitting.

Encryption is the process of encoding data to prevent


unauthorized parties from viewing or modifying and it is said to
occur when data is passed through a series of mathematical
operations that generate an alternate form of that data; the
sequence of these operations is called algorithm. To help
distinguish between the two forms of data, the unencrypted data

7
is referred to as the plaintext and the encrypted data as
ciphertext.

Decryption is the process of converting ciphertext back to


plaintext by reversing the algorithm used or by using a key that
was used to encrypt the data.

Project Prerequisites
To build this project we will use basic concept of python,
Tkinter, and base64 library.
• Tkinter is a standard GUI python library
• base64 module provides a function to encode the binary data
to ASCII characters and decode that ASCII characters back to
binary data.

Project File Structure


The step to build message encode – decode python project
• Import module
• Create display window
• Define function
• Define labels and buttons

Steps to develop message encode-decode project


8
1. Import Libraries
The first step is to import tkinter and base64 libraries.

2. Initialize window
• Tk() initialized tkinter which means window created
• geometry() set the width and height of the window
• resizable(0,0) set the fixed size of the window
• title() set the title of the window

3. Define variables
• Text variable stores the message to encode and decode
• private_key variable store the private key used to encode and decode
• mode is used to select that is either encoding or decoding
• Result store the result

4. Function to encode
Encode function have arguments – key and message

5. Function to decode
Decode() function has arguments – key, message

6. Function to set Mode


User sets the mode if ‘e’ then Encode() function will be
execute
If ‘d’ then Decode() function will be executed

7. Function to Exit window


[Link]() will quit the program by stopping the mainloop()

8. Function to reset window


Function sets all variable to empty string

9. Labels and Buttons


9
• Label() widget use to display one or more than one line of text that users aren’t
able to modify.
• Entry() widget used to create an input text field.
• Button() widget used to display button on our window

Project Source Code


# import tkinter module
from tkinter import *
# import other necessery modules
import random
# Vigenère cipher for encryption and decryption
import base64
# creating root object
root = Tk()

# defining size of window


[Link]("1200x6000")
# setting up the title of window
[Link]("Message Encryption and Decryption")
Tops = Frame(root, width=1500, relief=SUNKEN)
[Link](side=TOP)
f1 = Frame(root, width=600, relief=SUNKEN)
[Link](side=LEFT)
# ==============================================

10
lblInfo = Label(Tops, font=('Calibri Light (Headings)', 50, 'bold'),
text="SECRET MESSAGING \n Vigenère Cipher",
fg="Green", bd=10, anchor='w')

[Link](row=0, column=0)

# Initializing variables
Msg = StringVar()
key = StringVar()
mode = StringVar()
Result = StringVar()

# labels for the message


lblMsg = Label(f1, font=('Times New Roman', 16, 'bold'),
text="MESSAGE", bd=16, anchor="w")

[Link](row=1, column=0)
# Entry box for the message
txtMsg = Entry(f1, font=('arial', 16, 'bold'),
textvariable=Msg, bd=10, insertwidth=4,
bg="powder blue", justify='right')

[Link](row=1, column=1)
# labels for the key
lblkey = Label(f1, font=('Times New Roman', 16, 'bold'),
text="KEY (Only Integer)", bd=16, anchor="w")

[Link](row=2, column=0)

11
# Entry box for the key
txtkey = Entry(f1, font=('arial', 16, 'bold'),
textvariable=key, bd=10, insertwidth=4,
bg="powder blue", justify='right')

[Link](row=2, column=1)

# labels for the mode


lblmode = Label(f1, font=('Times New Roman', 16, 'bold'),
text="MODE(e for encrypt, d for decrypt)",
bd=16, anchor="w")

[Link](row=3, column=0)
# Entry box for the mode
txtmode = Entry(f1, font=('arial', 16, 'bold'),
textvariable=mode, bd=10, insertwidth=4,
bg="powder blue", justify='right')
[Link](row=3, column=1)

# labels for the result


lblResult = Label(f1, font=('Times New Roman', 16, 'bold'),
text="The encoded message -", bd=16, anchor="w")

[Link](row=2, column=2)

# Entry box for the result


txtResult = Entry(f1, font=('arial', 16, 'bold'),
textvariable=Result, bd=10, insertwidth=4,
bg="powder blue", justify='right')

12
[Link](row=2, column=3)

# Vigenère cipher
# Function to encode
def encode(key, msg):
enc = []
for i in range(len(msg)):
key_c = key[i % len(key)]
enc_c = chr((ord(msg[i]) +
ord(key_c)) % 256)
[Link](enc_c)
print("enc:", enc)
return base64.urlsafe_b64encode("".join(enc).encode()).decode()

# Function to decode
def decode(key, enc):
dec = []

enc = base64.urlsafe_b64decode(enc).decode()
for i in range(len(enc)):
key_c = key[i % len(key)]
dec_c = chr((256 + ord(enc[i]) -
ord(key_c)) % 256)

[Link](dec_c)
13
print("dec:", dec)
return "".join(dec)

def Results():
# print("Message= ", ([Link]()))

msg = [Link]()
k = [Link]()
m = [Link]()

if (m == 'e'):
[Link](encode(k, msg))
else:
[Link](decode(k, msg))

# exit function
def qExit():
[Link]()

# Function to reset the window


def Reset():

[Link]("")
[Link]("")
[Link]("")
[Link]("")
14
# Show message button
btnTotal = Button(f1, padx=16, pady=8, bd=16, fg="black",
font=('arial', 16, 'bold'), width=10,
text="Secret Message", bg="powder blue",
command=Results).grid(row=7, column=1)

# Reset button
btnReset = Button(f1, padx=16, pady=8, bd=16,
fg="black", font=('arial', 16, 'bold'),
width=10, text="Reset", bg="green",
command=Reset).grid(row=7, column=2)

# Exit button
btnExit = Button(f1, padx=16, pady=8, bd=16,
fg="black", font=('arial', 16, 'bold'),
width=10, text="Exit", bg="red",
command=qExit).grid(row=7, column=3)

# keeps window alive


[Link]()

15
First screen

Encoded Example Screen

16
Decoded Example Screen

Summary
We have successfully developed Message encode – decode
project in Python. We used the popular tkinter library for

17
rendering graphics on a display window and base64 to encode &
decode. We learned how to encode and decode the string, how to
create button, widget, and pass the function to the button.

In this way, we can encode our message and decode the encoded
message in a secure way by using the key. We hope you enjoyed
building this python project.

18
BIBLIOGRAPHY

[Link]
[Link]
[Link]

19

You might also like