├── LICENSE ├── README.md └── encode.py /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Tahmid Rayat 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PyObfuscate 2 | **Simple Python Code Obfuscator.** 3 | 4 | [![Author](https://img.shields.io/badge/Author-HTR--TECH-blue)](https://github.com/htr-tech) 5 | [![Language](https://img.shields.io/badge/Written%20in-python-blue)](#) 6 | [![Opensource](https://img.shields.io/badge/Open%20Source-Yes-green)](#) 7 | 8 | ### Supported Language: 9 | - **python 2.x** 10 | - **python 3.x** 11 | 12 | ### Installation : 13 | 14 | ```bash 15 | apt install git python -y 16 | git clone https://github.com/htr-tech/PyObfuscate.git 17 | cd PyObfuscate 18 | python encode.py 19 | ``` 20 | 21 |

22 | 23 | ***Copyright (c) 2021 Tahmid Rayat Under [MIT LICENSE](https://github.com/htr-tech/PyObfuscate/blob/master/LICENSE#L1)*** 24 | 25 | ### *📡 Get in Touch :* 26 | [![Github](https://img.shields.io/badge/Github-525252?style=for-the-badge&logo=github)](https://github.com/htr-tech) 27 | [![Facebook](https://img.shields.io/badge/Facebook-3b5998?style=for-the-badge&logo=facebook)](https://fb.com/tahmid.rayat.official) 28 | [![Instagram](https://img.shields.io/badge/Instagram-8a3ab9?style=for-the-badge&logo=instagram)](https://www.instagram.com/tahmid.rayat) 29 | 30 | -------------------------------------------------------------------------------- /encode.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf8 -*- 2 | 3 | # Supports python2 & python3 4 | # Name : PyObfuscate - Simple Python Code Obfuscator 5 | # Author : HTR-TECH 6 | # Date : Sun Jul 19 00:19:27 2021 7 | 8 | # Import Modules 9 | import os 10 | import sys 11 | import zlib 12 | import time 13 | import base64 14 | import marshal 15 | import py_compile 16 | 17 | # Select raw_input() or input() 18 | if sys.version_info[0]==2: 19 | _input = "raw_input('%s')" 20 | elif sys.version_info[0]==3: 21 | _input = "input('%s')" 22 | else: 23 | sys.exit("\n Your Python Version is not Supported!") 24 | 25 | # Encoding 26 | zlb = lambda in_ : zlib.compress(in_) 27 | b16 = lambda in_ : base64.b16encode(in_) 28 | b32 = lambda in_ : base64.b32encode(in_) 29 | b64 = lambda in_ : base64.b64encode(in_) 30 | mar = lambda in_ : marshal.dumps(compile(in_,'','exec')) 31 | note = "\x23\x20\x4f\x62\x66\x75\x73\x63\x61\x74\x65\x64\x20\x77\x69\x74\x68\x20\x50\x79\x4f\x62\x66\x75\x73\x63\x61\x74\x65\x0a\x23\x20\x68\x74\x74\x70\x73\x3a\x2f\x2f\x77\x77\x77\x2e\x67\x69\x74\x68\x75\x62\x2e\x63\x6f\x6d\x2f\x68\x74\x72\x2d\x74\x65\x63\x68\x0a\x23\x20\x54\x69\x6d\x65\x20\x3a\x20%s\n\x23\x20\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x2d\x0a" % time.ctime() 32 | 33 | def banner(): # Program Banner 34 | print(' ╔═════════════════════════════════╗\n ║ PyObfuscate ║\n ║ Simple Python Code Obfuscator ║\n ║ Author : Tahmid Rayat ║\n ║ Github : Github.com/HTR-TECH ║\n ╚═════════════════════════════════╝\n') 35 | 36 | def menu(): # Program Menu 37 | print("\x20\x5b\x30\x31\x5d\x20\x45\x6e\x63\x6f\x64\x65\x20\x4d\x61\x72\x73\x68\x61\x6c\x0a\x20\x5b\x30\x32\x5d\x20\x45\x6e\x63\x6f\x64\x65\x20\x5a\x6c\x69\x62\x0a\x20\x5b\x30\x33\x5d\x20\x45\x6e\x63\x6f\x64\x65\x20\x42\x61\x73\x65\x31\x36\x0a\x20\x5b\x30\x34\x5d\x20\x45\x6e\x63\x6f\x64\x65\x20\x42\x61\x73\x65\x33\x32\x0a\x20\x5b\x30\x35\x5d\x20\x45\x6e\x63\x6f\x64\x65\x20\x42\x61\x73\x65\x36\x34\x0a\x20\x5b\x30\x36\x5d\x20\x45\x6e\x63\x6f\x64\x65\x20\x5a\x6c\x69\x62\x2c\x42\x61\x73\x65\x31\x36\x0a\x20\x5b\x30\x37\x5d\x20\x45\x6e\x63\x6f\x64\x65\x20\x5a\x6c\x69\x62\x2c\x42\x61\x73\x65\x33\x32\x0a\x20\x5b\x30\x38\x5d\x20\x45\x6e\x63\x6f\x64\x65\x20\x5a\x6c\x69\x62\x2c\x42\x61\x73\x65\x36\x34\x0a\x20\x5b\x30\x39\x5d\x20\x45\x6e\x63\x6f\x64\x65\x20\x4d\x61\x72\x73\x68\x61\x6c\x2c\x5a\x6c\x69\x62\x0a\x20\x5b\x31\x30\x5d\x20\x45\x6e\x63\x6f\x64\x65\x20\x4d\x61\x72\x73\x68\x61\x6c\x2c\x42\x61\x73\x65\x31\x36\x0a\x20\x5b\x31\x31\x5d\x20\x45\x6e\x63\x6f\x64\x65\x20\x4d\x61\x72\x73\x68\x61\x6c\x2c\x42\x61\x73\x65\x33\x32\x0a\x20\x5b\x31\x32\x5d\x20\x45\x6e\x63\x6f\x64\x65\x20\x4d\x61\x72\x73\x68\x61\x6c\x2c\x42\x61\x73\x65\x36\x34\x0a\x20\x5b\x31\x33\x5d\x20\x45\x6e\x63\x6f\x64\x65\x20\x4d\x61\x72\x73\x68\x61\x6c\x2c\x5a\x6c\x69\x62\x2c\x42\x31\x36\x0a\x20\x5b\x31\x34\x5d\x20\x45\x6e\x63\x6f\x64\x65\x20\x4d\x61\x72\x73\x68\x61\x6c\x2c\x5a\x6c\x69\x62\x2c\x42\x33\x32\x0a\x20\x5b\x31\x35\x5d\x20\x45\x6e\x63\x6f\x64\x65\x20\x4d\x61\x72\x73\x68\x61\x6c\x2c\x5a\x6c\x69\x62\x2c\x42\x36\x34\x0a\x20\x5b\x31\x36\x5d\x20\x53\x69\x6d\x70\x6c\x65\x20\x45\x6e\x63\x6f\x64\x65\x0a\x20\x5b\x31\x37\x5d\x20\x45\x78\x69\x74\n") 38 | 39 | class FileSize: # Gets the File Size 40 | def datas(self,z): 41 | for x in ['Byte','KB','MB','GB']: 42 | if z < 1024.0: 43 | return "%3.1f %s" % (z,x) 44 | z /= 1024.0 45 | def __init__(self,path): 46 | if os.path.isfile(path): 47 | dts = os.stat(path).st_size 48 | print(" [-] Encoded File Size : %s\n" % self.datas(dts)) 49 | # FileSize('rec.py') 50 | 51 | # Encode Menu 52 | def Encode(option,data,output): 53 | loop = int(eval(_input % " [-] Encode Count : ")) 54 | if option == 1: 55 | xx = "mar(data.encode('utf8'))[::-1]" 56 | heading = "_ = lambda __ : __import__('marshal').loads(__[::-1]);" 57 | elif option == 2: 58 | xx = "zlb(data.encode('utf8'))[::-1]" 59 | heading = "_ = lambda __ : __import__('zlib').decompress(__[::-1]);" 60 | elif option == 3: 61 | xx = "b16(data.encode('utf8'))[::-1]" 62 | heading = "_ = lambda __ : __import__('base64').b16decode(__[::-1]);" 63 | elif option == 4: 64 | xx = "b32(data.encode('utf8'))[::-1]" 65 | heading = "_ = lambda __ : __import__('base64').b32decode(__[::-1]);" 66 | elif option == 5: 67 | xx = "b64(data.encode('utf8'))[::-1]" 68 | heading = "_ = lambda __ : __import__('base64').b64decode(__[::-1]);" 69 | elif option == 6: 70 | xx = "b16(zlb(data.encode('utf8')))[::-1]" 71 | heading = "_ = lambda __ : __import__('zlib').decompress(__import__('base64').b16decode(__[::-1]));" 72 | elif option == 7: 73 | xx = "b32(zlb(data.encode('utf8')))[::-1]" 74 | heading = "_ = lambda __ : __import__('zlib').decompress(__import__('base64').b32decode(__[::-1]));" 75 | elif option == 8: 76 | xx = "b64(zlb(data.encode('utf8')))[::-1]" 77 | heading = "_ = lambda __ : __import__('zlib').decompress(__import__('base64').b64decode(__[::-1]));" 78 | elif option == 9: 79 | xx = "zlb(mar(data.encode('utf8')))[::-1]" 80 | heading = "_ = lambda __ : __import__('marshal').loads(__import__('zlib').decompress(__[::-1]));" 81 | elif option == 10: 82 | xx = "b16(mar(data.encode('utf8')))[::-1]" 83 | heading = "_ = lambda __ : __import__('marshal').loads(__import__('base64').b16decode(__[::-1]));" 84 | elif option == 11: 85 | xx = "b32(mar(data.encode('utf8')))[::-1]" 86 | heading = "_ = lambda __ : __import__('marshal').loads(__import__('base64').b32decode(__[::-1]));" 87 | elif option == 12: 88 | xx = "b64(mar(data.encode('utf8')))[::-1]" 89 | heading = "_ = lambda __ : __import__('marshal').loads(__import__('base64').b64decode(__[::-1]));" 90 | elif option == 13: 91 | xx = "b16(zlb(mar(data.encode('utf8'))))[::-1]" 92 | heading = "_ = lambda __ : __import__('marshal').loads(__import__('zlib').decompress(__import__('base64').b16decode(__[::-1])));" 93 | elif option == 14: 94 | xx = "b32(zlb(mar(data.encode('utf8'))))[::-1]" 95 | heading = "_ = lambda __ : __import__('marshal').loads(__import__('zlib').decompress(__import__('base64').b32decode(__[::-1])));" 96 | elif option == 15: 97 | xx = "b64(zlb(mar(data.encode('utf8'))))[::-1]" 98 | heading = "_ = lambda __ : __import__('marshal').loads(__import__('zlib').decompress(__import__('base64').b64decode(__[::-1])));" 99 | else: 100 | sys.exit("\n Invalid Option!") 101 | 102 | for x in range(loop): 103 | try: 104 | data = "exec((_)(%s))" % repr(eval(xx)) 105 | except TypeError as s: 106 | sys.exit(" TypeError : " + str(s)) 107 | with open(output, 'w') as f: 108 | f.write(note + heading + data) 109 | f.close() 110 | 111 | # Special Encode 112 | def SEncode(data,output): 113 | for x in range(5): 114 | method = repr(b64(zlb(mar(data.encode('utf8'))))[::-1]) 115 | data = "exec(__import__('marshal').loads(__import__('zlib').decompress(__import__('base64').b64decode(%s[::-1]))))" % method 116 | z = [] 117 | for i in data: 118 | z.append(ord(i)) 119 | sata = "_ = %s\nexec(''.join(chr(__) for __ in _))" % z 120 | with open(output, 'w') as f: 121 | f.write(note + "exec(str(chr(35)%s));" % '+chr(1)'*10000) 122 | f.write(sata) 123 | f.close() 124 | py_compile.compile(output,output) 125 | 126 | # Main Menu 127 | def MainMenu(): 128 | try: 129 | os.system('clear') # os.system('cls') 130 | banner() 131 | menu() 132 | try: 133 | option = int(eval(_input % " [-] Option : ")) 134 | except ValueError: 135 | sys.exit("\n Invalid Option !") 136 | 137 | if option > 0 and option <= 17: 138 | if option == 17: 139 | sys.exit("\n Thanks For Using this Tool") 140 | os.system('clear') # os.system('cls') 141 | banner() 142 | else: 143 | sys.exit('\n Invalid Option !') 144 | try: 145 | file = eval(_input % " [-] File Name : ") 146 | data = open(file).read() 147 | except IOError: 148 | sys.exit("\n File Not Found!") 149 | 150 | output = file.lower().replace('.py', '') + '_enc.py' 151 | if option == 16: 152 | SEncode(data,output) 153 | else: 154 | Encode(option,data,output) 155 | print("\n [-] Successfully Encrypted %s" % file) 156 | print(" [-] Saved as %s" % output) 157 | FileSize(output) 158 | except KeyboardInterrupt: 159 | time.sleep(1) 160 | sys.exit() 161 | 162 | if __name__ == "__main__": 163 | MainMenu() 164 | --------------------------------------------------------------------------------