How do I use keygen?

I have received several questions in office hours about how keygen is used. keygen is a helper function for generating valid keys for your subst_encrypt and subst_decrypt functions. You should not use keygen within the subst_encrypt and subst_decrypt functions. Instead, as shown in the lab examples, both of those functions take the key, generated previously by keygen, as a parameter. For example:

key = keygen("mypassword")
encrypted = subst_encrypt("this is a secret message", key)
decrypted = subst_decrypt(encrypted, key)
print(decrypted)

Notice that the key produced by keygen is used as the second parameter to both subst_encrypt and subst_decrypt. More specifically, your code should produce the exact same output as below, that is given a string and a key, your function should be able to encrypt or decrypt the message (without using keygen):

>>> subst_encrypt("this is a secret message", "jf rdesquztkwhoipcbamlvxgny")
'aqubyubyjybd cdaywdbbjsd'
>>> subst_decrypt("aqubyubyjybd cdaywdbbjsd", "jf rdesquztkwhoipcbamlvxgny")
'this is a secret message'