-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day-8
36 lines (31 loc) · 1.42 KB
/
Day-8
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
from art import logo
def main():
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', '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']
direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n")
text = input("Type your message:\n").lower()
shift = int(input("Type the shift number:\n"))
def ceasar(start_text, shift_amount, cipher_direction):
end_text = ""
for letter in start_text:
if letter in alphabet:
position = alphabet.index(letter)
if direction == "encode":
new_position = position - shift_amount
elif direction == "decode":
new_position = position + shift_amount
shift_amount = shift_amount % 26
new_word = alphabet[new_position]
end_text += new_word
else:
end_text += letter
print(f"The {cipher_direction} result is: {end_text}")
ceasar(text, shift, direction)
main()
last = input("Type 'yes' if you want to go again. Otherwise type 'no'.\n")
if last == "no":
print("Good Bye")
while last == "yes":
main()
last = input("Type 'yes' if you want to go again. Otherwise type 'no'.\n")