-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncryptionDecryption.py
More file actions
41 lines (40 loc) · 1.12 KB
/
Copy pathEncryptionDecryption.py
File metadata and controls
41 lines (40 loc) · 1.12 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
41
#encryption and decryption of a message
#Encryption of a message
import string as srr
def EncryptM(s,key):
if(len(s)<=0):
print("Message length is too short foe Encryption ...")
return
elif (len(str(key))<4):
print("Pass-Key is too short")
return
else:
li=[]
# adding pass-key with every character
for i in range(0,len(s)):
a = chr(ord(s[i])+key)
li.append(a)
s=""
for i in range(0,len(li)):
s=s+li[i]
del li
return(s)
#Decryption of a message
def DecryptM(s,key):
li=[]
# adding pass-key with every character
for i in range(0,len(s)):
a = chr(ord(s[i])-key)
li.append(a)
s=""
for i in range(0,len(li)):
s=s+li[i]
del li
return(s)
#for take message from user with a pass-key of minimum length 4
m = str(input("Enter your message here :\n"))
k = int(input("enter a pass-key : "))
m = EncryptM(m,k)
D_m = DecryptM(m,k)
print("Encrypted message is :\n",m)
print("according to your key the Decrypted message is :\n",D_m)