-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractical4.py
More file actions
33 lines (33 loc) · 992 Bytes
/
practical4.py
File metadata and controls
33 lines (33 loc) · 992 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
def Encryption(s,k):
encstr=""
for i in s:
if(ord(i))>=65 and (ord(i)<=90):
temp=(ord(i)+k)
if temp>90:
temp=temp%90+64
encstr=encstr+chr(temp)
elif(ord(i))>=97 and (ord(i)<=122):
temp=(ord(i)+k)
if temp>122:
temp=temp%122+96
encstr=encstr+chr(temp)
else:
encstr=encstr+chr(ord(i)+k)
return encstr
def Decryption(k):
p=Encryption(s,k)
decstr=""
for i in p:
if((ord(i))>=65) and (ord(i))<=90:
decstr=decstr+chr((ord(i) - k-65) % 26 + 65)
elif((ord(i))>=97) and (ord(i))<=122:
decstr=decstr+chr((ord(i) - k - 97) % 26 + 97)
else:
decstr=decstr+chr(ord(i)-k)
return decstr
print("Enter the string to Encrypt and decrypt : ")
s=input()
k=9
k=k%26
print("Encrypted String : ",Encryption(s,k))
print("Decrypted String : ",Decryption(k))