Python: How to encrypt a string of character length n
by an 8 digit key.
My Code so far is below - however it will only encrypt the length of the string up to the 8th digit in key (or key length). I need to reset the key when it comes to it's end and continue for the rest of the string. Really stuck on this one. Any guidance or help would be really appreciated.
def code_char(c,key):
c = ord(c)
if c >= 65 and c <= 90:
c = c + key
if c <= 90:
return chr(c)
while c > 90:
c = c - 26
return chr(c)
elif c >= 97 and c <= 122:
c = c + key
if c <= 122:
return chr(c)
while c > 122:
c = c - 26
return chr(c)
def code_block(word, key):
newWord = ""
for char, num in zip(word, key):
newWord = newWord + code_char(char, int(num))
return newWord
print(code_block('abcdefghijklmn','111111111'))
Thanks for help - should have stated I'm not allowed to use any built in functions for this.