0

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("This program uses a Caesar Cipher to encrypt a plaintext message using the encryption key you provide.")
plaintext = input("Enter the message to be encrypted:")
plaintext = plaintext.upper()
n = eval(input("Enter an integer for an encrytion key:"))
ascii_list = []

# encipher
ciphertext = ""
for x in range(len(plaintext)):
    ascii_list[x] = plaintext (ascii_list) + n %26
    print()

But error appears as like this:

   TypeError: 'str' object is not callable

I want the result to come out:

This program uses a Caesar Cipher to encrypt a plaintext message using the encryption key you provide.
Enter the message to be encrypted: Boiler Up Baby!
Enter an integer for an encrytion key: 1868
The fully encoded message is: CWOTFZ&]QCHICa'

I have tried so many different ways but the result does not come out.

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52
Hee Ra Choi
  • 113
  • 1
  • 1
  • 10

1 Answers1

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 in range(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

DobromirM
  • 2,017
  • 2
  • 20
  • 29