-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdp_encoder.py
151 lines (95 loc) · 2.55 KB
/
dp_encoder.py
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
'''
COP3502C Spring 2023, Lisha Zhou
lab 06 - Version Control
Donovan Porter ufid: 3156-0961
'''
super_encoded = ''
super_decoded = ''
passing = ''
def encoder(pw):
'''
Takes string value of integers. Returns an encrypted string value of integers.
'''
password = list(pw)
encoded = ''
for i in password:
if i == '7' or i == '8' or i == '9':
i = int(i)
i = i + 3 - 10
else:
i = int(i)
i += 3
encoded += str(i)
return encoded
# This function decodes a previously encoded password
def decoder(encoded):
decoded = ''
encoded = str(encoded)
for i in encoded:
i = int(i)
if i == 2 or i == 1 or i == 0:
i = i + 10
i -= 3
decoded += str(i)
return decoded
def menu():
'''
Displays a menu to the user, and asks for a choice.
'''
print('''What would you like to do?
1. Encode
2. Decode
3. Quit
''')
choice = input()
if int(choice) < 1 and int(choice) > 3:
raise ValueError('Choice out of bounds.')
return choice
def main():
'''
Main logic loop.
'''
global super_encoded
global super_decoded
global passing
try:
chose = int(menu())
# Third option is 'Quit'
if chose == 3:
quit()
# First option is 'Encode'
elif chose == 1:
print('Please enter your password to encode: ')
passing = input()
print('Your password has been encoded and stored!')
# I put in the code for this part of main!! I tried to match your formatting as best I could.
elif chose == 2:
super_encoded = encoder(passing)
super_decoded = decoder(super_encoded)
print(f'The encoded password is {super_encoded}, and the original password is {super_decoded}.\n')
# Restarts program if choice is out of bounds.
except ValueError:
print('Please enter an integer 1, 2, or 3.')
main()
# Restarts program.
main()
# What's this called? A dunder?
if __name__ == '__main__':
main()
# Congratulations if you have gotten this far.
# But, now you must die.
# My attack kitten leaves no survivors.
# /\ /\
#/ \ / \
# (*) (*)
# = M =
# mwrar
# You fool! I have created an equally powerful being.
# Meet the smiley face which is very good at beating up kittens!!
# While they fight I shall sneak away unscathed.
# _________
# / (@) (@)\
# | \______/ |
# \_________/
# *Grins*