-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsofis_encode
More file actions
77 lines (60 loc) · 1.62 KB
/
Copy pathsofis_encode
File metadata and controls
77 lines (60 loc) · 1.62 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
# create menu function with starter display
def menu():
print("Menu")
print("-------------")
print("1. Encode")
print("2. Decode")
print("3. Quit")
# create selection function
def choose_selection():
global selection, password, encoded_password
selection = int(input('Please enter an option: '))
while selection != 3:
if selection == 1:
password = input("Please enter your password to encode:")
encoded_password = encode(password)
print("Your password has been encoded and stored!")
menu()
choose_selection()
if selection == 2:
# add decode function
decoded_password = decode(encoded_password)
print("The encoded password is", encoded_password, "and the original password is", decoded_password, ".")
menu()
choose_selection()
# create encode function
def encode(password):
x = ""
for i in password:
i = int(i)
if i == 7:
i = 0
x = x + str(i)
elif i == 8:
i = 1
x = x + str(i)
elif i == 9:
i = 2
x = x + str(i)
else:
i += 3
x = x + str(i)
return x
#decode function
def decode(encoded_password):
decoded_password = ''
for i in encoded_password:
x = int(i)
if x == 0:
x = 7
elif x == 1:
x = 8
elif x == 2:
x = 9
else:
x -= 3
decoded_password += str(x)
return decoded_password
if __name__ == "__main__":
menu()
choose_selection()