a = input("Enter the msg: ")
key = int(input("Enter the key: "))
ct = []
pt = []
for i in a:
if ord(i) >= 97 and ord(i) <= 122:
d = (((ord(i) + key) - 97) % 26) + 97
ct.append(chr(d))
elif ord(i) >= 62 and ord(i) <= 90:
d = (((ord(i) + key) - 62) % 26) + 62
ct.append(chr(d))
else:
ct.append(i)
print("Encrypted Data")
str1 = ''.join(ct)
print(str1)
for i in ct:
if ord(i) >= 97 and ord(i) <= 122:
d = (((ord(i) - key) - 97) % 26) + 97
pt.append(chr(d))
elif ord(i) >= 62 and ord(i) <= 90:
d = (((ord(i) - key) - 62) % 26) + 62
pt.append(chr(d))
else:
pt.append(i)
print("Decrypted Data")
str2 = ''.join(pt)
print(str2)
Screenshot:
No comments:
Post a Comment