From dd21662fa85c1bd2653025a3b3643ff43c0079bc Mon Sep 17 00:00:00 2001 From: moon Date: Mon, 23 Feb 2026 21:41:32 +0000 Subject: [PATCH 1/2] add encryption project --- Encrypt_Message/README.md | 6 ++++ Encrypt_Message/encryption/aes.py | 13 ++++++++ Encrypt_Message/encryption/sha.py | 5 +++ Encrypt_Message/main.py | 54 +++++++++++++++++++++++++++++++ Encrypt_Message/requirements.txt | 1 + 5 files changed, 79 insertions(+) create mode 100644 Encrypt_Message/README.md create mode 100644 Encrypt_Message/encryption/aes.py create mode 100644 Encrypt_Message/encryption/sha.py create mode 100644 Encrypt_Message/main.py create mode 100644 Encrypt_Message/requirements.txt diff --git a/Encrypt_Message/README.md b/Encrypt_Message/README.md new file mode 100644 index 0000000..93db246 --- /dev/null +++ b/Encrypt_Message/README.md @@ -0,0 +1,6 @@ +# Encrypt Message + +A bad made Encrypt code that can Encrypt with: +SHA-256 +AES-128 +More soon \ No newline at end of file diff --git a/Encrypt_Message/encryption/aes.py b/Encrypt_Message/encryption/aes.py new file mode 100644 index 0000000..9fccb38 --- /dev/null +++ b/Encrypt_Message/encryption/aes.py @@ -0,0 +1,13 @@ +from Crypto.Cipher import AES + +def aes_enc(message: str, key: bytes): + mess = message.encode() + cipher = AES.new(key, AES.MODE_EAX) + nonce = cipher.nonce + mess_cipher, tag = cipher.encrypt_and_digest(mess) + return mess_cipher, nonce + +def aes_desc(message: bytes, key: bytes, nonce: bytes): + + cipher = AES.new(key, AES.MODE_EAX, nonce=nonce) + return cipher.decrypt(message) \ No newline at end of file diff --git a/Encrypt_Message/encryption/sha.py b/Encrypt_Message/encryption/sha.py new file mode 100644 index 0000000..8d5eee3 --- /dev/null +++ b/Encrypt_Message/encryption/sha.py @@ -0,0 +1,5 @@ +import hashlib + +def sha256_enc(message: str): + + return hashlib.sha256(message.encode()).hexdigest() \ No newline at end of file diff --git a/Encrypt_Message/main.py b/Encrypt_Message/main.py new file mode 100644 index 0000000..30b282a --- /dev/null +++ b/Encrypt_Message/main.py @@ -0,0 +1,54 @@ +from encryption import sha, aes +import os + +def main(): + """ + This is the entry point of this Encryption Message + """ + + print("""Welcome to Encrypt Message!\n + Your options are:\n + 1 - AES\n + 2 - SHA\n +""") + + option = int(input()) + + match option: + case 1: + + print("""Do you want to encrypt or decrypt a message?\n + 1 - Encrypt + 2 - Decrypt""") + + enc_dec = int(input()) + + if enc_dec == 1: + + message = input("Which message you want to encrypt? ") + key = os.urandom(16) + + print(f"Your key is {key}\n*Save it!*") + + enc_mess, nonce = aes.aes_enc(message, key) + + print(f"{enc_mess}\n{nonce}\n*Save this*") + else: + message = eval(input("What's the message you want to decrypt? ")) + key = eval(input("What's the key? ")) + nonce = eval(input("What's the nonce? ")) + + desc_mess = aes.aes_desc(message, key, nonce) + + print(f"{desc_mess}") + + case 2: + message = input("What's the message you want to hide? (This method is unreversible)") + + enc_mess = sha.sha256_enc(message) + + print(f"{enc_mess}") + +if __name__ == "__main__": + main() + diff --git a/Encrypt_Message/requirements.txt b/Encrypt_Message/requirements.txt new file mode 100644 index 0000000..c21b6ec --- /dev/null +++ b/Encrypt_Message/requirements.txt @@ -0,0 +1 @@ +pycryptodome \ No newline at end of file From cbf6192cbaa0ff7847d3aa2dea95a170464a018e Mon Sep 17 00:00:00 2001 From: moon Date: Tue, 24 Feb 2026 19:09:21 +0000 Subject: [PATCH 2/2] added encryption project This is a project to make examples of how to encrypt using specific methods listed in the README --- Encrypt_Message/README.md | 6 -- Encrypt_Message/encryption/aes.py | 13 ----- Encrypt_Message/encryption/sha.py | 5 -- Encrypt_Message/main.py | 54 ------------------ Encrypt_Message/requirements.txt | 1 - Encryption_Project/README.md | 9 +++ Encryption_Project/encryption/aes.py | 22 ++++++++ Encryption_Project/encryption/base64.py | 16 ++++++ Encryption_Project/encryption/sha.py | 10 ++++ Encryption_Project/main.py | 73 +++++++++++++++++++++++++ Encryption_Project/requirements.txt | 1 + 11 files changed, 131 insertions(+), 79 deletions(-) delete mode 100644 Encrypt_Message/README.md delete mode 100644 Encrypt_Message/encryption/aes.py delete mode 100644 Encrypt_Message/encryption/sha.py delete mode 100644 Encrypt_Message/main.py delete mode 100644 Encrypt_Message/requirements.txt create mode 100644 Encryption_Project/README.md create mode 100644 Encryption_Project/encryption/aes.py create mode 100644 Encryption_Project/encryption/base64.py create mode 100644 Encryption_Project/encryption/sha.py create mode 100644 Encryption_Project/main.py create mode 100644 Encryption_Project/requirements.txt diff --git a/Encrypt_Message/README.md b/Encrypt_Message/README.md deleted file mode 100644 index 93db246..0000000 --- a/Encrypt_Message/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# Encrypt Message - -A bad made Encrypt code that can Encrypt with: -SHA-256 -AES-128 -More soon \ No newline at end of file diff --git a/Encrypt_Message/encryption/aes.py b/Encrypt_Message/encryption/aes.py deleted file mode 100644 index 9fccb38..0000000 --- a/Encrypt_Message/encryption/aes.py +++ /dev/null @@ -1,13 +0,0 @@ -from Crypto.Cipher import AES - -def aes_enc(message: str, key: bytes): - mess = message.encode() - cipher = AES.new(key, AES.MODE_EAX) - nonce = cipher.nonce - mess_cipher, tag = cipher.encrypt_and_digest(mess) - return mess_cipher, nonce - -def aes_desc(message: bytes, key: bytes, nonce: bytes): - - cipher = AES.new(key, AES.MODE_EAX, nonce=nonce) - return cipher.decrypt(message) \ No newline at end of file diff --git a/Encrypt_Message/encryption/sha.py b/Encrypt_Message/encryption/sha.py deleted file mode 100644 index 8d5eee3..0000000 --- a/Encrypt_Message/encryption/sha.py +++ /dev/null @@ -1,5 +0,0 @@ -import hashlib - -def sha256_enc(message: str): - - return hashlib.sha256(message.encode()).hexdigest() \ No newline at end of file diff --git a/Encrypt_Message/main.py b/Encrypt_Message/main.py deleted file mode 100644 index 30b282a..0000000 --- a/Encrypt_Message/main.py +++ /dev/null @@ -1,54 +0,0 @@ -from encryption import sha, aes -import os - -def main(): - """ - This is the entry point of this Encryption Message - """ - - print("""Welcome to Encrypt Message!\n - Your options are:\n - 1 - AES\n - 2 - SHA\n -""") - - option = int(input()) - - match option: - case 1: - - print("""Do you want to encrypt or decrypt a message?\n - 1 - Encrypt - 2 - Decrypt""") - - enc_dec = int(input()) - - if enc_dec == 1: - - message = input("Which message you want to encrypt? ") - key = os.urandom(16) - - print(f"Your key is {key}\n*Save it!*") - - enc_mess, nonce = aes.aes_enc(message, key) - - print(f"{enc_mess}\n{nonce}\n*Save this*") - else: - message = eval(input("What's the message you want to decrypt? ")) - key = eval(input("What's the key? ")) - nonce = eval(input("What's the nonce? ")) - - desc_mess = aes.aes_desc(message, key, nonce) - - print(f"{desc_mess}") - - case 2: - message = input("What's the message you want to hide? (This method is unreversible)") - - enc_mess = sha.sha256_enc(message) - - print(f"{enc_mess}") - -if __name__ == "__main__": - main() - diff --git a/Encrypt_Message/requirements.txt b/Encrypt_Message/requirements.txt deleted file mode 100644 index c21b6ec..0000000 --- a/Encrypt_Message/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -pycryptodome \ No newline at end of file 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