forked from souravjain540/Basic-Python-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencryption_text.py
More file actions
40 lines (35 loc) · 1.3 KB
/
encryption_text.py
File metadata and controls
40 lines (35 loc) · 1.3 KB
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
def encrypt(message, key):
encrypted_message = ''
for alphabet in message:
if alphabet.isalpha():
encrypted_message += chr(ord(alphabet) - key)
else:
encrypted_message += alphabet
return encrypted_message
def decrypt(encrypted_message, key):
decrypted_message = ''
for alphabet in encrypted_message:
if alphabet.isalpha():
decrypted_message += chr(ord(alphabet) + key)
else:
decrypted_message += alphabet
print('Decrypted Message:', decrypted_message)
def main():
print("Hello Anonymous, you can encrypt or decrypt a message.")
try:
choice = int(input('Enter 1 for encryption or 0 for decryption: '))
if choice == 1:
message = input('Enter any string value: ')
key = int(input('Enter the shift value: '))
encrypted_result = encrypt(message, key)
print('Encrypted Message:', encrypted_result)
if choice ==0:
encrypted_message = input('Enter the encrypted message: ')
key = int(input('Enter the shift value: '))
decrypt(encrypted_message, key)
else:
print('please enter valid value')
except ValueError:
print('ERROR !!!!!!!!!!!!! please enter only integer 1 and 0')
if __name__ == "__main__":
main()