-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaesar-cypher-dry.py
More file actions
executable file
·80 lines (61 loc) · 3.01 KB
/
Copy pathcaesar-cypher-dry.py
File metadata and controls
executable file
·80 lines (61 loc) · 3.01 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
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
logo = '''
.oooooo.
d8P' `Y8b
888 .oooo. .ooooo. .oooo.o .oooo. oooo d8b
888 `P )88b d88' `88b d88( "8 `P )88b `888""8P
888 .oP"888 888ooo888 `"Y88b. .oP"888 888
`88b ooo d8( 888 888 .o o. )88b d8( 888 888
`Y8bood8P' `Y888""8o `Y8bod8P' 8""888P' `Y888""8o d888b
.oooooo. oooo
d8P' `Y8b `888
888 oooo ooo oo.ooooo. 888 .oo. .ooooo. oooo d8b
888 `88. .8' 888' `88b 888P"Y88b d88' `88b `888""8P
888 `88..8' 888 888 888 888 888ooo888 888
`88b ooo `888' 888 888 888 888 888 .o 888
`Y8bood8P' .8' 888bod8P' o888o o888o `Y8bod8P' d888b
.o..P' 888
`Y8P' o888o
'''
print(logo)
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']
run_again = True
def caesar_cypher():
direction = input(
"\nType 'encode' to encrypt your message or 'decode' to decrypt it:\n --: ").lower()
new_text = ""
original_alpha = alphabet
if direction == "encode":
text = input("\nType your message here:\n --: ").lower()
shift = int(input("\nKey in the shift number:\n --: ")) % 25
shifted_alpha = alphabet[shift:] + alphabet[:shift]
elif direction == "decode":
text = input("\nType your message here:\n --: ").lower()
shift = int(input("\nKey in the shift number:\n --: "))
shifted_alpha = alphabet[-shift:] + alphabet[:-shift]
else:
print("\nThat is not an acceptable option! ")
return
text = text.split(" ")
for word in text:
new_word = []
for item in word:
if item in original_alpha:
index = original_alpha.index(item)
new_word += shifted_alpha[index]
else:
new_word += item
encrypted_w = "".join(new_word)
new_text += (encrypted_w + " ")
print(
f"\n\n Your new message reads: \n\n -----------------------------------------\n\n {new_text} \n\n------------------------------------------\n")
while run_again == True:
caesar_cypher()
answer = input(
"\nWould you like to run it again? Type yes or no:\n --: ").lower()
if answer == "yes":
run_again = True
elif answer == "no":
run_again = False
else:
break