rename attribute to property
This commit is contained in:
@@ -38,11 +38,11 @@ class Customer:
|
||||
for idx in range(passcode_len):
|
||||
key_numb = selected_keys[idx]
|
||||
set_idx = set_vals_idx[idx]
|
||||
selected_attr_idx = user.user_keypad.get_prop_idx_by_keynumb_setidx(key_numb, set_idx)
|
||||
presumed_property_idxs.append(selected_attr_idx)
|
||||
selected_prop_idx = user.user_keypad.get_prop_idx_by_keynumb_setidx(key_numb, set_idx)
|
||||
presumed_property_idxs.append(selected_prop_idx)
|
||||
|
||||
enciphered_attr = user.cipher.encipher_salt_hash_code(presumed_property_idxs, self.cipher)
|
||||
if enciphered_attr != user.enciphered_passcode.code:
|
||||
enciphered_prop = user.cipher.encipher_salt_hash_code(presumed_property_idxs, self.cipher)
|
||||
if enciphered_prop != user.enciphered_passcode.code:
|
||||
return False
|
||||
|
||||
if user.renew:
|
||||
|
||||
@@ -12,7 +12,7 @@ class NKodePolicy:
|
||||
min_nkode_len: int = 4
|
||||
distinct_sets: int = 0
|
||||
distinct_properties: int = 4
|
||||
byte_len: int = 2 # Todo: this should change the total number of bytes an attribute or set value can be
|
||||
byte_len: int = 2 # Todo: this should change the total number of bytes an properities or set value can be
|
||||
lock_out: int = 5
|
||||
expiration: int = -1 # in seconds -1 means nkode never expires
|
||||
|
||||
|
||||
@@ -74,8 +74,8 @@ class UserCipher:
|
||||
customer_cipher: CustomerCipher
|
||||
) -> EncipheredNKode:
|
||||
passcode_prop_idx_array = np.array(passcode_prop_idx, dtype=np.uint16)
|
||||
passcode_attrs = 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(attr) for attr in passcode_attrs], 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)
|
||||
code = self.encipher_salt_hash_code(passcode_prop_idx, customer_cipher)
|
||||
return EncipheredNKode(
|
||||
@@ -90,24 +90,24 @@ class UserCipher:
|
||||
) -> str:
|
||||
passcode_prop_idx_array = np.array(passcode_prop_idx, dtype=np.uint16)
|
||||
passcode_len = len(passcode_prop_idx_array)
|
||||
passcode_attrs = np.array([customer_prop.prop_key[idx] for idx in passcode_prop_idx_array], dtype=np.uint16)
|
||||
passcode_props = np.array([customer_prop.prop_key[idx] for idx in passcode_prop_idx_array], dtype=np.uint16)
|
||||
|
||||
passcode_cipher = self.pass_key.copy()
|
||||
for idx in range(passcode_len):
|
||||
attr_idx = passcode_prop_idx_array[idx]
|
||||
passcode_cipher[idx] = passcode_cipher[idx] ^ self.prop_key[attr_idx] ^ passcode_attrs[idx]
|
||||
prop_idx = passcode_prop_idx_array[idx]
|
||||
passcode_cipher[idx] = passcode_cipher[idx] ^ self.prop_key[prop_idx] ^ passcode_props[idx]
|
||||
|
||||
return self._hash_passcode(passcode_cipher)
|
||||
|
||||
def encipher_mask(
|
||||
self,
|
||||
passcode_sets: list[int],
|
||||
customer_attributes: CustomerCipher
|
||||
customer_properites: CustomerCipher
|
||||
) -> str:
|
||||
padded_passcode_sets = self.pad_user_mask(passcode_sets, customer_attributes.set_key)
|
||||
padded_passcode_sets = self.pad_user_mask(passcode_sets, customer_properites.set_key)
|
||||
|
||||
# Get indices of set values
|
||||
set_idx = np.array([customer_attributes.get_set_index(set_val) for set_val in padded_passcode_sets],
|
||||
set_idx = np.array([customer_properites.get_set_index(set_val) for set_val in padded_passcode_sets],
|
||||
dtype=np.uint16)
|
||||
mask_set_keys = np.array([self.set_key[idx] for idx in set_idx], dtype=np.uint16)
|
||||
|
||||
|
||||
@@ -22,13 +22,12 @@ class UserKeypad:
|
||||
raise ValueError("Keypad size is dispersable")
|
||||
self.random_keypad_shuffle()
|
||||
keypad_matrix = self.keypad_matrix()
|
||||
attr_set_view = keypad_matrix.T
|
||||
#attr_set_view = secure_fisher_yates_shuffle(attr_set_view)
|
||||
attr_set_view = np.random.permutation(attr_set_view)
|
||||
attr_set_view = attr_set_view[:self.keypad_size.numb_of_keys]
|
||||
keypad_matrix = attr_set_view.reshape(-1)#matrix_transpose(attr_set_view)
|
||||
prop_set_view = keypad_matrix.T
|
||||
prop_set_view = np.random.permutation(prop_set_view)
|
||||
prop_set_view = prop_set_view[:self.keypad_size.numb_of_keys]
|
||||
keypad_matrix = prop_set_view.reshape(-1)
|
||||
return UserKeypad(
|
||||
keypad=keypad_matrix.reshape(-1),#matrix_to_list(keypad_matrix),
|
||||
keypad=keypad_matrix.reshape(-1),
|
||||
keypad_size=KeypadSize(
|
||||
numb_of_keys=self.keypad_size.numb_of_keys,
|
||||
props_per_key=self.keypad_size.numb_of_keys
|
||||
@@ -56,10 +55,10 @@ class UserKeypad:
|
||||
#shuffled_keys = secure_fisher_yates_shuffle(user_keypad_matrix)
|
||||
shuffled_keys = rng.permutation(user_keypad_matrix, axis=0)
|
||||
#prop_rotation = secure_fisher_yates_shuffle(list(range(self.keypad_size.numb_of_keys)))[:self.keypad_size.props_per_key]
|
||||
attr_rotation = rng.permutation(list(range(self.keypad_size.numb_of_keys)))[:self.keypad_size.props_per_key]
|
||||
prop_rotation = rng.permutation(list(range(self.keypad_size.numb_of_keys)))[:self.keypad_size.props_per_key]
|
||||
dispersed_keypad = random_property_rotation(
|
||||
shuffled_keys,
|
||||
attr_rotation.tolist(),
|
||||
prop_rotation.tolist(),
|
||||
)
|
||||
self.keypad = dispersed_keypad.reshape(-1)
|
||||
|
||||
@@ -72,11 +71,11 @@ class UserKeypad:
|
||||
#user_keypad_matrix = self.keypad_matrix()
|
||||
#shuffled_keys = secure_fisher_yates_shuffle(user_keypad_matrix)
|
||||
#keypad_by_sets = []
|
||||
#for idx, attrs in enumerate(matrix_transpose(shuffled_keys)):
|
||||
#for idx, props in enumerate(matrix_transpose(shuffled_keys)):
|
||||
# if idx in selected_sets:
|
||||
# keypad_by_sets.append(secure_fisher_yates_shuffle(attrs))
|
||||
# keypad_by_sets.append(secure_fisher_yates_shuffle(props))
|
||||
# else:
|
||||
# keypad_by_sets.append(attrs)
|
||||
# keypad_by_sets.append(props)
|
||||
#self.keypad = matrix_to_list(matrix_transpose(keypad_by_sets))
|
||||
pass
|
||||
|
||||
@@ -85,9 +84,9 @@ class UserKeypad:
|
||||
user_keypad_keypad = self.keypad_matrix()
|
||||
graph = {}
|
||||
for key in user_keypad_keypad:
|
||||
for attr in key:
|
||||
graph[attr] = set(key)
|
||||
graph[attr].remove(attr)
|
||||
for prop in key:
|
||||
graph[prop] = set(key)
|
||||
graph[prop].remove(prop)
|
||||
return graph
|
||||
|
||||
def get_prop_idx_by_keynumb_setidx(self, key_numb: int, set_idx: int) -> int:
|
||||
@@ -95,5 +94,5 @@ class UserKeypad:
|
||||
raise ValueError(f"key_numb must be between 0 and {self.keypad_size.numb_of_keys - 1}")
|
||||
if not (0 <= set_idx < self.keypad_size.props_per_key):
|
||||
raise ValueError(f"set_idx must be between 0 and {self.keypad_size.props_per_key - 1}")
|
||||
keypad_attr_idx = self.keypad_matrix()
|
||||
return int(keypad_attr_idx[key_numb][set_idx])
|
||||
keypad_prop_idx = self.keypad_matrix()
|
||||
return int(keypad_prop_idx[key_numb][set_idx])
|
||||
|
||||
@@ -19,14 +19,14 @@ class UserSignupSession:
|
||||
def deduce_passcode(self, confirm_key_entry: list[int]) -> list[int]:
|
||||
if not all(0 <= key <= self.keypad_size.numb_of_keys for key in confirm_key_entry):
|
||||
raise ValueError("Key values must be within valid range")
|
||||
attrs_per_key = self.keypad_size.props_per_key
|
||||
props_per_key = self.keypad_size.props_per_key
|
||||
set_key_entry = self.set_key_entry
|
||||
if len(set_key_entry) != len(confirm_key_entry):
|
||||
raise ValueError("Key entry lengths must match")
|
||||
set_keypad = self.set_keypad
|
||||
confirm_keypad = self.confirm_keypad
|
||||
set_key_vals = [set_keypad[key * attrs_per_key:(key + 1) * attrs_per_key] for key in set_key_entry]
|
||||
confirm_key_vals = [confirm_keypad[key * attrs_per_key:(key + 1) * attrs_per_key] for key in
|
||||
set_key_vals = [set_keypad[key * props_per_key:(key + 1) * props_per_key] for key in set_key_entry]
|
||||
confirm_key_vals = [confirm_keypad[key * props_per_key:(key + 1) * props_per_key] for key in
|
||||
confirm_key_entry]
|
||||
passcode = []
|
||||
for idx in range(len(set_key_entry)):
|
||||
|
||||
14
src/utils.py
14
src/utils.py
@@ -2,13 +2,13 @@ import numpy as np
|
||||
|
||||
def random_property_rotation(
|
||||
user_keypad: np.ndarray,
|
||||
attr_rotation: list[int]
|
||||
prop_rotation: list[int]
|
||||
) -> np.ndarray:
|
||||
transposed = user_keypad.T
|
||||
if len(attr_rotation) != len(transposed):
|
||||
raise ValueError("prop_rotation must be the same length as the number of attributes")
|
||||
for idx, attr_set in enumerate(transposed):
|
||||
rotation = attr_rotation[idx]
|
||||
rotation = rotation % len(attr_set) if len(attr_set) > 0 else 0
|
||||
transposed[idx] = np.roll(attr_set, rotation)
|
||||
if len(prop_rotation) != len(transposed):
|
||||
raise ValueError("prop_rotation must be the same length as the number of properties")
|
||||
for idx, prop_set in enumerate(transposed):
|
||||
rotation = prop_rotation[idx]
|
||||
rotation = rotation % len(prop_set) if len(prop_set) > 0 else 0
|
||||
transposed[idx] = np.roll(prop_set, rotation)
|
||||
return transposed.T
|
||||
|
||||
Reference in New Issue
Block a user