It is necessary to create a file so that one program writes a random number there and another one can read it, but the problem is that this file could not be opened and changed by the user.

  • eleven
    He will always open it and change it if he wants, regardless of the expansion - andreymal
  • You can even create an extension without an extension, it is not a problem to open it ... and the user can always open and change it, if he really wants to. As a fool proof, you can write there not in an open form, but binary data or even a little bit encrypted. But in the debugger, it is all the same to whom it is necessary, they will find how they are encrypted) - Isaev
  • one
    Someone seems to be trying to invent a named pipe or sockets - KoVadim
  • If one is written down, the other is read, then it would be good to make a key pair and encrypt - eri

1 answer 1

Path 1 try to make your file hidden. On Windows is done somehow

import subprocess subprocess.check_call(["attrib","+H","myfile.txt"]) 

On Linux-like operating systems, you can simply add "." at the beginning of the file.

But in any case, that on Windows that on Linux, the user will be able to edit or view it if he wants.

Path 2 use encryption. The user will see a text that is some kind of garbage and abrucadabra.

 from Crypto.Cipher import AES import base64 text = 'TOP SECRET TEXT'.rjust(32) #текст который мы хотим зашифровать secret_key = 'qwerty'.rjust(32) # пароль cipher = AES.new(secret_key,AES.MODE_ECB) encoded = base64.b64encode(cipher.encrypt(text)) # зашифрованный текст decoded = cipher.decrypt(base64.b64decode(encoded)) # расшифорванный текст 
  • one
    Running an external program to set the file attribute is beyond good and evil. It is better then to write bat-files. - Sergey Gornostaev
  • one
    @SergeyGornostaev yu̶n̶i̶k̶s̶v̶e̶y̶n̶o̶! ̶ - andreymal
  • The user can not encrypt the content. Authentication is required. - MarianD 8:55 pm