Um, another error, another thread? O.o Well, anyway, here's the code:
import cs50
import sys
if len(sys.argv) == 1 or len(sys.argv) > 2:
print("Usage: python vigenere.py <key>")
exit(1)
key = sys.argv[1]
for i in range(len(key)):
if key[i].isalpha() is not True:
print("Keyword must only contain letters A-Z or a-z")
exit(2)
print("plaintext: ", end="")
plaintext = cs50.get_string()
plaintext_size = len(plaintext)
key_size = len(key)
ciphertext = []
j = 0
for i in range(plaintext_size):
if j >= key_size:
j = 0
if plaintext[i].isalpha():
k = ord(key[j].upper()) % 65
ciphertext = []
c = (ord(ciphertext[i]) + ord(key[i])) % 26
c += ord('A')
ciphertext.append(chr(c))
j += 1
else:
c = ord(plaintext[i])
ciphertext.append(chr(c))
print("ciphertext: ", end="")
print("".join(ciphertext))
exit(0)
The error is on line 28: c = (ord(ciphertext[i]) + ord(key[i])) % 26
, and it says, "IndexError: list index out of range".