refactor render_markdown.py
This commit is contained in:
@@ -15,8 +15,9 @@ def random_username() -> str:
|
||||
return "test_username" + "".join([choice(ascii_lowercase) for _ in range(6)])
|
||||
|
||||
|
||||
def select_keys_with_passcode_values(user_passcode: list[int], interface: list[int], attrs_per_key: int) -> list[int]:
|
||||
return [interface.index(attr) // attrs_per_key for attr in user_passcode]
|
||||
def select_keys_with_passcode_values(user_passcode: list[int], keypad: np.ndarray, attrs_per_key: int) -> list[int]:
|
||||
indices = [np.where(keypad == attr)[0][0] for attr in user_passcode]
|
||||
return [int(index // attrs_per_key) for index in indices]
|
||||
|
||||
|
||||
def visualize_keypad(keypad_list: np.ndarray, props_per_key: int):
|
||||
@@ -39,7 +40,7 @@ def render_nkode_authentication(data: dict):
|
||||
output = template.render(data)
|
||||
|
||||
# Print or save the output
|
||||
output_file = "/Users/donov/Desktop/NKode_documentation/nkode/docs/nkode_authentication.md"
|
||||
output_file = os.path.expanduser("~/Desktop/nkode_authentication.md")
|
||||
with open(output_file, 'w') as fp:
|
||||
fp.write(output)
|
||||
print("File written successfully")
|
||||
@@ -71,18 +72,17 @@ if __name__ == "__main__":
|
||||
set_attribute_dict = dict(zip(set_vals, attr_set_view))
|
||||
|
||||
session_id, signup_interface = api.generate_signup_keypad(customer_id)
|
||||
#signup_keypad = list_to_matrix(signup_keypad, keypad_size.numb_of_keys)
|
||||
signup_keypad = signup_interface.reshape(-1, keypad_size.props_per_key)
|
||||
signup_keypad = signup_interface.reshape(-1, keypad_size.numb_of_keys)
|
||||
|
||||
username = random_username()
|
||||
passcode_len = 4
|
||||
user_passcode = signup_interface[:passcode_len]
|
||||
user_passcode = signup_interface[:passcode_len].tolist()
|
||||
selected_keys_set = select_keys_with_passcode_values(user_passcode, signup_interface, keypad_size.numb_of_keys)
|
||||
server_side_attr = [customer.cipher.prop_key[idx] for idx in user_passcode]
|
||||
|
||||
confirm_interface = api.set_nkode(username, customer_id, selected_keys_set, session_id)
|
||||
|
||||
confirm_keypad = list_to_matrix(confirm_interface, keypad_size.numb_of_keys)
|
||||
confirm_keypad = confirm_interface.reshape(-1, keypad_size.numb_of_keys)
|
||||
|
||||
selected_keys_confirm = select_keys_with_passcode_values(user_passcode, confirm_interface, keypad_size.numb_of_keys)
|
||||
|
||||
@@ -121,7 +121,7 @@ if __name__ == "__main__":
|
||||
USER LOGIN
|
||||
"""
|
||||
login_interface = api.get_login_keypad(username, customer_id)
|
||||
login_keypad = list_to_matrix(login_interface, keypad_size.props_per_key)
|
||||
login_keypad = login_interface.reshape(-1, keypad_size.props_per_key)
|
||||
selected_keys_login = select_keys_with_passcode_values(user_passcode, login_interface, keypad_size.props_per_key)
|
||||
success = api.login(customer_id, username, selected_keys_login)
|
||||
assert success
|
||||
@@ -141,7 +141,7 @@ if __name__ == "__main__":
|
||||
login_passcode_sets = []
|
||||
for set_cipher in deciphered_mask[:passcode_len]:
|
||||
set_idx = np.where(set_key_rand_component == set_cipher)[0][0]
|
||||
login_passcode_sets.append(set_vals[set_idx])
|
||||
login_passcode_sets.append(int(set_vals[set_idx]))
|
||||
|
||||
"""
|
||||
GET PRESUMED ATTRIBUTES
|
||||
@@ -200,7 +200,7 @@ if __name__ == "__main__":
|
||||
'server_side_attr': server_side_attr,
|
||||
'confirm_keypad': confirm_keypad,
|
||||
'selected_keys_confirm': selected_keys_confirm,
|
||||
'cipher': user_keys,
|
||||
'user_cipher': user_keys,
|
||||
'passcode_server_attr': passcode_server_attr,
|
||||
'passcode_server_set': passcode_server_set,
|
||||
'enciphered_nkode': enciphered_nkode,
|
||||
|
||||
Reference in New Issue
Block a user