Edona - Encryptor and Decryptor: Using Python protect your Data.

Edona – Encryptor and Decryptor: Using Python protect your Data

Introduction:

In today’s digital age, securing sensitive information is more important than ever. One effective way to protect your data is through encryption. This blog post will guide you through creating Edona a password encryptor and decryptor tool using Python, It uses a secret key to encrypt and decrypt password or data.

It’s a security risk because if our computer gets hacked and the data is stolen, the attacker could use our password to perform malicious actions. When you encrypt a password and save it in a file, it becomes secure because it can only be decrypted with the secret PIN you set. This ensures that even if someone accesses the file, they cannot read the password without the PIN.

Note:- I named my python tool “Edona”

Technical Overview of Edona:

Following are the pseudo code and steps that we follow to implement the endcoding and decoding process of Edona.

Encoding Process:

  1. Take input string from user.
  2. Take a secret pin from the user.
  3. Encode the input string to base64.
  4. Split the base64 encoded string in the length number of pin. ex: if user input 32 then its length is 2 therefore base64 string or password is split into two parts.
  5. Replace the character with its pin digit from letters. ex: as 3 is first character of 32, therefore each character of the first part of base64 string or passsword is exceed by that value. (‘a’ becomes ‘d’).

Decoding Process:

  1. Take encrypted string or password from user.
  2. Take a secret pin from the user that user use to encrypt the password previously.
  3. Split the encrypted password in the length number of secret pin.
  4. Restore the character through pin value. ex: as 3 is first character of 32, therefore each character of the first part of base64 string or password is back to the value. (‘d’ becomes ‘a’).

Remember the secret key you used to encrypt the password, as you’ll need it to decrypt the password later. There’s no need to manually copy the encrypted or decrypted password, as it will be copied automatically.

Requirements:

Before we start, make sure you have Python installed on your computer. Using a code editor like Visual Studio Code or PyCharm will also make coding and testing much more convenient. Following python’s modules are needed:-

  • String module: It is a pre-installed module.
  • Base64 module: Built-in module, no need to install.
  • Tkinter module: This python’s module will help to create GUI applications. Install this using the commang, pip install tk-tools==0.16.0

Python Code:

You can also check out this project on GitHub.

# https://amanaadi.com  --> Python's Project

import base64
import string
from tkinter import *


def main():
    def clip(text):
        window.clipboard_clear()
        window.clipboard_append(text)

    def enc():
        data = pass_entry.get()
        pin = pin_entry.get()
        encryted_data = encryptor(data, pin)
        show_label.config(text=encryted_data)
        clip(encryted_data)

    def dec():
        data = pass_entry.get()
        pin = pin_entry.get()
        decryted_data = decryptor(data, pin)
        show_label.config(text=decryted_data)
        clip(decryted_data)

    FONT = ("Arial", 15, "normal")

    window = Tk()
    window.title("Edona - Encryptor and Decryptor")
    window.config(padx=20, pady=20)

    pin_label = Label(text="Secret Pin:", font=FONT)
    pin_label.grid(row=0, column=0)

    pin_entry = Entry(width=20, font=FONT, )
    pin_entry.grid(row=0, column=2, pady=15)

    pass_label = Label(text="Password:", font=FONT)
    pass_label.grid(row=1, column=0)

    pass_entry= Entry(width=20, font=FONT)
    pass_entry.grid(row=1, column=2)

    enc_button = Button(text="Encrypt", font=FONT, command=enc)
    enc_button.grid(row=2, column=0, pady=50, padx=10)

    dec_button = Button(text="Decrypt", font=FONT, command=dec)
    dec_button.grid(row=2, column=2, pady=50)

    show_label = Label(text="", font=FONT)
    show_label.grid(row=3, column=1)
    
    window.mainloop()



def split_string(data, number):
    """Split the string in 'n' number of parts. and return a list"""

    parts = []

    for i in range(number):
        m = i+1
        n = len(data)//number  # each parts should have this number of characters.
        if i == 0: # It run for making first part.
            parts.append(data[:n])  # it is same as n
        elif i == number-1: # it runs for making last part.  
            parts.append(data[n*i:])
        else: # it runs for making middle parts.
            parts.append(data[n*i:n*m])

    return parts


def encryptor(data, pin):
    """take the splited string and exceed the character index by given pin value respectively."""

    pin_len = len(pin)
    b64_encode = base64.b64encode(data.encode()).decode()
    splited_b64e_data = split_string(b64_encode, pin_len)
    letters = list(string.printable)
    new_encoded_data = ""

    for i in range(pin_len):
        for ch in splited_b64e_data[i]:
            if ch in letters:
                index = letters.index(ch)
                pin_index = int(pin[i])
                new_encoded_data += letters[index+pin_index]

    return new_encoded_data


def decryptor(data, pin):
    """take the splited string and exceed the character index by given pin value respectively."""

    pin_len = len(pin)
    splited_b64e_data = split_string(data, pin_len)
    letters = list(string.printable)
    b64_encoded_data = ""

    for i in range(pin_len):
        for ch in splited_b64e_data[i]:
            if ch in letters:
                index = letters.index(ch)
                pin_index = int(pin[i])
                b64_encoded_data += letters[index-pin_index]

    b64_decoded_data = base64.b64decode(b64_encoded_data).decode()
    return b64_decoded_data



if __name__ == "__main__":
    main()

Commands & Outputs:

Conclusion:

Congratulations! You’ve successfully created EDONA – encryptor and decryptor tool using Python. This tool can help you secure sensitive information by encrypting it with a secret key and decrypting it only when needed. By following these steps, you’ve taken an essential step towards enhancing your data security. Remember to keep your secret key safe and never share it with anyone you don’t trust.

Discover more from Aman Aadi

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top