-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
35 lines (24 loc) · 944 Bytes
/
main.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
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
def main():
cipher_continue = True
while cipher_continue:
option = input("Will you encode or decode: ")
message = input("What is your message: ")
shift = int(input("How much will you offset: "))
print(caesar(option, message, shift))
keep_playing = input("Keep Playing? [yes/no]")
if keep_playing == 'no':
print("User exited program!")
cipher_continue = False
def caesar(option, message, shift):
new_text = ""
if option == 'decode':
shift *= -1
for char in message:
if char in alphabet:
position = alphabet.index(char)
new_position = position + shift
new_text += alphabet[new_position]
return new_text
if __name__ == "__main__":
main()