Skip to content Skip to sidebar Skip to footer

Caesar Cipher In Python (unexpected Error)

I have to encrypt a user-provided plaintext using Caesar Cipher. Converting each plaintext character to its ASCII (integer) value and store in a list. I have done like this print

Solution 1:

You need to parse the initial characters to numbers, add the key to them and then parse them back to characters.

In your code ascii_list[x] must be changed to ascii_list.append() because you are referencing an index that does not exist. Also plaintext is not a function that you can call, it is just your initial message in uppercase.

You can do this:

for x inrange(len(plaintext)):
    ascii_list.append(chr(ord(plaintext[x]) + n))
print(ascii_list)

Note: The input/output (in:Boiler Up Baby!, out:CWOTFZ&]QCHICa') you provided is not typical Caesar cipher as some of the letters turn into symbols and also the symbols are encoded as well. Using this solution will only shift the keys up, meaning that for example Z will never become A. If you need proper Caesar cipher solution you might want to look at this question: Caesar Cipher Function in Python

Post a Comment for "Caesar Cipher In Python (unexpected Error)"