From 1fc04c37d3456790f2bfac96e743eb92629981e9 Mon Sep 17 00:00:00 2001 From: Eternity <1533512157@qq.com> Date: Mon, 26 Jan 2026 12:22:54 +0800 Subject: [PATCH] perf(sandbox): optimize code encryption handling --- sandbox/app/core/encryption.py | 3 ++- sandbox/app/core/runners/python/prescript.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sandbox/app/core/encryption.py b/sandbox/app/core/encryption.py index 5e0855c9..47a756c8 100644 --- a/sandbox/app/core/encryption.py +++ b/sandbox/app/core/encryption.py @@ -12,9 +12,10 @@ def encrypt_code(code: bytes, key: bytes) -> str: Returns: Base64 encoded encrypted code """ + key_length = len(key) encrypted_code = bytearray(len(code)) for i in range(len(code)): - encrypted_code[i] = code[i] ^ key[i % 64] + encrypted_code[i] = code[i] ^ key[i % key_length] encoded_code = base64.b64encode(encrypted_code).decode("utf-8") return encoded_code diff --git a/sandbox/app/core/runners/python/prescript.py b/sandbox/app/core/runners/python/prescript.py index 4790be73..950710ea 100644 --- a/sandbox/app/core/runners/python/prescript.py +++ b/sandbox/app/core/runners/python/prescript.py @@ -17,7 +17,7 @@ sys.excepthook = excepthook # Load security library if available lib = ctypes.CDLL("./libpython.so") lib.init_seccomp.argtypes = [ctypes.c_uint32, ctypes.c_uint32, ctypes.c_bool] -lib.init_seccomp.restype = None +lib.init_seccomp.restype = None # TODO: raise error info # Get running path running_path = sys.argv[1]