-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCryptography_System.py
More file actions
35 lines (28 loc) · 896 Bytes
/
Cryptography_System.py
File metadata and controls
35 lines (28 loc) · 896 Bytes
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
LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'
LETTERS = LETTERS.lower()
def encrypt(message, 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):
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()