-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaesar cipher advanced.py
More file actions
41 lines (35 loc) · 1.71 KB
/
caesar cipher advanced.py
File metadata and controls
41 lines (35 loc) · 1.71 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
logo = r"""
___ ___ ___ ___ ___ __ ___ ( ) ___ / __ ___ __
// ) ) // ) ) //___) ) (( ) ) //___) ) // ) ) // ) ) / / // ) ) // ) ) //___) ) // ) )
// // / / // \ \ // // // / / //___/ / // / / // //
((____ ((___( ( ((____ // ) ) ((____ // ((____ / / // // / / ((____ // """
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', '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 cipher(starttext, shiftamount, cipher_direction):
endtext = ""
if cipher_direction == "decode":
shiftamount *= (-1)
for letter in starttext:
if letter == " ":
endtext += " "
elif letter in alphabet:
position = alphabet.index(letter)
new_position = position + shiftamount
letter = alphabet[new_position]
endtext += letter
else:
endtext += letter
print(f"The {cipher_direction}d result is: {endtext}")
end = False
while not end:
direction = input("Type 'encode' or 'decode' to do whatever you want:\n")
text = input(f"Enter the text you want to {direction}: ")
shift = int(input("Enter the shift amount: "))
shift = shift % 26
cipher(starttext=text, shiftamount=shift, cipher_direction=direction)
restart = input("Do you want to restart the cipher program? Type 'yes' or 'no'.\n")
if restart == "no":
end = True
print("Goodbye")