-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP40_CipherText.py
53 lines (41 loc) · 1.34 KB
/
P40_CipherText.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
51
52
53
# Author: AKHILESH
# This program illustrates a simple example for encrypting/ decrypting your text
LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
LETTERS = LETTERS.lower()
def encrypt(message, key):
''' This function lets you to encrypt your message based on a key '''
encrypted = ''
for chars in message:
if chars in LETTERS:
num = LETTERS.find(chars)
num += key
encrypted += LETTERS[num]
return encrypted
def decrypt(message, key):
''' This function lets you to decrypt your message based on a key '''
decrypted = ''
for chars in message:
if chars in LETTERS:
num = LETTERS.find(chars)
num -= key
decrypted += LETTERS[num]
return decrypted
def main():
message = str(input('Enter your message: '))
key = int(input('Enter you key [1 - 26]: '))
choice = input('Encrypt or Decrypt? [E/D]: ')
if choice.lower().startswith('e'):
print(encrypt(message, key))
else:
print(decrypt(message, key))
if __name__ == '__main__':
main()
# OUTPUT:
# Enter your message: akhilesh
# Enter you key [1 - 26]: 3
# Encrypt or Decrypt? [E/D]: e
# dnklohvk
# Enter your message: dnklohvk
# Enter you key [1 - 26]: 3
# Encrypt or Decrypt? [E/D]: d
# akhilesh