Skip to content

Commit 9b2ae27

Browse files
committed
Added new features
1 parent ca8ff3d commit 9b2ae27

File tree

5 files changed

+112
-42
lines changed

5 files changed

+112
-42
lines changed
741 Bytes
Binary file not shown.
549 Bytes
Binary file not shown.

caesar_cipher.py

Lines changed: 58 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,61 @@
11
#Caeser Cipher Algorithm for encryption and decryption
22

3-
def caesar_encryption(plaintext, key):
4-
encrypted_str = ""
5-
for i in plaintext:
6-
if i.isupper():
7-
uni_value = 65 + ((ord(i) - 65 + key) % 26)
8-
encrypted_str = encrypted_str + chr(uni_value)
9-
elif i.islower():
10-
uni_value = 97 + ((ord(i) - 97 + key) % 26)
11-
encrypted_str = encrypted_str + chr(uni_value)
12-
else:
13-
encrypted_str = encrypted_str + i
3+
import caesar_encryption, caesar_decryption
4+
import time
5+
import sys
6+
7+
def decor(func):
8+
def wrap():
9+
print("[=======================================]")
10+
func()
11+
print("\n[=======================================]")
12+
return wrap
13+
14+
@decor
15+
def display():
16+
print(" CAESAR CIPHER ALGORITHM")
17+
18+
display()
19+
20+
time.sleep(0.5)
21+
22+
print("Hello there! What can i help you with?")
23+
time.sleep(1)
24+
print("\n1. Encryption")
25+
time.sleep(0.3)
26+
print("2. Decryption\n")
27+
time.sleep(1)
28+
29+
option = input("Input an option: ")
30+
31+
if option == '1':
32+
plaintext = input("Enter the text: ")
33+
key = int(input("Enter the key: "))
1434

15-
print("The encrypted text is:", encrypted_str)
16-
17-
plaintext = input("Enter the text: ")
18-
key = int(input("Enter the key: "))
19-
caesar_encryption(plaintext, key)
20-
21-
def caesar_decryption(ciphertext, key):
22-
decrypted_str = ""
23-
for i in ciphertext:
24-
if i.isupper():
25-
if (ord(i) - 65 - key) < 0:
26-
uni_value = 65 + ((ord(i) - 65 - key) + 26) % 26
27-
decrypted_str = decrypted_str + chr(uni_value)
28-
else:
29-
uni_value = 65 + (ord(i) - 65 - key) % 26
30-
decrypted_str = decrypted_str + chr(uni_value)
31-
elif i.islower():
32-
if (ord(i) - 97 - key) < 0:
33-
uni_value = 97 + ((ord(i) - 97 - key) + 26) % 26
34-
decrypted_str = decrypted_str + chr(uni_value)
35-
else:
36-
uni_value = 97 + (ord(i) - 97 - key) % 26
37-
decrypted_str = decrypted_str + chr(uni_value)
38-
else:
39-
decrypted_str = decrypted_str + i
40-
41-
print("The decrypted text is:", decrypted_str)
42-
43-
ciphertext = input("Enter the encrypted text: ")
44-
key = int(input("Enter the key:"))
45-
caesar_decryption(ciphertext, key)
35+
for i in 'Encrypting....':
36+
sys.stdout.write(i)
37+
sys.stdout.flush()
38+
time.sleep(0.3)
39+
print()
40+
41+
for j in '..............':
42+
sys.stdout.write(j)
43+
sys.stdout.flush()
44+
time.sleep(0.3)
45+
print()
46+
47+
for k in 'Almost there....':
48+
sys.stdout.write(k)
49+
sys.stdout.flush()
50+
time.sleep(0.3)
51+
print('\n')
52+
53+
caesar_encryption.caesar_encryption(plaintext, key)
54+
55+
elif option == '2':
56+
ciphertext = input("Enter the encrypted text: ")
57+
key = int(input("Enter the key:"))
58+
caesar_decryption.caesar_decryption(ciphertext, key)
59+
60+
else:
61+
print("invalid option")

caesar_decryption.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#Decryption algorithm
2+
import time
3+
4+
def caesar_decryption(ciphertext, key):
5+
decrypted_str = ""
6+
#welcome to caesar cipher decryptor
7+
for i in ciphertext:
8+
9+
if i.isupper():
10+
11+
if (ord(i) - 65 - key) < 0:
12+
uni_value = 65 + ((ord(i) - 65 - key) + 26) % 26
13+
decrypted_str = decrypted_str + chr(uni_value)
14+
15+
else:
16+
uni_value = 65 + (ord(i) - 65 - key) % 26
17+
decrypted_str = decrypted_str + chr(uni_value)
18+
19+
elif i.islower():
20+
21+
if (ord(i) - 97 - key) < 0:
22+
uni_value = 97 + ((ord(i) - 97 - key) + 26) % 26
23+
decrypted_str = decrypted_str + chr(uni_value)
24+
25+
else:
26+
uni_value = 97 + (ord(i) - 97 - key) % 26
27+
decrypted_str = decrypted_str + chr(uni_value)
28+
29+
else:
30+
decrypted_str = decrypted_str + i
31+
32+
time.sleep(1)
33+
print("The decrypted text is:", decrypted_str)

caesar_encryption.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#Encryption algorithm
2+
import time
3+
4+
def caesar_encryption(plaintext, key):
5+
encrypted_str = ""
6+
#welcome to caeser cipher encryptor
7+
for i in plaintext:
8+
9+
if i.isupper():
10+
uni_value = 65 + ((ord(i) - 65 + key) % 26)
11+
encrypted_str = encrypted_str + chr(uni_value)
12+
13+
elif i.islower():
14+
uni_value = 97 + ((ord(i) - 97 + key) % 26)
15+
encrypted_str = encrypted_str + chr(uni_value)
16+
17+
else:
18+
encrypted_str = encrypted_str + i
19+
20+
time.sleep(1)
21+
print("The encrypted text is:", encrypted_str)

0 commit comments

Comments
 (0)