Skip to content

Commit aa52595

Browse files
committed
perf: ⚡️ speed up decrypt_key
Closes: #17
1 parent deda1ed commit aa52595

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

pyencrypt/decrypt.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import os
2-
from functools import lru_cache
32
from pathlib import Path
43

54
from pyencrypt.aes import aes_decrypt
65
from pyencrypt.ntt import intt
76

87

9-
@lru_cache(maxsize=128)
108
def decrypt_key(cipher_key: str, d: int, n: int) -> str:
119
plain_ls = list()
1210
for num in map(int, cipher_key.split("O")):

pyencrypt/loader.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
import traceback
55
import types
6+
from functools import lru_cache
67
from importlib import abc, machinery
78
from importlib._bootstrap_external import _NamespacePath
89
from importlib.machinery import ModuleSpec
@@ -49,6 +50,11 @@ def _init_license_path(self) -> None:
4950
self.license_path = path
5051
break
5152

53+
@classmethod
54+
@lru_cache(maxsize=128)
55+
def _decrypt_key(cls, cipher_key: str, d: int, n: int):
56+
return decrypt_key(cipher_key, d, n)
57+
5258
def check(self) -> bool:
5359
if self.license is False:
5460
return False
@@ -58,7 +64,7 @@ def check(self) -> bool:
5864

5965
__n, __d = self.__private_key.split("O", 1)
6066
check_license(
61-
self.license_path, decrypt_key(self.__cipher_key, int(__d), int(__n))
67+
self.license_path, self._decrypt_key(self.__cipher_key, int(__d), int(__n))
6268
)
6369
return True
6470

@@ -72,7 +78,7 @@ def get_data(self, path: _Path) -> bytes:
7278
try:
7379
__n, __d = self.__private_key.split("O", 1)
7480
return decrypt_file(
75-
Path(path), decrypt_key(self.__cipher_key, int(__d), int(__n))
81+
Path(path), self._decrypt_key(self.__cipher_key, int(__d), int(__n))
7682
)
7783
except Exception:
7884
traceback.print_exc()

0 commit comments

Comments
 (0)