Coders Packet

Cryptography Project in Python using Tkinter

By Krishna Prasad Deekonda

This packet gives us an idea of how to build a project which will convert your plain secret text to ciphertext and vice versa.

Modules used:


Description /Functionality:

First of all we need to make sure that our python IDE has pip installed in it if not download file from the web in the same directory as Python is installed and then we can install required modules in our IDE Terminal using

pip install command

and In general we use cryptography for secrecy of data and convert into ciphertext  and we use Tkinter in this application as it provides us simple way to create GUI elements using widgets found in TK where we give the user an option/Task whether they want to encrypt/decrypt a particular text by entering e(or)d in the Tk application and dynamically entering the cipher text/secret text for the application in the resulting application and we can either swap the letters or add certain ASCII values to change the meaning of the text.


from tkinter import messagebox, simpledialog, Tk

def is_even(num):
    return num % 2 == 0

def get_even_letters(msg):
    even_letters = []
    for counter in range(0, len(msg)):
        if is_even(counter):
    return even_letters

def get_odd_letters(msg):
    odd_letters = []
    for counter in range(0, len(msg)):
        if not is_even(counter):
    return odd_letters

def swap_letters(msg):
    letter_list = []
    if not is_even(len(msg)):
        msg = msg + 'x'
    even_letters = get_even_letters(msg)
    odd_letters = get_odd_letters(msg)
    for counter in range(0, int(len(msg) / 2)):
    new_msg = ''.join(letter_list)
    return new_msg

def get_task():
    task = simpledialog.askstring('Task', 'Do you want to encrypt or decrypt?')
    return task

def get_msg():
    message = simpledialog.askstring('Message', 'Enter the secret message: ')
    return message

root = Tk()
while True:
    task = get_task()
    if task == 'e':
        msg = get_msg()
        e = swap_letters(msg)
        messagebox.showinfo('Ciphertext of the secret message is:', e)

    elif task == 'd':
        msg = get_msg()
        d = swap_letters(msg)
        messagebox.showinfo('Plaintext of the secret message is:', d)

Download Complete Code


No comments yet