I am writing a code that will encrypt a list of String entered by user. these lists will be encrypted and then it will be decrypted. But once it will reach the part of encryption it gives me this error.
Traceback (most recent call last): File "C:/Users/dana/Desktop/q2.py", line 16, in x = ord(c) TypeError: ord() expected a character, but string of length 4 found
I am sure that it will give the same error even in the decryption part.
This is my code:
# Encryption
list1=[]
list2=[]
i = 0
while not(False):
plain_text = input ("Enter any string ")
if (plain_text !='q'):
list1.append(plain_text)
i=i+1
else:
break
encrypted_text = ""
for c in list1:
x = ord(c)
x = x + 1
c2 = chr(x)
encrypted_text = encrypted_text + c2
print(encrypted_text)
#Decryption
encrypted_text = "Uijt!jt!b!uftu/!BCD!bcd"
plain_text = ""
for c in encrypted_text:
x = ord(c)
x = x - 1
c2 = chr(x)
plain_text = plain_text + c2
print(plain_text)
list2=[encrypted_text]
print(plain_text)
print("the original msgs are :" , list1)
print("the encrypted msgs are :" ,list2)