-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
55 lines (51 loc) · 1.67 KB
/
main.py
File metadata and controls
55 lines (51 loc) · 1.67 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
def encode(password):
new_password = ""
for i in range(len(password)):
new_password += str((int(password[i]) + 3)%10)
return new_password
def decode(password):
decoded = ''
decoding = []
for i in range(0, len(password)):
decoding.append(decoded + str(int(password[i:i + 1]) - 3))
for i in range(0,len(password)):
if decoding[i] == '-3':
decoded = decoded + str(7)
elif decoding[i] == '-2':
decoded = decoded + str(8)
elif decoding[i] == '-1':
decoded = decoded + str(9)
else:
decoded = decoded + str(decoding[i])
return decoded
def main():
global password
# Print Menu
print("Menu\n-------------\n1. Encode\n2. Decode\n3. Quit\n")
try:
choice = int(input("Please enter an option: "))
except:
print("Invalid Input! Please try again.")
else:
if choice == 1:
# Ask user for proper input
while True:
try:
password_input = str(input("Please enter your password to encode: "))
password = encode(password_input)
print("Your password has been encoded and stored!\n")
except:
print("Invalid Password Input! Please try again.")
else:
break
elif choice == 2:
# Decode
print(f"The encoded password is {password}, and the original password is {decode(password)}.\n")
pass
elif choice == 3:
exit()
else:
print("Invalid Input!")
if __name__ == "__main__":
while True:
main()