473,724 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

hide python code !

hi
can we hide a python code ?
if i want to write a commercial software can i hide my source code from
users access ?
we can conver it to pyc but this file can decompiled ... so ...!!
do you have any idea about this ...?

---------------------------------------
First Iranian Open Source Community : www.python.ir

Aug 10 '06 #1
64 7536

Bayazee wrote:
hi
can we hide a python code ?
if i want to write a commercial software can i hide my source code from
^^^^^^^^^^^^^^^ ^^^^^^^^^[1]
users access ?
we can conver it to pyc but this file can decompiled ... so ...!!
do you have any idea about this ...?

---------------------------------------
First Iranian Open Source Community : www.python.ir
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^[2]
[1] and [2] don't seem to be compatible.

Really the only way to keep your code secret is not to distribute it --
provide the functionality from a web server.

If you want to distribute obfuscated code, consider writing it in perl
:-)

Aug 10 '06 #2
hi
in compiled languages when we compile a code to an executable file it
convert to a machine code so now we cant access to source ...
but in python we easily open the program executable(asci i) file and
read source ....
i meen than any way to protect my code or convert it to executable
witch can not be decompiled (python code)....

Aug 10 '06 #3

Bayazee wrote:
hi
in compiled languages when we compile a code to an executable file it
convert to a machine code so now we cant access to source ...
but in python we easily open the program executable(asci i) file and
read source ....
i meen than any way to protect my code or convert it to executable
witch can not be decompiled (python code)....
I know what you mean.

However consider this: There is no such thing as an executable which
cannot be decompiled; if the code can be executed, then anybody with
read access to the code can disassemble/decompile/whatever it -- there
is no theoretical difference between disassembling an .exe file and
decompiling a .pyc file. What's in a .pyc file is just the machine code
for a virtual machine ...

Consider changing your business plan: write crappy software, charge
heaps for support -- it's not a novel idea :-)

Aug 11 '06 #4
On Thu, 10 Aug 2006 17:03:51 -0700, Bayazee wrote:
hi
in compiled languages when we compile a code to an executable file it
convert to a machine code so now we cant access to source ...
There are disassemblers for machine code. If somebody really wants to see
how your code works, they can do it.
but in python we easily open the program executable(asci i) file and read
source ....
Yes. That is by design.
i meen than any way to protect my code or convert it to executable witch
can not be decompiled (python code)....
In your first email, you wrote:

"First Iranian Open Source Community : www.python.ir"

Hiding source code is incompatible with Open Source software. You can hide
code, or be Open Source, but not both.

What makes you think that your code is so special that it is worth
stealing? Do you have incredible secret algorithms that nobody has ever
seen before? Or are you just so ashamed of it that you don't want people
to see it?

Or maybe you've copied other people's code, and you don't want them to see
that? What are you hiding?

Whatever your reasons for hiding the source code, there are things which
you can do to obfuscate Python code which will make it difficult for
people to get to the source code. Google for "python obfuscate" for links.
But I'm guessing that, if you hide your source code, most people will
wonder what you are hiding and avoid your program.

If you really want something which compiles to machine code, then Python
is not the language for you. Use another language.

--
Steven D'Aprano

Aug 11 '06 #5
I don't think you're the first person that has wondered about this. But
you might have some options:

1. If you are running it on Windows only, use py2exe to wrap it up as
an executable.
2. I've never done this, but you might be able to encrypt or otherwise
turn you modules into binary form, and then use a clever import hook. I
know zipimport in the standard lib gives you more control over
importing zip files, but I don't think it can handle encrypted ones.
3. Write a custom module importer in C using Python's API so you can
encrypt your modules any way you want as long as you know how to use C
to decrypt them again.

There's probably a thousand other ways if you're clever enough (e.g.
write it in Jython and package it as .jar files). As long as your
program sticks closer to pure Python, the easier it will be. If you're
using a lot of open source modules to help you out, you might want to
double-check their licensing to see if what you're doing is allowed
anyway.
Bayazee wrote:
hi
can we hide a python code ?
if i want to write a commercial software can i hide my source code from
users access ?
we can conver it to pyc but this file can decompiled ... so ...!!
do you have any idea about this ...?

---------------------------------------
First Iranian Open Source Community : www.python.ir
Aug 11 '06 #6
Bayazee wrote:
hi
in compiled languages when we compile a code to an executable file it
convert to a machine code so now we cant access to source ...
It can still be disassembled and reverse engineered.
but in python we easily open the program executable(asci i) file and
read source ....
i meen than any way to protect my code or convert it to executable
witch can not be decompiled (python code)....
How do you reconcile this desire with being part of "First Iranian Open
Source Community"?

I am not hostile, just curious.
BTW, John Machin's suggestion of presenting your code as a web service
is a good one.

Peace,
~Simon

Aug 11 '06 #7
In article <pa************ *************** *@REMOVEME.cybe rsource.com.au> ,
Steven D'Aprano <st***@REMOVEME .cybersource.co m.auwrote:
>On Thu, 10 Aug 2006 17:03:51 -0700, Bayazee wrote:
>hi
in compiled languages when we compile a code to an executable file it
convert to a machine code so now we cant access to source ...

There are disassemblers for machine code. If somebody really wants to see
how your code works, they can do it.
>but in python we easily open the program executable(asci i) file and read
source ....

Yes. That is by design.
>i meen than any way to protect my code or convert it to executable witch
can not be decompiled (python code)....

In your first email, you wrote:

"First Iranian Open Source Community : www.python.ir"

Hiding source code is incompatible with Open Source software. You can hide
code, or be Open Source, but not both.

What makes you think that your code is so special that it is worth
stealing? Do you have incredible secret algorithms that nobody has ever
seen before? Or are you just so ashamed of it that you don't want people
to see it?

Or maybe you've copied other people's code, and you don't want them to see
that? What are you hiding?

Whatever your reasons for hiding the source code, there are things which
you can do to obfuscate Python code which will make it difficult for
people to get to the source code. Google for "python obfuscate" for links.
But I'm guessing that, if you hide your source code, most people will
wonder what you are hiding and avoid your program.

If you really want something which compiles to machine code, then Python
is not the language for you. Use another language.
Aug 11 '06 #8
"Bayazee" <ba*****@gmail. comwrites:
can we hide a python code ?
Sure; don't distribute it to anyone. Then they can't run the program
or inspect it or anything.
if i want to write a commercial software can i hide my source code
from users access ?
You can write commercial software and sell it without hiding the
source code.
we can conver it to pyc but this file can decompiled ... so ...!!
Indeed. So?

--
\ "For of those to whom much is given, much is required." -- |
`\ John F. Kennedy |
_o__) |
Ben Finney

Aug 11 '06 #9
Bayazee wrote:
hi
can we hide a python code ?
if i want to write a commercial software can i hide my source code from
users access ?
we can conver it to pyc but this file can decompiled ... so ...!!
It's just the same with java byte-code or machine code. FWIW, I had a
cracked (and localised) copy of Steinberg's Cubase midi sequencer v1.1
*before* v1.0 was publicly available in France... And believe me, they
had made their best to protect the software (dongle etc...).

The only secure way to protect "critical" code is to not distribute it -
make it run on your own server, and require the application to access
the server.
Aug 11 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.