-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
Zelix75
  • 73
  • 1
  • 8
  • 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. – Rashid 'Lee' Ibrahim Aug 31 '20 at 16:20
  • Please repeat [on topic](https://stackoverflow.com/help/on-topic) and [how to ask](https://stackoverflow.com/help/how-to-ask) from the [intro tour](https://stackoverflow.com/tour). In particular, we expect you to search for an answer before posting. – Prune Aug 31 '20 at 16:25
  • That's fine, but I want it to be in Python format only – Zelix75 Aug 31 '20 at 16:25
  • @Prune I have searched, and have not found any answer that fullfils my required parameters – Zelix75 Aug 31 '20 at 16:27
  • 2
    As your newly added criteria do not match https://stackoverflow.com/questions/3344115/how-to-obfuscate-python-code-effectively I've reopened the question. But the short answer is, you can't have all of those. – snakecharmerb Aug 31 '20 at 16:32
  • Are you sure, cuz this project is really important to me – Zelix75 Aug 31 '20 at 16:34
  • 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. – Rashid 'Lee' Ibrahim Aug 31 '20 at 16:43
  • Does this answer your question? [How to obfuscate Python code effectively?](https://stackoverflow.com/questions/3344115/how-to-obfuscate-python-code-effectively) – Peter O. Sep 01 '20 at 00:59
  • No, as it doesn't have the given parameters – Zelix75 Sep 04 '20 at 05:10

1 Answers1

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.

Prune
  • 76,765
  • 14
  • 60
  • 81
  • So what if I use multiple services to encrypt my .pyc/.py file (basically add multiple layers of encryption)? – Zelix75 Aug 31 '20 at 16:50
  • 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? – Prune Aug 31 '20 at 16:52
  • 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? – Zelix75 Aug 31 '20 at 17:00
  • "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? – Prune Aug 31 '20 at 17:03
  • 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. – Prune Aug 31 '20 at 21:40