Secret Message Encrypter(ZeroAndOne)

by TechnoFrost in Circuits > Software

220 Views, 1 Favorites, 0 Comments

Secret Message Encrypter(ZeroAndOne)

Screenshot 2021-12-08 093627.png

This right here, is a secret ZeroandOne code interpreter, basically it encrypts text in a way which without our tool, is impossible to decode. In this instructable, you can learn how to make your own and how this one works! It uses 4 levels of decryption, including using a custom key which only you know. Here's a link for you to try it yourself

Supplies

Python

Any IDE of your choice(I use Sublime Text)

3 Braincells

Installing Requirements

Assuming that you have python installed on your computer, first you need to download the requirements.

To achieve this we are going to use PIP, a python package managing tool. In this project we use Flask(a web frame work for python) and python-dotenv(a module used to read .env files)

Type this in your terminal

pip install flask python-dotenv


How It Works

Screenshot 2021-12-08 164513.png
Order of files for this project

So basically, we will make 2 modules, encrypt.py and decrypt.py which we will use in the main code, to make our code look cleaner and more professional and because why the heck not.

Before we start doing clickity clackity on our keyboards, we should probably understand how it works right?

First we make a key based on the alphabets, and any other characters you want it to include. Then we use that key to encrypt text. After this we use a technique called Caesar Cipher to shift alphabets by 8. Then we add random characters to confuse would-be-secret-spillers. Then like a boss we REVERSE the string and return it as encrypted text.


.

Coding the Main Function

Screenshot 2021-12-08 164642.png
main.py

Create a file and name it main.py. This will be the file we run every time, and it will start the flask server

you can just copy it here

Now let me explain the code. first we import the modules called encrypt and decrypt that we have made, then we import stuff from Flask, a python web framework.

After that we start the flask server and make a function. We have used HTML and CSS to create a webpage. In the html code, we have input boxes which return "processed_text". Then we have called the functions from the modules, depending on which button in pressed.

Coding the Encrypt and Decrypt Functions

image.png
Screenshot 2021-12-08 171150.png
Screenshot 2021-12-08 171209.png

So now we just have to encrypt or decrypt the text and return it to the main program, because we have made those 2 functions into separate modules.


First of all, instead of just showing sensitive info like the alphabet and key, we recommend saving them in a .env file

.env
key=paste_the_key_you_get_from_makekey.py_here
alphabet=abcdefghijklm nopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%&*()-_+="';:<>,.?{}[]

Now we need a "key" for this to be really secure. So lets just make one using the characters allowed(numbers work but they aren't included here)

Here is how you can make one!

Run this code

import random
import os
from dotenv import load_dotenv, find_dotenv


load_dotenv(find_dotenv())
alphabet = os.environ['alphabet']


def makeKey(alphabet):  # needed only while making new key
        alphabet = list(alphabet)
        random.shuffle(alphabet)
        return ''.join(alphabet) #then store this in a safe place for eg environment variable


print(makeKey(alphabet))

Or you can just copy the code from the main source code given below


Then copy paste this key in the .env file and don't add quotes.

Now what you can do is do all this code locally, or just fork my repl here


Here is the source code.

Doing the HTML CSS Part

Screenshot 2021-12-08 171441.png
Screenshot 2021-12-08 171408.png
Screenshot 2021-12-08 171549.png

Follow the above hierarchy and make folders. Then copy the code from the source code given above

Finishing Up!

And there it is! You should now have a working message Encrypter and Decrypter! This was made as a submission for the hourofcode21 contest