Nov-09-2022, 09:21 PM
(This post was last modified: Nov-09-2022, 09:21 PM by deanhystad.)
Did you want to do something like this?
Why did you write a decrypt() function? Look at encrypt() and decrypt() see any similarities? Is there potential for code reuse?
Finally, you can do this:
shift = 10 message = encrypt(input("Message: "), shift) print(message() message = decrypt(message, shift) print(message)When you fix that error you will notice that encrypt and decrypt return empty strings. Inside the functions you are setting message="", so you are encrypting (or decrypting) an empty string regardless of what "message" you pass in.
Why did you write a decrypt() function? Look at encrypt() and decrypt() see any similarities? Is there potential for code reuse?
Finally, you can do this:
if c in alphabet: i = alphabet.index(c) j = (i + shift) % 26 encrypted_message = encrypted_message + alphabet[j] else: encrypted_message = encrypted_message + cBut why when you can do this:
# encrypt c if it is in alphabet, otherwise leave unchanged. if c in alphabet: c = alphabet[(alphabet.index(c) + shift) % len(alphabet)] encrypted_message += cAvoid duplicate code when you can, even if it is as little as "encrypted_message = encrypted_message + "