Created
December 12, 2024 01:02
-
-
Save AO8/40120967e5923059174ac04ee5b75aa3 to your computer and use it in GitHub Desktop.
Simple Binary 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 binary encryption | |
def encrypt_message(message): | |
encrypted = ' '.join(format(ord(char), '08b') for char in message) | |
return encrypted | |
def decrypt_message(encrypted_message): | |
decrypted = ''.join(chr(int(binary, 2)) for binary 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