-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcaesar_cipher.py
65 lines (45 loc) · 1.88 KB
/
caesar_cipher.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
import art
#encryption and decryption
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 caesar(choice, message, shift):
if choice == "decode":
shift *= -1
output = ""
for letter in message:
shifted_index = alphabet.index(letter) + shift
shifted_index %= len(alphabet)
output += alphabet[shifted_index]
print(f"Your {choice}d message : {output}")
print(art.cipher)
should_continue = True
while should_continue:
choice = input("Do you want to encrypt or decrypt?\nType 'encode' to encrypt or 'decode' to decrypt\n").lower()
message = input("Type your message: ").lower()
shift = int(input("Enter the shift number: "))
caesar(choice, message, shift)
restart = input("Would you like to encode or decode again : \nType 'yes' or 'no'").lower()
if(restart== "no"):
should_continue = False
print("Thank you!!")
'''
def caesar(choice, message, shift):
if choice == "encode":
def encrypt(message, shift):
cipher_text = ""
for letter in message:
shifted_index = alphabet.index(letter) + shift
shifted_index %= len(alphabet)
cipher_text += alphabet[shifted_index]
print(f"Your encoded message is {cipher_text}")
encrypt(message, shift)
elif choice == "decode":
def decrypt(message, shift):
cipher_text = ""
for letter in message:
shifted_index = alphabet.index(letter) - shift
shifted_index %= len(alphabet)
cipher_text += alphabet(shifted_index)
print(f"Your decoded message is {cipher_text}")
else:
print("Invalid")
'''