I am in the process of creating a text-based adventure game in Python. The game will not (and has no reason to) access the internet. When creating a save file, I want to securely encrypt and store the file. I would take all the data to be saved, run it through some encryption function, and create a text file storing the output of that encryption function. The file would be stored on the player's local computer storage (hard disk, user documents, user desktop, whatever).
My question is this: is there any way that I can create an encryption function inside the program that virtually uncrackable (whilst being decryptable)? Can any local encryption (even outside of Python) ever be "truly" secure? Just thinking about it/based on my knowledge of cryptography, I would say that it's not possible, but I've been wrong before.
I know that I can create pseudo-cryptography that's essentially obfuscation, but that, very obviously, is quite easy to crack. Also, I understand that most people wouldn't bother to or have the knowledge to edit the save file, but it doesn't take someone with too awfully much knowledge to do what I've stated in the following paragraph (if the individual is motivated enough, which most cheaters are).
The reason I want to encrypt the save file is because without encrypting it, it is so very easy to cheat the game by simply editing the (unencrypted) save file. Even encrypting the file leaves the encryption algorithm in plain sight in the python code; python does not need to be compiled into an executable, so the raw/natural python code is outright for anyone who simply looks at the contents of the game.
I highly doubt that secure encryption such as this is even possible, but if it is, please explain how and, if possible, provide some example Python code for incorporating it into Python (if it's possible for Python).
There is no secure (as in cryptographically secure) way of achieving this. As the comments already say: your program must be able to decrypt the file again, so the knowledge how to decrypt it, must be there.
However, you can raise the bar that cheaters need to cross. The simplest way is to just encode the file instead of encrypting it. This can be base64 or even something simple as gzip. Your users would need to use an extra tool instead of just using a text editor.
Everything else needs your creativity. You might use obfuscated code to obtain the encryption key, like the hash of a python source file, or whatever. A cheater would then need to use a python debugger, which increases the needed knowledge.
But the question remains: If you don't play online, whom are your users going to cheat?
Can encryption/cryptography be secure inside a local, internet-nonaccessing program?