-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_Encryption__Decryption_project_cs.py
More file actions
58 lines (42 loc) · 1.45 KB
/
_Encryption__Decryption_project_cs.py
File metadata and controls
58 lines (42 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
Project Name: _Encryption__Decryption_project_cs
Title: Caesar Cipher Encryption & Decryption
Description: A program to encrypt and decrypt text using Caesar Cipher algorithm.
Author: Deeksha P
"""
def encrypt(text, shift):
encrypted_text = ""
for char in text:
if char.isalpha():
ascii_offset = 65 if char.isupper() else 97
shifted = (ord(char) - ascii_offset + shift) % 26
encrypted_text += chr(shifted + ascii_offset)
else:
encrypted_text += char
return encrypted_text
def decrypt(text, shift):
return encrypt(text, -shift)
def main():
while True:
print("\n========== SCT_CS_1 ==========")
print("1. Encrypt")
print("2. Decrypt")
print("3. Exit")
choice = input("Enter your choice (1/2/3): ")
if choice == "3":
print("Exiting program...")
break
message = input("Enter your message: ")
try:
shift = int(input("Enter shift value: "))
except ValueError:
print("Shift must be a number!")
continue
if choice == "1":
print("Encrypted Message:", encrypt(message, shift))
elif choice == "2":
print("Decrypted Message:", decrypt(message, shift))
else:
print("Invalid choice! Please try again.")
if __name__ == "__main__":
main()