-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspy.py
More file actions
81 lines (46 loc) · 1.6 KB
/
Copy pathspy.py
File metadata and controls
81 lines (46 loc) · 1.6 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import random
import string
# Generate random letters
def random_letters():
return ''.join(random.choices(string.ascii_letters, k=3))
while True:
print("\n====== SECRET CODE LANGUAGE ======")
print("1. Encode Message")
print("2. Decode Message")
print("3. Exit")
choice = input("Enter your choice: ")
# ------------------ ENCODE ------------------
if choice == "1":
message = input("\nEnter your message: ")
words = message.split()
encoded_message = []
for word in words:
if len(word) >= 3:
first_letter = word[0]
new_word = word[1:] + first_letter
new_word = random_letters() + new_word + random_letters()
encoded_message.append(new_word)
else:
encoded_message.append(word[::-1])
print("\nEncoded Message:")
print(" ".join(encoded_message))
# ------------------ DECODE ------------------
elif choice == "2":
message = input("\nEnter secret code: ")
words = message.split()
decoded_message = []
for word in words:
if len(word) >= 3:
word = word[3:-3]
original = word[-1] + word[:-1]
decoded_message.append(original)
else:
decoded_message.append(word[::-1])
print("\nDecoded Message:")
print(" ".join(decoded_message))
# ------------------ EXIT ------------------
elif choice == "3":
print("\nThank You!")
break
else:
print("\nInvalid Choice!")