When provided text as input string, and rule as input integer, challenge is to find ASCII value sum then convert back to string based on new numeric value.
My code appears on the right track, but given ascii_encrypt("a",1), for example, my current output is b'b' when it should be 'b'. I'm new to the encode function, which I'm guessing is tripping me up.
def ascii_encrypt(text, rule):
text = sum([ord(c) for c in text])
if not text:
return ""
else:
encrypted_text = chr(text + rule)
return encrypted_text.encode('utf-8')
text = sum([ord(c) for c in text]). Do you want to use this function with strings larger than 1 character ?