WIP library that will encrypt some text for the purpose of obfuscating my code
Preamble

What you're looking for is a way to obfuscate your code, not a way to encrypt it. The issue lies in the fact that the interpreter needs to have access to the unencrypted source code. This means that you have to store the key somewhere and decrypt the file before runtime, which defeats the purpose of encrypting the source code in the first place. It's almost impossible to properly protect Python code and there's lots of decompilers out there.



There's several better ways to go about doing this:


Use a restrictive (proprietary) license. Be sure to do some research on what license is best, so you know exactly what restrictions and rights people have when using your software.
If you need to interact with a (web)server, try to make as much as possible happen server-side, which, provided you secure your server, prevents people from viewing the source code.
Push frequent, backward-incompatible updates.
Think again and decide you may as well just release it under an open-source license like the MIT license or the GNU GPL.


Your code

Ram Chandra Giri covered most issues with style conventions. I'd like to point out something:


After calling open, one should call close to properly clean up. We may be tempted to do something like this:

f = open(FILENAME, MODE)
# Do stuff with `f`
f.close()


But what if an exception occurs before the close call? So, we have to wrap it in a try: | finally: statement instead:

try:
    f = open(FILENAME, MODE)
    # Do stuff with `f`
finally:
    f.close()


Python provides a cleaner way to do this, using context managers:

with EXPR as VAR:
    BLOCK


In the case of file descriptors, we can use:

with open(FILENAME, MODE) as f:
    # Do something with `f`


Specifically:

with open("save.txt", "r") as f:
    contents = f.read()
    contents = int(contents, 2)
    return contents.to_bytes(
        (contents.bit_length() + 7) // 8,
        'big'
    ).decode()

You can use sys.byteorder to find the system's native byte order. Alternatively if you want to use 'big' as byteorder, I'd make it a constant:

BYTE_ORDER = "big"

If the file is sufficiently large, the system may run out of memory trying to read it all at once. We can avoid this problem by reading 'chunks' into memory.


Here's the same code, but rewritten to implement all changes:

import sys


def write_binary_string(string, filename):
    """Convert `string` to binary and write it to `filename`.

    :param str string: The string to be obfuscated.
    :param str filename: The filename to write to.
    :raises FileNotFoundError: If `filename` is not a file.
    :return: None
    """
    with open(filename, "w") as f:
        binary_representation = bin(int.from_bytes(
            string.encode("utf-8"),
            sys.byteorder
            )
        )
        f.write(binary_representation)


def read_binary_string(filename):
    """Open `filename` and return the deobfuscated contents.

    :param str filename: The file to read from.
    :raises FileNotFoundError: If `filename` is not a file.
    :return: None
    """
    CHUNK_SIZE = 65536
    binary_representation = []
    with open(filename, "r") as f:
        while True:
            chunk = f.read()
            if not chunk:
                break
            binary_representation.append(chunk)
    binary_representation = "".join(binary_representation)
    return int(binary_representation, 2).to_bytes(
        (binary_representation.bit_length()+7) // 8,
        sys.byteorder
    ).decode("utf-8")