I am trying to create a Caesar Cipher in Python.
I have managed to put together my program with the help of some other websites but have hit a bit of a wall.
My code allows me to encrypt a single character and will then ouput this and write it to a file.
I want to apply this function to work with a block of text. I know I could add a for loop to go through each character but was wondering how I would go about creating another function called encryptText that calls my encryptChar function but iterates through each character not just a single one.
Here is my encryptCharacter function
def encryptCharacter(character, key):
encrypted =''
if character.isalpha():
num = ord(character)
num += key
if character.isupper():
if num > ord('Z'):
num -= 26
elif num < ord('A'):
num += 26
elif character.islower():
if num > ord('z'):
num -= 26
elif num < ord('a'):
num += 26
encrypted+=chr(num)
else:
encrypted+=character
return encrypted