-2

So, I recently made a Python program that I want to send to someone with them being able to execute it, but not read the code I have typed in it. Any ideas how to do it?
BTW, I want it to be irreversible
In short, here are my Parameters:

  1. Should remain a Python file
  2. Can't be reversed
  3. Code should not be readable
  4. Should still have the ability to be run
9
  • The best way to achieve something like this would be to package the code into an exe file so that the program is just an executable and not actually source code. The other benefit of this is that the end user won't have to install python to run your code. However, it is key to note, that even exe files can be decompiled into byte code. Even production off the shelf programs can have that done to them. But that's not something the average user knows how to do. Commented Aug 31, 2020 at 16:20
  • Please repeat on topic and how to ask from the intro tour. In particular, we expect you to search for an answer before posting. Commented Aug 31, 2020 at 16:25
  • That's fine, but I want it to be in Python format only Commented Aug 31, 2020 at 16:25
  • 2
    As your newly added criteria do not match stackoverflow.com/questions/3344115/… I've reopened the question. But the short answer is, you can't have all of those. Commented Aug 31, 2020 at 16:32
  • 1
    Yes we are sure. Either you compile to byte code, run it as a service (like @Prune suggested), you let them see the code, or you don't use python. Commented Aug 31, 2020 at 16:43

1 Answer 1

2

The criteria you've posted are inconsistent. Python is an interpreted language. The entity running the language (i.e. Python interpreter) is reading your code and executing it, line by line. If you wrap it up to send to someone, their Python interpreter must have read permissions on the file, whether it's source code or "compiled" Python (which is easily decompiled into equivalent source code).

If we take a wider interpretation of "send to someone", there may be a business solution that serves your needs. You would provide your functionality, rather than the code: deploy it as a service from some available server: your own, or rented space. To do this, you instead provide an interface to your functionality.

If this fulfills your needs, you now have your next research topic.

Sign up to request clarification or add additional context in comments.

5 Comments

So what if I use multiple services to encrypt my .pyc/.py file (basically add multiple layers of encryption)?
I'm not sure what sort of response you want from this. What do you intend to gain? What additional security layers are you implementing in the extra encryption, that you do not get in one? Please clarify the question?
I mean what if I use the in-built compiler to create a .pyc file, and then use an external tool to encrypt the .pyc file further?
"encrypt" covers a lot of ground. I think you're asking me to comment on a design, in which case I need you to explain the full design. How do you deploy the encrypted, pre-compiled file?
No. The compiler takes Python source code as input and produces a pre-compiled intermediate code. That intermediate code is not input format for anything except the Python interpreter. Yes, you could run it through a generic encoder, but then your destination point would have to decode it before execution.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.