Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (4)

Powered by Vanilla. Made with Bootstrap.
Simple - Encoding your source
  • So I'm writing this very simple guide to help you encode your source. It can of course be decoded but it's good for simply encoding it.
    First we take our source and encode it using base64. Check out this simple example for encoding:

    import base64
    code = ('''
    import os, sys
    a = \"test1\"
    a1 = os.name
    print a1
    print(\"\\n\\ntest2\") #Notice we use two slashes. This is to escape when we write to the file
    sys.exit()
    ''')
    base = base64.b64encode(code)
    print base

    Here would be the output:

    CmltcG9ydCBvcywgc3lzCmEgPSAidGVzdDEiCmExID0gb3MubmFtZSgpCnByaW50IGExCnByaW50KCJcblxudGVzdDIiKSAjTm90aWNlIHdlIHVzZSB0d28gc2xhc2hlcy4gVGhpcyBpcyB0byBlc2NhcGUgd2hlbiB3ZSB3cml0ZSB0byB0aGUgZmlsZQpzeXMuZXhpdCgpCg==

    Now we take that and decode it and write to a file.

    import base64
    code=('''
    CmltcG9ydCBvcywgc3lzCmEgPSAidGVzdDEiCmExID0gb3MubmFtZSgpCnByaW50IGExCnByaW50KCJcblxudGVzdDIiKSAjTm90aWNlIHdlIHVzZSB0d28gc2xhc2hlcy4gVGhpcyBpcyB0byBlc2NhcGUgd2hlbiB3ZSB3cml0ZSB0byB0aGUgZmlsZQpzeXMuZXhpdCgpCg==
    ''')
    code1 = base64.b64decode(code)
    file = open('/tmp/test.py', 'w')
    file.write(code1)
    file.close()

    Simple. It decodes and writes to a file. Now lets execute /tmp/test.py

    chronic@vandal:/tmp$ python /tmp/test/py
    posix


    test2

    It worked :)

    Note that this is easy to decode.
    You could also use eval() but I haven't had success with that.
  • Xin
    Posts: 3,251
    Nice, although pretty easy to decode if you were trying to decompile it
    Xin
  • chroniccommand
    Posts: 1,389
    said:


    Nice, although pretty easy to decode if you were trying to decompile it



    Yea I mentioned that :p