For Pset6 Python, Vigenere.py does not encrypt any message with any key. It only prints out the given plaintext, not encrypted. Any help would be greatly appreciated. Thanks in advance.
Code:
#Encrypts a message using vigenere's cipher using a user-given key
from cs50 import get_string
from sys import argv
def main():
#Ensures proper usage
if not len(argv) == 2:
exit("Usage: ./caesar key(purely alphabetical key)")
#Ensures string is alphabetical
key = argv[1]
isalpha = True
for c in key:
if key.isalpha == False:
exit("Usage: ./caesar key(purely alphabetical key)")
#Gets plaintext from user
plaintext = get_string("plaintext: ")
ciphertext = []
k = 0
#Encrypts message
for c in plaintext:
#Encrypts single letter
ciphertext.append(encrypt(c, key[k]))
#Updates which letter of the key is in use
if c.isalpha:
k = (k + 1) % len(key)
#Prints ciphertext
print("ciphertext: ", end = "")
for c in ciphertext:
print(c, end = "")
print()
def encrypt(x, y):
#Proceeds to encrypt only if char is alphabetical
if x.isalpha == True:
isuppur = False
isupper = False
#Checks case of plaintext letter
if x.upper == True:
isuppur = True
#Checks case of key letter
if y.upper == True:
isupper = True
numalpha = ord(x)
alphanum = ord(y)
#Converts both letters to ints
if isuppur == True:
numalpha -= 65
else:
numalpha -= 97
if isupper:
alphanum -= 65
else:
alphanum -= 97
#Applies formula to numalpha to change value
numalpha = (numalpha + alphanum) % 26
#Changes back to ASCII
if isuppur == True:
numalpha += 65
else:
numalpha += 97
#Changes back to char format
z = chr(numalpha)
return z
#Returns given char if isalpha returns false
else:
return x
if __name__ == "__main__":
main()