import argparse
import marshal
import base64
import os
from cryptography.fernet import Fernet
from Cryptodome.Cipher import AES
from Cryptodome.Util.Padding import pad, unpad
def a1b2c3():
return Fernet.generate_key()
def d4e5f6():
return os.urandom(32)
def g7h8i9(data, key):
cipher = AES.new(key, AES.MODE_CBC)
iv = cipher.iv
encrypted_data = cipher.encrypt(pad(data, AES.block_size))
return base64.b64encode(iv + encrypted_data)
def j0k1l2(data, key):
data = base64.b64decode(data)
iv = data[:16]
cipher = AES.new(key, AES.MODE_CBC, iv)
decrypted_data = unpad(cipher.decrypt(data[16:]), AES.block_size)
return decrypted_data
def m3n4o5(code, key):
cipher = Fernet(key)
return cipher.encrypt(code)
def p6q7r8(file_path):
with open(file_path, 'r') as f:
code = f.read()
bytecode = compile(code, file_path, 'exec')
return marshal.dumps(bytecode)
def s9t0u1(file_path, layers):
serialized_bytecode = p6q7r8(file_path)
aes_key = d4e5f6()
aes_encrypted = g7h8i9(serialized_bytecode, aes_key)
fernet_keys = [a1b2c3() for _ in range(layers)]
encrypted_bytecode = aes_encrypted
for key in fernet_keys:
encrypted_bytecode = m3n4o5(encrypted_bytecode, key)
base64_encoded = base64.b64encode(encrypted_bytecode).decode()
hex_encoded = base64_encoded.encode('utf-8').hex()
obfuscated_keys = [base64.b64encode(key).decode().encode('utf-8').hex() for key in fernet_keys]
aes_key_hex = aes_key.hex()
obfuscated_code = f"""
import base64 as b64, marshal as m, random, string
from cryptography.fernet import Fernet as F
from Cryptodome.Cipher import AES as A
from Cryptodome.Util.Padding import unpad as p
def _g7h8i9(encrypted_data, aes_key):
encrypted_data = b64.b64decode(encrypted_data)
iv = encrypted_data[:16]
cipher = A.new(aes_key, A.MODE_CBC, iv)
return p(cipher.decrypt(encrypted_data[16:]), A.block_size)
def _m3n4o5(encrypted_data, fernet_key):
fernet = F(fernet_key)
return fernet.decrypt(encrypted_data)
def _p6q7r8(hex_string):
return bytes.fromhex(hex_string)
def _s9t0u1():
encoded_bytecode='{hex_encoded}'
obfuscated_keys={obfuscated_keys}
aes_key_hex='{aes_key_hex}'
aes_key=bytes.fromhex(aes_key_hex)
encoded_data=_p6q7r8(encoded_bytecode)
decrypted_data=b64.b64decode(encoded_data)
key_list=[b64.b64decode(_p6q7r8(key)) for key in obfuscated_keys]
final_data=decrypted_data
for key in reversed(key_list):
final_data=_m3n4o5(final_data, key)
final_data=_g7h8i9(final_data, aes_key)
bytecode=m.loads(final_data)
exec(bytecode)
_s9t0u1()
"""
obfuscated_file_path = file_path.replace('.py', '_obfuscated.py')
with open(obfuscated_file_path, 'w') as f:
f.write(obfuscated_code)
print(f"[+] CG-Armor 1.0 Python Obfuscator")
print(f"[+] File Secured Successfully -> {obfuscated_file_path}")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='CG Armor 1.0 Powerful')
parser.add_argument('-f', '--file', type=str, required=True, help='File Name')
parser.add_argument('-l', '--layers', type=int, default=4, help='Encryption level (default: 4)')
args = parser.parse_args()
s9t0u1(args.file, args.layers)