Hi

Is there a way to hide the python source code from being copied or hacked?

I am planning to write and distribute some python code to my team, but I would prefer not to reveal the code. Is it possible in Linux?

In windows I wud probably create an .exe file and distribute it, how can i do the same in Linux?

Regards

Antonio

1) Convert the .py or .pyw files to a .pyc (python compiled file)
This is accomplished by importing the file; distribute the .pyc (Note that there are .pyc decompilers if they are wanting to know your code _that_ badly)
2) Obfuscate your code
This is accomplished by taking your code and making it as unreadable as possible. Take for example, the following code:

# For logging in to the system
class Secure():

    logbase = {'admin':'123456'}
    logged = False
    invalid = False

    def login(self, user, passw):
        self.logged = False
        self.invalid = False
        try:
            if self.logbase[user] == passw:
                self.logged = True
            else:
                self.logged = False
        except:
            self.logged = False
            self.invalid = True

    def __init__(self):
        while self.logged == False:
            user = raw_input('Username: ')
            passw = raw_input('Password: ')
            self.login(user, passw)
            if self.invalid == True:
                print "Invalid username"
            elif self.logged == False:
                print "Username and Password do not match"
            elif self.logged == True:
                print "Welcome to the system %s" %(user)

S = Secure()

Readable, right? Well, go through and rename every single variable to something else (_, __, ___, ____, etc.), and use import * as _. Also, try and fit as much as you can on one code; if possible, use the lambda function (I don't even know how to use it, sorry). So, our code now looks like this:

class _():
    _, __, ___ = {'admin':'123456'}, False, False
    def ____(_, __, ___):
        _.__ = False
        _.___ = False
        try:
            if _._[__] == ___: _.__ = True
            else: _.__ = False
        except:
            _.__, _.___ = False, True
    def __init__(_):
        while _.__ == False:
            __, ___ = raw_input('Username: '), raw_input('Password: ')
            _.____(__, ___)
            if _.___ == True: print "Invalid username"
            elif _.__ == False: print "Username and Password do not match"
            elif _.__ == True: print "Welcome to the system %s" %(__)
__ = _()

Now the code is highly unreadable, but still functional. Maybe this plus a fancy encryptor? xD That would work wonders. If you want a basic encryptor based on hexing, I can post some source code. Hope this helped :D

class _():
    _, __, ___ = {'admin':'123456'}, False, False
    def ____(_, __, ___):
        _.__ = False
        _.___ = False
        try:
            if _._[__] == ___: _.__ = True
            else: _.__ = False
        except:
            _.__, _.___ = False, True
    def __init__(_):
        while _.__ == False:
            __, ___ = raw_input('Username: '), raw_input('Password: ')
            _.____(__, ___)
            if _.___ == True: print "Invalid username"
            elif _.__ == False: print "Username and Password do not match"
            elif _.__ == True: print "Welcome to the system %s" %(__)
__ = _()

Duh!
I didn't thought of this.
a hacker heart will broke once he finds the code he used a lot of time and energy is that mess. He might even start thinking that his decompiler is lying to him ;)

This article has been dead for over six months. Start a new discussion instead.