hide sourcecode

M

Mark Buch

Hi, is it possible to protect the python sourcecode?
I have a nice little script and i dont want to show everbody the source.

Im using python on a windows pc.

Thank you - Mark
 
L

Larry Bates

You could move the .PY file somewhere where
it cannot be seen and leave the .pyc for execution
or you can "freeze" it with py2exe.

-Larry
 
J

Josiah Carlson

Hi, is it possible to protect the python sourcecode?
I have a nice little script and i dont want to show everbody the source.

Im using python on a windows pc.

Compile the .py file into bytecode (.pyc). That .pyc file will only be
usable on platforms with the same x.y version of Python as you.

Remember that .pyc files suffer from the same decompilation
vulnerabilities as any other programming language (which is why there
exists software cracks). If someone wants to know what you are doing,
they will.

- Josiah

P.S. What kind of script do you have that you want to hide from prying eyes?
 
G

Gerrit

Josiah said:
Compile the .py file into bytecode (.pyc). That .pyc file will only be
usable on platforms with the same x.y version of Python as you.

Remember that .pyc files suffer from the same decompilation
vulnerabilities as any other programming language (which is why there
exists software cracks). If someone wants to know what you are doing,
they will.

I don't know about Windows, but on Unix you can create a script with
permissions 700 and create a small setuid program executing this script.

Don't know whether Windows has such useful things though, probably not :p

Gerrit.
 
J

Josiah Carlson

I don't know about Windows, but on Unix you can create a script with
permissions 700 and create a small setuid program executing this script.

Don't know whether Windows has such useful things though, probably not :p

I've never used setuid, but I would imagine that it works as the name
suggests, it sets the user id of the process. Which would allow you to
run the script with Python, but not read the source.

There is likely a nontrivial set of methods and system calls where a
script could use the 'run as' service in windows to do a similar thing,
but I wouldn't want to write it.

- Josiah
 
A

Anand Pillai

In a lighter vein, why do you want to hide your
python source code? Python is an 'open source' language
so I advise you to share your source code with us :)

-Anand
 
J

Josiah Carlson

Anand said:
In a lighter vein, why do you want to hide your
python source code? Python is an 'open source' language
so I advise you to share your source code with us :)

I'm all about sharing the code, the starter of the thread wanted to hide
it, I was just answering his question.

- Josiah
 
T

Terry Reedy

Simon Wittber said:
source code with us :)

This was preceded by "In a lighter vein, why do you want to hide your
python source code?".
Python is open-source, true. However that does not mean programs written
in Python must be open-sourced. Maybe I am having a bad day,

I think so.
but I read your comment as a mob/peer pressure tactic,

Come now. One person's opinion, written 'in a lighter vein' and concluded
with ':)' is hardly mob pressure, and not even much peer pressure.

In any case, there are a couple of relevant and related points contained in
'Python is open-source'.

On the one hand, Guido intentionally did not GPL Python or put any but the
most obvious and sensible restrictions on its use. In particular, one can
do the following that GPL prohibits: modify the compile and eval functions
to use a different set of op codes and distribute apps using the modified
interpreter without making the source of the modified interpreter
available. (This is not absolute security, but it does make disassembly of
application runtime code harder.)

On the other hand, Guido and the developers, as Python developers,
generally prefer that Python code be potentially and actually shared. So
they are under no obligation and are disinclined to do anything to make
non-sharing easier, not withstanding whatever they may have to do privately
to feed themselves and their families.

Terry J. Reedy
 
A

A. Lloyd Flanagan

Mark Buch said:
Hi, is it possible to protect the python sourcecode?
I have a nice little script and i dont want to show everbody the source.

Im using python on a windows pc.

Thank you - Mark

This comes up every once in a while. If you want to hide your source,
python is probably a bad choice of language -- it's designed to be
easy to understand, and you can probably decompile the byte-code
pretty easily.

Have you considered Perl? The advantage of Perl is, you could share
the source code with anybody you wanted, and be perfectly safe. You
can easily write Perl code that makes no sense at all to anyone but
you :)
 
B

Bernhard Herzog

Ira Baxter said:
One way is to hide the source as obfuscated "cleartext".

As usual Python comes with batteries included:

# -*- coding=rot13 -*-

cevag "uryyb ebg13 jbeyq"



:)

Bernhard
 
M

Mike C. Fletcher

Bernhard Herzog wrote:
....
As usual Python comes with batteries included:

# -*- coding=rot13 -*-

cevag "uryyb ebg13 jbeyq"
cevag h"uryyb ebg13 jbeyq"

Don't you mean?

Nice trick, btw, especially what happens if you include a syntax error
(translated to un-encoded :) ).

Have fun,
Mike

_______________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://members.rogers.com/mcfletch/
 
B

Bernhard Herzog

Mike C. Fletcher said:
Bernhard Herzog wrote:
...

cevag h"uryyb ebg13 jbeyq"

Don't you mean?

Yes. I had played around with that a few months ago and should have
checked the code again before posting.

Bernhard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top