refactor use numpy in user_cipher.py

This commit is contained in:
2025-03-11 10:33:08 -05:00
parent dd0b496a21
commit 526e537586
7 changed files with 230 additions and 177 deletions

View File

@@ -10,20 +10,20 @@ from src.utils import xor_lists
class User:
username: str
enciphered_passcode: EncipheredNKode
user_keys: UserCipher
cipher: UserCipher
user_keypad: UserKeypad
renew: bool = field(default=False)
def renew_keys(self, sets_xor: list[int], attrs_xor: list[int]):
def renew_keys(self, set_xor: list[int], prop_xor: list[int]):
self.renew = True
self.user_keys.set_key = xor_lists(self.user_keys.set_key, sets_xor)
self.user_keys.prop_key = xor_lists(self.user_keys.prop_key, attrs_xor)
self.cipher.set_key = xor_lists(self.cipher.set_key, set_xor)
self.cipher.prop_key = xor_lists(self.cipher.prop_key, prop_xor)
def refresh_passcode(self, passcode_attr_idx: list[int], customer_attributes: CustomerCipher):
self.user_keys = UserCipher.create(
self.cipher = UserCipher.create(
customer_attributes.keypad_size,
customer_attributes.set_key,
self.user_keys.max_nkode_len
self.cipher.max_nkode_len
)
self.enciphered_passcode = self.user_keys.encipher_nkode(passcode_attr_idx, customer_attributes)
self.enciphered_passcode = self.cipher.encipher_nkode(passcode_attr_idx, customer_attributes)
self.renew = False