1

I would like to store some information for a game I'm making in python using text files. Some of the information stored shouldn't be changeable for the user. Is there any easy way to make the files unopenable/unreadable for a user, however it would still be saved in the same directory. (Preferably without the use of external libraries, however if that is the easiest or only way then that's fine)

2 Answers2

5

This might help: You'd need to make the files not readable for users other than you, so the mode should probably be 0o700.

import os
os.chmod(path, 0o700)

Alternatively, you can also use chmod with a terminal: chmod 700 path/to/your/file.

aleph-null
  • 443
  • 4
  • 11
  • Please don't paste links only answers. They have a tendency to die making them unusable for future readers. Instead include the information, and link for further reading if you feel it adds value. Thanks :) – Nathan Jul 27 '20 at 22:34
  • 2
    Oh, it's a StackOverflow link itself, are those acceptable to paste in answers? Taking the contents from it seems redundant, but I could well be wrong. – aleph-null Jul 27 '20 at 22:36
  • you're right that in this case, it's probably ok. I figured since you're new to the site it would be best to give you a heads up for future answers :) – Nathan Jul 27 '20 at 22:37
  • @aleph-null Hi, thanks that worked fine. Only thing is I had to put `0o` in front of it as it was an octal integer (or that's what the error said). Also, 0400 worked in the same way (or at least how I checked if it worked), but thanks either way. – Johnny Peacock Jul 27 '20 at 23:53
  • Ah sorry, yeah that makes sense. It’s intended as an octal integer: 4 is read, 2 is write, and 1 is execute, and their sum determines the permission granted for that group. – aleph-null Jul 27 '20 at 23:59
  • @aleph-null Sorry I didn't see that you put `0o` in front in your original answer I just misread it – Johnny Peacock Jul 28 '20 at 14:31
  • I hadn’t, was an edit after your comment. Thanks for said comment, by the way. – aleph-null Jul 28 '20 at 14:45
  • @aleph-null Ahh ok, makes sense. Thanks for your help though – Johnny Peacock Jul 28 '20 at 14:51
0

You can't make the file unopenable or unreadable its the users computer so they can do whatever they want.
however, I have an Idea, but it won't stop a smart one
use Ceaser Cipher also called Shift cipher
This vid Will How to Use the Caesar (Shift) Cipher
simply it is swapping letter with another, like

if your file is like

{
"name","Joe"
}

apply a ceaser cipher with key = 6,you will get

{
"tgsk","Puk"
}

however if he is smart, its likely he is gonna be able to decrypt it easily and know the key
at the end its their computer they can do whatever they like with you file

White Death
  • 408
  • 5
  • 12