diff --git a/Encryption_Project/README.md b/Encryption_Project/README.md new file mode 100644 index 0000000..1992a90 --- /dev/null +++ b/Encryption_Project/README.md @@ -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* diff --git a/Encryption_Project/encryption/aes.py b/Encryption_Project/encryption/aes.py new file mode 100644 index 0000000..c284215 --- /dev/null +++ b/Encryption_Project/encryption/aes.py @@ -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 diff --git a/Encryption_Project/encryption/base64.py b/Encryption_Project/encryption/base64.py new file mode 100644 index 0000000..8bf15b4 --- /dev/null +++ b/Encryption_Project/encryption/base64.py @@ -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 \ No newline at end of file diff --git a/Encryption_Project/encryption/sha.py b/Encryption_Project/encryption/sha.py new file mode 100644 index 0000000..1892060 --- /dev/null +++ b/Encryption_Project/encryption/sha.py @@ -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 diff --git a/Encryption_Project/main.py b/Encryption_Project/main.py new file mode 100644 index 0000000..d0b72d7 --- /dev/null +++ b/Encryption_Project/main.py @@ -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() diff --git a/Encryption_Project/requirements.txt b/Encryption_Project/requirements.txt new file mode 100644 index 0000000..acdfd20 --- /dev/null +++ b/Encryption_Project/requirements.txt @@ -0,0 +1 @@ +pycryptodome