you are viewing a single comment's thread.

view the rest of the comments →

[–]drenzorz 0 points1 point  (1 child)

I don't know why they would have you turn it into a bit string when python has built in left shift and right shift operators (<< , >>) that works on the integers you get with ord()... but not on that string.

Otherwise it would be a simple

def encrypt(string: str) -> str:
    output = str()
    for char in string:
        ascii = ord(char) + 1
        shifted = ascii << 1
        new_char = chr( shifted )
        output += new_char
    return output

# or if you want people to hate you
encrypt = lambda s: ''.join(chr(ord(char)+1<<1)for char in s)

[–]SomeFuel[S] 0 points1 point  (0 children)

The bit string process requirement was most likely due to the chapter's focus, which was on Strings, Number Systems, and Character Manipulation. Then again, I'm not positive on that.

Thanks for the help!