I've pretty much gotten my program to work 90% successfully! But, it does not produce the correct outcome for mix case or spaces/symbols. I've tried a number of different methods to no avail. At the moment, when I have mix case I get a blank ciphertext output. In any instance of space/symbols, my last print statement produces something such as this:
~/workspace/pset6/ $ python caesar.py 12
plaintext: why not
ciphertext: wwhwhywhy why nwhy nowhy not
Here is my current code:
from cs50 import get_string
import cs50
import sys
import string
while True:
# convert string into integer
key = int(sys.argv[1])
# if index is greater than 0 and has 2 arguments move to the next step
if key > 0 and len(sys.argv) == 2:
break
# print error if not
else:
print("Error-- must have 2 arguments and sys.argv[1] must be a positive integer")
exit(0)
# get plaintext input from user
print("plaintext: ", end="")
plaintext = cs50.get_string()
i = 0
c = ""
print("ciphertext: ", end="")
for i in plaintext:
n = ord(i) + key
if plaintext.isupper():
c = ((n -65) % 26 + 65)
print(chr(c), end="")
elif plaintext.islower():
c = ((n -97) % 26 + 97)
print(chr(c), end="")
else:
c = c + i
print(c, end="")
print()