please guys i am really stuck, first of i have a question as to how to debug python code. like the debug50. and my second is with my code for vigenere.
import cs50
import sys
def main():
# make sure the user gives the right parameters
if len(sys.argv) != 2:
print("python caesar.py key")
exit(1)
# make sure the input are valid alabetical characters
if sys.argv[1].isalpha() == False:
print("plase provide valid input")
exit(2)
# prompt the user for text to be ciphered
print("plaintext: ", end="")
plaintext = cs50.get_string()
print("ciphertext: ", end="")
# prepare to do the ciphering
key_index = 0
key_len = len(sys.argv[1])
ciphertext = []
# loop and cipher
for characters in plaintext:
if characters.isalpha():
key_index = key_index % key_len
ciphertext.append(cipher_this(characters, key_index))
else:
ciphertext.append(characters)
# print the final solution
print("".join(ciphertext))
def cipher_this(char, key):
if char.isupper():
return chr(((ord(char) - 65 + key - 65) % 26) + 65)
key+=key
elif char.islower():
return chr(((ord(char) - 97 + key - 97) % 26) + 97)
key+=key
if __name__=="__main__":
main()
i cannot figure out what is going on with my code. please any help would be great. specifically how do i get at the i'th index of the key with python. i feel like C, i know i sound crazy saying this, is wayyy easier when it comes to getting at the index of the key, but i am so confused about this one. thanks for the help in advanced