Caesar password questions

Asked 2 years ago, Updated 2 years ago, 15 views

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

2022-09-20 20:00

1 Answers

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)


2022-09-20 20:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.