How do I write a string to a file or socket in Python?
I want to make a one time pad in Python. This example I found on Stack Overflow: def encrypt(pad, secret): return ''.join([chr(ord(c) ^ ord(secret[i])) for i, c in enumerate(pad[:len(secret)])]) I need to write the cipher (what the above function returns) either to a file or TCP/IP connection. When I tried to write the cipher to a file, I got: UnicodeEncodeError: 'charmap' codec can't encode characters in position 6-7: character maps to <undefined> How do I write the cipher to a file or socket with socket.sendall(...)? EDIT I try to use this : def one_time_pad_encode(message: str, key: bytes)
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.