File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed
Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ # Author: OMKAR PATHAK
2+ # This program illustrates a simple example for encrypting/ decrypting your text
3+
4+ LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5+ LETTERS = LETTERS .lower ()
6+
7+ def main ():
8+ message = str (input ('Enter your message: ' ))
9+ key = int (input ('Enter you key [1 - 26]: ' ))
10+ choice = input ('Encrypt or Decrypt? [E/D]: ' )
11+
12+ if choice .lower ().startswith ('e' ):
13+ print (encrypt (message , key ))
14+ else :
15+ print (decrypt (message , key ))
16+
17+ def encrypt (message , key ):
18+ encrypted = ''
19+ for chars in message :
20+ if chars in LETTERS :
21+ num = LETTERS .find (chars )
22+ num += key
23+ encrypted += LETTERS [num ]
24+ else :
25+ encrypted += symbol
26+
27+ return encrypted
28+
29+ def decrypt (message , key ):
30+ decrypted = ''
31+ for chars in message :
32+ if chars in LETTERS :
33+ num = LETTERS .find (chars )
34+ num -= key
35+ decrypted += LETTERS [num ]
36+ else :
37+ decrypted += symbol
38+
39+ return decrypted
40+
41+ if __name__ == '__main__' :
42+ main ()
43+
44+ # omkarpathak@omkarpathak-Inspiron-3542:~/Documents/GITs/Python-Programs/Programs$ python P40_CipherText.py
45+ # Enter your message: omkar
46+ # Enter you key [1 - 26]: 2
47+ # Encrypt or Decrypt? [E/D]: e
48+ # qomct
49+ #
50+ # omkarpathak@omkarpathak-Inspiron-3542:~/Documents/GITs/Python-Programs/Programs$ python P40_CipherText.py
51+ # Enter your message: qomct
52+ # Enter you key [1 - 26]: 2
53+ # Encrypt or Decrypt? [E/D]: d
54+ # omkar
You can’t perform that action at this time.
0 commit comments