diff --git a/src/user_cipher.py b/src/user_cipher.py index daa3bf5..f1513c3 100644 --- a/src/user_cipher.py +++ b/src/user_cipher.py @@ -73,10 +73,7 @@ class UserCipher: passcode_prop_idx: list[int], customer_cipher: CustomerCipher ) -> EncipheredNKode: - passcode_prop_idx_array = np.array(passcode_prop_idx, dtype=np.uint16) - passcode_props = np.array([customer_cipher.prop_key[idx] for idx in passcode_prop_idx_array], dtype=np.uint16) - passcode_sets = np.array([customer_cipher.get_prop_set_val(prop) for prop in passcode_props], dtype=np.uint16) - mask = self.encipher_mask(passcode_sets.tolist(), customer_cipher) + mask = self.encipher_mask(passcode_prop_idx, customer_cipher) code = self.encipher_salt_hash_code(passcode_prop_idx, customer_cipher) return EncipheredNKode( code=code, @@ -101,18 +98,20 @@ class UserCipher: def encipher_mask( self, - passcode_sets: np.ndarray, - customer_properites: CustomerCipher + passcode_prop_idx: list[int], + customer_cipher: CustomerCipher ) -> str: - padded_passcode_sets = self.pad_user_mask(passcode_sets, customer_properites.set_key) + 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) # Get indices of set values - set_idx = np.array([customer_properites.get_set_index(set_val) for set_val in padded_passcode_sets], + set_idx = np.array([customer_cipher.get_set_index(set_val) for set_val in padded_customer_sets], dtype=np.uint16) mask_set_keys = np.array([self.set_key[idx] for idx in set_idx], dtype=np.uint16) # XOR operations - ciphered_mask = np.bitwise_xor(mask_set_keys, padded_passcode_sets) + ciphered_mask = np.bitwise_xor(mask_set_keys, padded_customer_sets) ciphered_mask = np.bitwise_xor(ciphered_mask, self.mask_key) mask = self.encode_base64_str(ciphered_mask)