Communicate with Your Friends Secretly using Python

Send messages secretly to your friends using python program. It can encrypt and decrypt text messages.

Introduction

Have you ever felt, It would be nice if I could talk to my secret friend(secret means girlfriend/boyfriend) in secret. In teenage many students fall in love and tries to hide his/her friend from their parents, relatives, etc. They want to be connected with each other, but secretly.

There is a chance to caught by someone every time. But today, I came up here with a solution of it with python programming.

In this tutorial, we'll create a python program to Encrypt and Decrypt our Secret Messages. Using this program you can communicate with your friends secretly by encrypting your messages.

Not only senders are gonna get help through it, also receivers will get too. So let's get started.

👉Visit AlsoWish Your Friends with Stylish TExt in Python - ASCII Art

Program Details

Secret Messages

The program will ask you to choose an option between 'encrypt' and 'decrypt'. Then it will ask to type the message in a text box. If you choose 'encrypt', then your message will be formed into a penniless form. But if you choose 'decrypt', your meaningless message will be turned into a text you can read.

How the program works

The program puts a random letter between each pair of letters in the message. Iteration starts from the first two, then the next two, and so on. The program also makes the encrypted text readable again by removing the extra letters from the meaningless message.

Requirements

The Tkinter module has been used to make the GUI of the program. The only third-party module, you've to install before running it.

tkinter: pip install tkinter

Import the modules

You need to import the tkinter module along with some widgets. These will let you use some of the GUI features of the module.


from tkinter import *
from tkinter import ttk, messagebox, simpledialog
from random import choice

Encrypt or Decrypt?

Now create a function: controller(), to show the options of 'encrypt' or 'decrypt' in a combo box for choosing by the users.


def controller():
while True:
if task.get() == 'encrypt':
message = get_message()
encrypted = encrypt(message)
messagebox.showinfo('Encrypted message is:', encrypted)
elif task.get() == 'decrypt':
message = get_message()
decrypted = decrypt(message)
messagebox.showinfo('Decrypted message is:', decrypted)
else:
break

Get the secret message

Now create a new function: 'get_message()', to show a dialog box. It asks the users to enter the message.


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

Encrypt the text

Create a function: 'encrypt()', to create the logic of the encryption technique. We'll put some random fake letters between each pair of letters of the original message. See the image below.

encryption technique - PySeek

def encrypt(message):
encrypted_list = []
fake_letters = ['a', 'b', 'c', 'd', 'e', 'f', 's', 't', 'y', 'z']
for counter in range(0, len(message)):
encrypted_list.append(message[counter])
encrypted_list.append(choice(fake_letters))
new_message = ''.join(encrypted_list)
return new_message

Decrypt the text

Add this 'decrypt()' function just after the 'encrypt()' function, to remove the fake letters from the meaningless text and to get back the original one.

dencryption technique - PySeek

 

def decrypt(message):
even_letters = get_even_letters(message)
new_message = ''.join(even_letters)
return new_message

Get the even letters

Let's create a function 'get_even_letters()', which takes texts and returns a list containing all the even-numbered letters.


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

Is it even?

'is_even()', will tell the program if there's an even number of characters or not, in the text message.


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

The Main Function

Now you need to create the main function to manage the GUI of this program.


if __name__ == '__main__':
root = Tk()
root.geometry("280x130")
root.title('Task')

label_1 = Label(root, text='Do you want to encrypt or decrypt?', \
font=("times new roman",14))
label_1.place(x=10, y=10)

# Get the task
task = StringVar()
task_combobox = ttk.Combobox(root, width=30, height=10, textvariable=task)
task_combobox['values'] = ['encrypt', 'decrypt']
task_combobox.current(0)
task_combobox.place(x=10, y=40)

# Buttons
ok_button = Button(root, text='OK', bg="white", fg="black", \
width= 12,command=controller)
ok_button.place(x=10, y=70)

cancel_button = Button(root, text='Cancel', bg="white", \
fg="black", width= 12,command=root.quit)
cancel_button.place(x=140, y=70)

root.mainloop()

The Output


☛Visit AlsoCreate a Screen Recorder using Python - Very Easy to Use

Summary

In this tutorial, we build a python program which can turn a meaningful message into a gibberish one. We used a simple encryption technique in this program.

✭Do share this code with your friend to communicate with each other secretly

I hope you loved this tutorial. Please share your love, and do comment below for whom you're gonna use this python program.

To get more lovely python topics, visit the separate page created only for Unique Examples. Some examples are given below.

👉Draw the Sketch of Lionel Messi using a Python Program

👉Blurring an image in Python - using OpenCV and Pillow library

👉Extract Metadata from an Image using Python

👉Check the strength of your password using python

Thanks for reading!💙

PySeek

Subhankar Rakshit

Meet Subhankar Rakshit, a Computer Science postgraduate (M.Sc.) and the creator of PySeek. Subhankar is a programmer, specializes in Python language. With a several years of experience under his belt, he has developed a deep understanding of software development. He enjoys writing blogs on various topics related to Computer Science, Python Programming, and Software Development.

1 Comments

Post a Comment
Previous Post Next Post