-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
35 lines (26 loc) · 912 Bytes
/
app.py
File metadata and controls
35 lines (26 loc) · 912 Bytes
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
def caesar_cipher(text, shift, direction):
result = ""
# Direction handling
if direction == "L":
shift = -shift
elif direction == "R":
pass
else:
return "Invalid direction! Use L or R."
for char in text:
if char.isalpha():
base = ord("A") if char.isupper() else ord("a")
result += chr((ord(char) - base + shift) % 26 + base)
else:
result += char
return result
print("Caesar Cipher \n")
message = input("Enter message: ")
shift = int(input("Enter shift key: "))
direction = input("Choose direction (L = Left, R = Right): ").upper()
encrypted = caesar_cipher(message, shift, direction)
print("\nEncrypted Message:", encrypted)
# Decryption uses opposite direction
opposite = "L" if direction == "R" else "R"
decrypted = caesar_cipher(encrypted, shift, opposite)
print("Decrypted Message:", decrypted)