-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathceasar2.py
More file actions
41 lines (36 loc) · 1.45 KB
/
Copy pathceasar2.py
File metadata and controls
41 lines (36 loc) · 1.45 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
from art import logo
print(logo)
play = True
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']
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"))
encrypted_list = []
decrypted_list = []
new_alphabet = alphabet[shift:] + alphabet[:shift]
def ceasarciph(text,shift):
while play:
if direction == 'encode':
print(new_alphabet)
text_indexes = []
for letter in text:
for char in alphabet:
if letter == char:
text_indexes.append(alphabet.index(char))
print(text_indexes)
for num in text_indexes:
encrypted_list.append(new_alphabet[num])
encrypted_message = ''.join(encrypted_list)
print(encrypted_message)
elif direction == 'decode':
text_indexes = []
for letter in text:
for char in new_alphabet:
if letter == char:
text_indexes.append(new_alphabet.index(char))
print(text_indexes)
for num in text_indexes:
decrypted_list.append(alphabet[num])
decrypted_message = ''.join(decrypted_list)
print(decrypted_message)
ceasarciph(text, shift)