-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtp1.py
More file actions
30 lines (24 loc) · 665 Bytes
/
tp1.py
File metadata and controls
30 lines (24 loc) · 665 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import string
import random
# Generate all possible characters
all_chars = string.ascii_letters + string.digits + string.punctuation
# Count the number of characters
key_length = len(all_chars)
key=list(all_chars)
random.shuffle(key) # Shuffles key in place
print("#" * 30)
# print("All Characters:", all_chars)
# print("Key Length:", key_length)
# print(key)
plain_text=input("enter your plain text")
ciphered_text=""
for letter in plain_text:
index=all_chars.index(letter)
ciphered_text += key[index]
print(ciphered_text)
plain=""
# decryption
for letter in ciphered_text:
index=key.index(letter)
plain += all_chars[index]
print(plain)