Skip to content

Commit 08e4a46

Browse files
authored
Add files via upload
1 parent 68fcef7 commit 08e4a46

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

caesar-cipher/art.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
logo = """
2+
,adPPYba, ,adPPYYba, ,adPPYba, ,adPPYba, ,adPPYYba, 8b,dPPYba,
3+
a8" "" "" `Y8 a8P_____88 I8[ "" "" `Y8 88P' "Y8
4+
8b ,adPPPPP88 8PP""""""" `"Y8ba, ,adPPPPP88 88
5+
"8a, ,aa 88, ,88 "8b, ,aa aa ]8I 88, ,88 88
6+
`"Ybbd8"' `"8bbdP"Y8 `"Ybbd8"' `"YbbdP"' `"8bbdP"Y8 88
7+
88 88
8+
"" 88
9+
88
10+
,adPPYba, 88 8b,dPPYba, 88,dPPYba, ,adPPYba, 8b,dPPYba,
11+
a8" "" 88 88P' "8a 88P' "8a a8P_____88 88P' "Y8
12+
8b 88 88 d8 88 88 8PP""""""" 88
13+
"8a, ,aa 88 88b, ,a8" 88 88 "8b, ,aa 88
14+
`"Ybbd8"' 88 88`YbbdP"' 88 88 `"Ybbd8"' 88
15+
88
16+
88
17+
"""

caesar-cipher/main.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
alphabet = [
2+
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
3+
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd',
4+
'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
5+
't', 'u', 'v', 'w', 'x', 'y', 'z'
6+
]
7+
8+
9+
def caesar(start_text, shift_amount, cipher_direction):
10+
end_text = ""
11+
if cipher_direction == "decode":
12+
shift_amount *= -1
13+
for char in start_text:
14+
if char in alphabet:
15+
position = alphabet.index(char)
16+
new_position = position + shift_amount
17+
end_text += alphabet[new_position]
18+
else:
19+
end_text += char
20+
21+
print(f"Here's the {cipher_direction}d result: {end_text}")
22+
23+
should_continue = True
24+
while should_continue:
25+
from art import logo
26+
print(logo)
27+
28+
direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n")
29+
text = input("Type your message:\n").lower()
30+
shift = int(input("Type the shift number:\n"))
31+
shift % 27
32+
33+
caesar(start_text=text, shift_amount=shift, cipher_direction=direction)
34+
decision = input("Do you wanna start again? (yes/no)\n")
35+
if decision == "no":
36+
should_continue = False
37+
print("Goodbye")
38+
39+

0 commit comments

Comments
 (0)