|
| 1 | +from encryption import sha, aes, base64 |
| 2 | +import os |
| 3 | + |
| 4 | +def main(): |
| 5 | + while True: |
| 6 | + print("""Welcome to Encryption Project\n |
| 7 | + 1 - SHA256\n |
| 8 | + 2 - AES\n |
| 9 | + 3 - Base64\n |
| 10 | + 4 - Quit\n |
| 11 | + More soon!\n""") |
| 12 | + |
| 13 | + encrypt_choice = int(input()) |
| 14 | + |
| 15 | + match encrypt_choice: |
| 16 | + case 1: |
| 17 | + message_to_encrypt = input("What's the message you want to encrypt?: ") |
| 18 | + |
| 19 | + encrypted_message = sha.encryption_sha(message_to_encrypt) |
| 20 | + |
| 21 | + print(f"The encrypted message is: {encrypted_message}") |
| 22 | + |
| 23 | + case 2: |
| 24 | + aes_choice = int(input("1 - Encrypt\n2 - Decrypt\n")) |
| 25 | + |
| 26 | + if aes_choice == 1: |
| 27 | + message_to_encrypt = input("What's the message you want to encrypt? ").encode('utf-8') |
| 28 | + key = os.urandom(16) # if you are confused, this just guarantee the key will have 16 bytes |
| 29 | + |
| 30 | + encrypted_message, nonce = aes.encrypt_aes(message_to_encrypt, key) |
| 31 | + |
| 32 | + print(f"Encrypted message: {encrypted_message}\nnonce: {nonce}\nkey: {key}\n *Save those!*") |
| 33 | + elif aes_choice == 2: |
| 34 | + message_to_decrypt = eval(input("What's the message to decrypt? ")) |
| 35 | + key = eval(input("What's the key? ")) |
| 36 | + nonce = eval(input("What's the nonce? ")) |
| 37 | + |
| 38 | + decrypted_message = aes.decrypt_aes(message_to_decrypt, key, nonce) |
| 39 | + |
| 40 | + print(f"Message: {decrypted_message}") |
| 41 | + |
| 42 | + else: |
| 43 | + print("Option does not exist") |
| 44 | + |
| 45 | + case 3: |
| 46 | + base_choice = int(input("1 - Encrypt\n2 - Decrypt\n")) |
| 47 | + |
| 48 | + if base_choice == 1: |
| 49 | + message_to_encrypt = input("What's the message you want to encrypt? ") |
| 50 | + |
| 51 | + encrypted_message = base64.encrypt_base64(message_to_encrypt) |
| 52 | + |
| 53 | + print(f"Message: {encrypted_message}") |
| 54 | + |
| 55 | + elif base_choice == 2: |
| 56 | + message_to_decrypt = input("What's the message to decrypt? ") |
| 57 | + |
| 58 | + decrypted_message = base64.decrypt_base64(message_to_decrypt) |
| 59 | + |
| 60 | + print(f"Message: {decrypted_message}") |
| 61 | + |
| 62 | + else: |
| 63 | + print("Option does not exist") |
| 64 | + |
| 65 | + case 4: |
| 66 | + print("Bye!") |
| 67 | + break |
| 68 | + |
| 69 | + case _: |
| 70 | + print("This option is not available") |
| 71 | + |
| 72 | +if __name__ == "__main__": |
| 73 | + main() |
0 commit comments