Currently, I'm working on a Caesar Cipher program for my Computer Science class. I however don't know how to use user-defined functions in this situation. I keep receiving an UnboundLocalError
#user defined functions
def encrypt(message, distance):
"""Will take message and rotate it the distance, in order to create an encrypted message"""
for ch in message:
ordvalue = ord(ch)
cipherValue = ordvalue + distance
if cipherValue > ord("z"):
cipherValue = ord("a") + distance - (ord("z") - ordvalue + 1)
encryption += chr(cipherValue)
return encryption
#input
message = input("Enter word to be encrypted: ") #original message
distance = int(input("Enter the distance value: ")) #distance letters will be moved
# test
fancy = encrypt(message, distance)
#encryption
print(fancy)