diff --git a/pyencrypt/decrypt.py b/pyencrypt/decrypt.py index 66cb602..aea4bdf 100644 --- a/pyencrypt/decrypt.py +++ b/pyencrypt/decrypt.py @@ -1,12 +1,10 @@ import os -from functools import lru_cache from pathlib import Path from pyencrypt.aes import aes_decrypt from pyencrypt.ntt import intt -@lru_cache(maxsize=128) def decrypt_key(cipher_key: str, d: int, n: int) -> str: plain_ls = list() for num in map(int, cipher_key.split("O")): diff --git a/pyencrypt/loader.py b/pyencrypt/loader.py index eeb99f5..ac75b5e 100644 --- a/pyencrypt/loader.py +++ b/pyencrypt/loader.py @@ -3,6 +3,7 @@ import sys import traceback import types +from functools import lru_cache from importlib import abc, machinery from importlib._bootstrap_external import _NamespacePath from importlib.machinery import ModuleSpec @@ -49,6 +50,11 @@ def _init_license_path(self) -> None: self.license_path = path break + @classmethod + @lru_cache(maxsize=128) + def _decrypt_key(cls, cipher_key: str, d: int, n: int): + return decrypt_key(cipher_key, d, n) + def check(self) -> bool: if self.license is False: return False @@ -58,7 +64,7 @@ def check(self) -> bool: __n, __d = self.__private_key.split("O", 1) check_license( - self.license_path, decrypt_key(self.__cipher_key, int(__d), int(__n)) + self.license_path, self._decrypt_key(self.__cipher_key, int(__d), int(__n)) ) return True @@ -72,7 +78,7 @@ def get_data(self, path: _Path) -> bytes: try: __n, __d = self.__private_key.split("O", 1) return decrypt_file( - Path(path), decrypt_key(self.__cipher_key, int(__d), int(__n)) + Path(path), self._decrypt_key(self.__cipher_key, int(__d), int(__n)) ) except Exception: traceback.print_exc()