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 ("\n 1. 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" )
0 commit comments