Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Encryption_Project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Encryption Project

For now this project can only encrypt messages using the following methods:

* SHA-256
* AES-128
* Base64

*If you want to understand how this works, this project comments all around it to make sure you understand what's happening*
22 changes: 22 additions & 0 deletions Encryption_Project/encryption/aes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Let's start with AES
# AES is a type of encryption used mainly for things that require certain level of safety and later will be used
# There is a specific thing you shouldn't encrypt with AES that's Passkeys
# For passkeys you will use a method showed later that are the Hash Methods

# In this example we using pycryptodome

from Crypto.Cipher import AES

def encrypt_aes(message: str, key: str):
encrypt_cipher = AES.new(key, AES.MODE_EAX) # This is the "configuration" for the encryption

nonce = encrypt_cipher.nonce # Nonce aka Number Once is basically what makes the key random

encrypted_message = encrypt_cipher.encrypt_and_digest(message) # Here we are truly encrypting the message

return encrypted_message, nonce

def decrypt_aes(message: bytes, key: bytes, nonce: bytes):
decrypt_cipher = AES.new(key, AES.MODE_EAX, nonce=nonce) # Here we are Saying what's the key, type of encryption and nonce
decrypted_message = decrypt_cipher.decrypt(message)
return decrypted_message
16 changes: 16 additions & 0 deletions Encryption_Project/encryption/base64.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Let's start
# Base64 is NOT a safe way to encrypt important things, it's used to encrypt binary data to text and doesn't have a key such as AES
# If you pretend encrypting something that you need to know later you should use AES
# Else you just want to encrypt something and doesn't care about the privacy Base64 might be a good choice

# In this example we are using a pre-installed module from Python called "base64"

import base64

def encrypt_base64(message: str):
encrypt_message = base64.b64encode(message.encode()).decode()
return encrypt_message

def decrypt_base64(message: str):
decrypt_message = base64.b64decode(message).decode('utf-8')
return decrypt_message
10 changes: 10 additions & 0 deletions Encryption_Project/encryption/sha.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Let's start with Hashes! (more specifically SHA256)
# Hashes are a way to encrypt thing in a irreversible way
# This means if you encrypt something using Hash Methods there is no way to know the content

# In this example we using pre-installed module called "hashlib"

import hashlib

def encryption_sha(message: str):
return hashlib.sha256().digest() # This makes the encryption in SHA-256. This is the usually how your passkeys are encrypted
73 changes: 73 additions & 0 deletions Encryption_Project/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from encryption import sha, aes, base64
import os

def main():
while True:
print("""Welcome to Encryption Project\n
1 - SHA256\n
2 - AES\n
3 - Base64\n
4 - Quit\n
More soon!\n""")

encrypt_choice = int(input())

match encrypt_choice:
case 1:
message_to_encrypt = input("What's the message you want to encrypt?: ")

encrypted_message = sha.encryption_sha(message_to_encrypt)

print(f"The encrypted message is: {encrypted_message}")

case 2:
aes_choice = int(input("1 - Encrypt\n2 - Decrypt\n"))

if aes_choice == 1:
message_to_encrypt = input("What's the message you want to encrypt? ").encode('utf-8')
key = os.urandom(16) # if you are confused, this just guarantee the key will have 16 bytes

encrypted_message, nonce = aes.encrypt_aes(message_to_encrypt, key)

print(f"Encrypted message: {encrypted_message}\nnonce: {nonce}\nkey: {key}\n *Save those!*")
elif aes_choice == 2:
message_to_decrypt = eval(input("What's the message to decrypt? "))
key = eval(input("What's the key? "))
nonce = eval(input("What's the nonce? "))

decrypted_message = aes.decrypt_aes(message_to_decrypt, key, nonce)

print(f"Message: {decrypted_message}")

else:
print("Option does not exist")

case 3:
base_choice = int(input("1 - Encrypt\n2 - Decrypt\n"))

if base_choice == 1:
message_to_encrypt = input("What's the message you want to encrypt? ")

encrypted_message = base64.encrypt_base64(message_to_encrypt)

print(f"Message: {encrypted_message}")

elif base_choice == 2:
message_to_decrypt = input("What's the message to decrypt? ")

decrypted_message = base64.decrypt_base64(message_to_decrypt)

print(f"Message: {decrypted_message}")

else:
print("Option does not exist")

case 4:
print("Bye!")
break

case _:
print("This option is not available")

if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions Encryption_Project/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pycryptodome