1
+ letters = ['a' ,'b' ,'c' ,'d' ,'e' ,'f' ,'g' ,'h' ,'i' ,'j' ,'k' ,'l' ,'m' ,'n' ,'o' ,'p' ,'q' ,'r' ,'s' ,'t' ,'u' ,'v' ,'w' ,'x' ,'y' ,'z'
2
+ 'A' ,'B' ,'C' ,'D' ,'E' ,'F' ,'G' ,'H' ,'I' ,'J' ,'K' ,'L' ,'M' ,'N' ,'O' ,'P' ,'Q' ,'R' ,'S' ,'T' ,'U' ,'V' ,'W' ,'X' ,'Y' ,'Z'
3
+ ]
4
+
5
+
6
+ def encryption (plain_message ,shift_key ):
7
+ ciper_text = ""
8
+ for char in plain_message :
9
+ if char in letters :
10
+ position = letters .index (char )
11
+ new_position = (position + shift_key )% 26
12
+ ciper_text += letters [new_position ]
13
+ else :
14
+ ciper_text += char
15
+ print (f"The encrpyted cipher text is: { ciper_text } " )
16
+
17
+ def decryption (cipher_text ,shift_key ):
18
+ plain_message = ""
19
+ for char in cipher_text :
20
+ if char in letters :
21
+ position = letters .index (char )
22
+ new_position = (position - shift_key )% 26
23
+ plain_message += letters [new_position ]
24
+ else :
25
+ plain_message += char
26
+ print (f"The decrpyted cipher text is: { plain_message } " )
27
+
28
+ flag = False
29
+ while not flag :
30
+ en_dn = input ("Type encrypt for encryption, Type decrypt for decryption: \n " )
31
+ message = input ("Enter your Message: \n " ).lower ()
32
+ shift = int (input ("Type shift number: \n " ))
33
+
34
+ if en_dn == "encrypt" :
35
+ encryption (plain_message = message , shift_key = shift )
36
+ elif en_dn == "decrypt" :
37
+ decryption (message , shift )
38
+ play_again = input ("Do you want to play again 'yes' or 'no': " )
39
+ if play_again == 'no' :
40
+ flag = True
41
+ print ("Good bye!!!" )
0 commit comments