Here are five riddles written in Caesar's code. First, use a function that can decrypt Caesar's code to find out how many letters each riddle question is pushed back, then interpret what it originally means, and think of the right answer to the question and express it in Caesar's code.
The error here is
Code is
defx(code, shift): #recover
result = ""
a=97
z=122
for i in code:
if i==" ":
result +=1
else:
change = ord(i)-shift
result += chr(change)
return result
def er(code,shift):
result = ""
m=97
e=122
code=code.lower()
for i in code:
if i==" ":
result +=1
else:
change = ord(i)-shift
return result
d = input("Input :").lower()
s = int(input("shift number:"))
p=x(d,s)
t=er(d,s)
print ('encryption :'+p)
print('decryption :'+t)
This is.
python
def casesar_encrypt(code, shift):
result = ""
a = 97
z = 122
for i in code:
if i == " ":
#result += 1
#I don't know what the conditions are,
#Assume that spacing is printed as it is
result += " "
else:
#change = ord(i)-shift
change = ord(i) + shift
#Caesar encryption is basically replaced by + when encrypting
if change > z:
change = change - z + a - 1
#ascii code If you move to a value of a~z or higher in the table,
#Must go back to a.
result += chr(change)
return result
#Only one return statement was encrypted because the previous return statement was in the for statement.
def caesar_decrypt(code,shift):
result = ""
a = 97
z = 122
code=code.lower()
for i in code:
if i == " ":
#result += 1
result += " "
else:
change = ord(i) - shift
if change < a:
change = change + z - a + 1
result += chr(change)
#This is missing
return result
d = input("Input :").lower()
s = int(input("shift number:"))
p = caesar_encrypt(d,s)
print ('encryption :'+p)
t = caesar_decrypt(p,s)
print('decryption :'+t)
© 2024 OneMinuteCode. All rights reserved.