-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaesar.py
50 lines (36 loc) · 1.47 KB
/
caesar.py
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
#!/usr/bin/env python3
import os
import pyperclip
os.system('cls' if os.name == 'nt' else 'clear')
# The string to be encrypted/decrypted.
message = input("[>] Enter a message: ")
key = 13 # The encryption/decryption key.
# Tells the program to encrypt or decrypt.
mode = 'encrypt' # Set to 'encrypt' or 'decrypt'.
# Every possible symbol that can be encrypted.
alphabet = 'abcdefghijklmnopqrstuvwyzABCDEFGHIJKLMNOPQRSTUVWYZ'
translated = '' # Stores the encrypted/decrypted form of the message.
#message = message.upper() # Capitalize the string in message.
for symbol in message:
if symbol in alphabet:
# Get the encrypted (or decrypted) number for this symbol.
num = alphabet.find(symbol) # Get the number of the symbol.
if mode == 'encrypt':
num = num + key
elif mode == 'decrypt':
num = num - key
# Alphabet of less than 0
if num >= len(alphabet):
num = num - len(alphabet)
elif num < 0:
num = num + len(alphabet)
# Add encrypted/decrypted number's symbol at the end of translated.
translated = translated + alphabet[num]
else:
# Just add the symbol without encryting/decrypting.
translated = translated + symbol
print('\033[92m[*] Original Text : \033[0m',message)
print('\033[92m[+] Cipher Text : \033[0m',translated)
# Copy the encrypted/decrypted string to the clipboard.
pyperclip.copy(translated)
quit()