Created
September 13, 2023 02:34
-
-
Save mheidari98/e5cf4425876add8bd0ab0ce40edd4845 to your computer and use it in GitHub Desktop.
Letters Positions Encryption & Decryption
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
import time | |
import random | |
def encrypt(txt): | |
lst = [f"{c}{i+1}" for i, c in enumerate(txt)] | |
random.shuffle(lst) | |
print(f" cipher: {' '.join(lst)}\n") | |
def decrypt(enc): | |
splitted = enc.split(' ') | |
for c in splitted: | |
char = c[0] | |
place = int(c[1:]) | |
time.sleep(0.1) | |
print(f'\033[{place}C' + char, end='') | |
print('\r', end='') | |
print("\n") | |
def menu(): | |
print("1. Encryption") | |
print("2. Decryption") | |
print("3. Exit") | |
return input("> select one option: ") | |
while True: | |
selected = menu() | |
if selected == "1": | |
txt = input("\nEnter your text: ") | |
encrypt(txt) | |
elif selected == "2": | |
enc = input("\nEnter your cipher: ") | |
decrypt(enc.strip()) | |
elif selected == "3": | |
break | |
else: | |
print("\t[X] Wrong input!\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment