I struck a brick wall trying to solve this and I am not sure how to approach this problem.
My idea is to compare both first characters of each string and if they are the same, save the character in the alphabet string of the index position shift. Recurse the rest of the string by removing the first character of the secret. If the first characters are different, recurse but removing the first character of the alphabet string.
I am not sure how to recurse for the rest of the alphabet though.
alphabet = "abcdefghijklmnopqrstuvwxyz"
def caesar_encrypt(secret, shift):
if len(secret) == 0:
return ""
elif shift == 0:
return secret
else:
if secret[0] == alphabet[0]:
return alphabet[shift] + caesar_encrypt(secret[1:],shift)
else:
return caesar_encrypt(secret,shift), alphabet[1:]