File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ print ("🔐 Caesar Cipher Encryptor & Decryptor 🔐" )
2+ print ("Hide your secret messages or reveal them! \n " )
3+
4+ while True :
5+ choice = input ("🎯 Choose Operation: Encrypt (E), Decrypt (D), or Quit (Q): " ).upper ()
6+
7+ if choice in ["Q" , "QUIT" ]:
8+ break
9+
10+ elif choice in ["E" , "D" ]:
11+ message = input ("📝 Enter your message: " )
12+
13+ try :
14+ shift = int (input ("🔑 Enter the shift key (whole number): " ))
15+ except ValueError :
16+ print ("❌ Error: Shift key must be a valid whole number.\n " )
17+ continue
18+
19+ # If decrypting, we just reverse the shift direction
20+ if choice == "D" :
21+ shift = - shift
22+
23+ result = ""
24+
25+ # Core Caesar Cipher Logic
26+ for char in message :
27+ if char .isalpha ():
28+ # Determine ASCII boundary (uppercase vs lowercase)
29+ start = ord ('A' ) if char .isupper () else ord ('a' )
30+
31+ # Shift character and wrap around using modulo 26
32+ shifted_pos = (ord (char ) - start + shift ) % 26
33+ new_char = chr (start + shifted_pos )
34+ result += new_char
35+ else :
36+ # Leave spaces, numbers, and punctuation untouched
37+ result += char
38+
39+ print ("\n ✨ Resulting Message:" )
40+ print (f"👉 { result } \n " )
41+
42+ else :
43+ print ("⚠️ Invalid input. Please type E, D, or Q.\n " )
44+
45+ print ("\n 👋 Thanks for using the Caesar Cipher! Stay secure! 🕵️♂️\n " )
You can’t perform that action at this time.
0 commit comments