Created
December 12, 2024 01:06
-
-
Save AO8/df8ea509fab38bce0ca2ebca23e2ccce to your computer and use it in GitHub Desktop.
Simple Unicode Encryption
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple unicode encryption | |
def encrypt_message(message): | |
encrypted = ' '.join(str(ord(char)) for char in message) | |
return encrypted | |
def decrypt_message(encrypted_message): | |
decrypted = ''.join(chr(int(num)) for num in encrypted_message.split()) | |
return decrypted | |
while True: | |
print('\nWhat would you like to do?\n') | |
print('1: Encrypt a message') | |
print('2: Decrypt a message') | |
print('3: Exit') | |
choice = input('\nEnter your choice: ') | |
if choice == '1': | |
user_message = input('\nEnter a message to encrypt:\n') | |
encrypted_message = encrypt_message(user_message) | |
print(f'Encrypted message:\n\n\033[31m{encrypted_message}\033[0m') | |
elif choice == '2': | |
user_encrypted_message = input('\nEnter an encrypted message to decrypt:\n\n') | |
decrypted_message = decrypt_message(user_encrypted_message) | |
print(f'Decrypted message:\n\n\033[31m{decrypted_message}\033[0m') | |
elif choice == '3': | |
print('\n\033[31mGoodbye\033[0m') | |
break | |
else: | |
print('\n\033[31mInvalid choice\033[0m') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment