refactor set_key -> position_key

This commit is contained in:
2025-03-19 09:34:02 -05:00
parent cfef58613c
commit 7b92a6b40b
10 changed files with 511 additions and 407 deletions

View File

@@ -19,9 +19,7 @@ class UserCipher:
def create(cls, keypad_size: KeypadSize, customer_set_key: np.ndarray, max_nkode_len: int) -> 'UserCipher':
if len(customer_set_key) != keypad_size.props_per_key:
raise ValueError("Invalid set values")
user_set_key = np.random.choice(2**16,size=keypad_size.props_per_key, replace=False)
return UserCipher(
prop_key=np.random.choice(2 ** 16, size=keypad_size.total_props, replace=False),
pass_key=np.random.choice(2 ** 16, size=max_nkode_len, replace=False),
@@ -93,7 +91,7 @@ class UserCipher:
passcode_cipher[:passcode_len] = (
passcode_cipher[:passcode_len] ^
self.prop_key[passcode_prop_idx] ^
customer_prop.prop_key[passcode_prop_idx]
customer_prop.property_key[passcode_prop_idx]
)
return passcode_cipher.astype(np.uint16).tobytes()
@@ -102,12 +100,10 @@ class UserCipher:
passcode_prop_idx: list[int],
customer_cipher: CustomerCipher
) -> str:
customer_props = customer_cipher.prop_key[passcode_prop_idx]
customer_sets = [customer_cipher.get_prop_set_val(prop) for prop in customer_props]
padded_customer_sets = self.pad_user_mask(np.array(customer_sets), customer_cipher.set_key)
set_idx = [customer_cipher.get_set_index(set_val) for set_val in padded_customer_sets]
ordered_set_key = self.combined_set_key[set_idx]
mask = ordered_set_key ^ padded_customer_sets ^ self.mask_key
set_idxs = customer_cipher.get_passcode_position_indices_padded(passcode_prop_idx, len(self.mask_key))
ordered_set_key = self.combined_set_key[set_idxs]
ordered_customer_key = customer_cipher.position_key[set_idxs]
mask = ordered_set_key ^ ordered_customer_key ^ self.mask_key
encoded_mask = self.encode_base64_str(mask)
return encoded_mask