I have written the following code for vigenere.py, but I do not know how to incorporate into my code the idea that after the for loop reaches the final character of the command-line argument, it automatically restarts from the first character of the command-line argument. My current program works only when the plain text and the command-line argument contain exactly the same number of characters, but it does not work when, for instance, the plain text contains more characters than the command-line argument. Any help will be greatly appreciated, thank you!
import cs50
import sys
def main():
if len(sys.argv) != 2:
print("You are wrong: restricted to only one command-line argument!")
return False
if not (sys.argv[1]).isalpha():
print("You are wrong: accept only alphabets!")
return False
plain_text = cs50.get_string()
i = 0
for j in plain_text:
if plain_text.isalpha():
k = sys.argv[1][i]
if (sys.argv[1]).isupper() & plain_text.isupper():
print("{}".format(chr((((ord(j) - 64) + (ord(k) - 64)) % 26) + 64)), end="")
elif (sys.argv[1]).islower() & plain_text.isupper():
print("{}".format(chr((((ord(j) - 64) + (ord(k) - 96)) % 26) + 64)), end="")
elif (sys.argv[1]).isupper() & plain_text.islower():
print("{}".format(chr((((ord(j) - 96) + (ord(k) - 64)) % 26) + 96)), end="")
elif (sys.argv[1]).islower() & plain_text.islower():
print("{}".format(chr((((ord(j) - 96) + (ord(k) - 96)) % 26) + 96)), end="")
i += 1
else:
print("{}".format(j), end="")
print(" ")
if __name__ == "__main__":
main()