-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaesar_cipher_tool.py
More file actions
77 lines (68 loc) · 2.85 KB
/
caesar_cipher_tool.py
File metadata and controls
77 lines (68 loc) · 2.85 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import pyfiglet
from termcolor import colored
# Function to encrypt using Caesar Cipher
def caesar_encrypt(plaintext, shift):
encrypted_text = ''
for char in plaintext:
if char.isalpha():
shift_base = ord('a') if char.islower() else ord('A')
new_char = chr((ord(char) - shift_base + shift) % 26 + shift_base)
encrypted_text += new_char
else:
encrypted_text += char
return encrypted_text
# Function to decrypt using Caesar Cipher
def caesar_decrypt(ciphertext, shift):
decrypted_text = ''
for char in ciphertext:
if char.isalpha():
shift_base = ord('a') if char.islower() else ord('A')
new_char = chr((ord(char) - shift_base - shift) % 26 + shift_base)
decrypted_text += new_char
else:
decrypted_text += char
return decrypted_text
# ASCII Banner
def print_banner():
banner = pyfiglet.figlet_format("Cipher Toolkit", font="slant") # You can change font here
print(colored(banner, "cyan"))
print(colored("Developed by n4it40_07", "yellow"))
print("=" * 60)
# Caesar Brute-force Mode
def brute_force_mode(text):
print(colored("Brute Force Results (All 26 Shifts):", "magenta"))
print("-" * 50)
for shift in range(0, 26): # Include shift 0
result = caesar_decrypt(text, shift)
print(colored(f"Shift {str(shift).rjust(2)}: ", "yellow") + colored(result, "blue"))
# Main Menu
def main():
while True:
print_banner()
print(colored("Choose an option:", "green"))
print(colored("[1] Encrypt", "cyan"))
print(colored("[2] Decrypt", "cyan"))
print(colored("[3] Brute Force Decryption", "cyan"))
print(colored("[4] Exit", "red"))
choice = input(colored("Enter your choice: ", "yellow")).strip()
if choice == '1':
text = input(colored("Enter plaintext to encrypt: ", "green"))
shift = int(input(colored("Enter shift (0-25): ", "green")))
result = caesar_encrypt(text, shift)
print(colored("Encrypted Text:", "magenta"), colored(result, "blue"))
elif choice == '2':
text = input(colored("Enter ciphertext to decrypt: ", "green"))
shift = int(input(colored("Enter shift (0-25): ", "green")))
result = caesar_decrypt(text, shift)
print(colored("Decrypted Text:", "magenta"), colored(result, "blue"))
elif choice == '3':
text = input(colored("Enter ciphertext for brute force: ", "green"))
brute_force_mode(text)
elif choice == '4':
print(colored("Exiting... Thank you for using Cipher Toolkit!", "red"))
break
else:
print(colored("Invalid choice. Please try again.", "red"))
input(colored("\nPress Enter to continue...", "white"))
if __name__ == "__main__":
main()