refactor; rename alpha to prop
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import ClassVar
|
||||
|
||||
from src.models import KeypadSize
|
||||
from src.utils import generate_random_nonrepeating_list
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ from typing import Dict, List, Tuple
|
||||
from src.customer import Customer
|
||||
from src.models import NKodePolicy, KeypadSize
|
||||
from src.user import User
|
||||
from src.user_cipher_keys import UserCipher
|
||||
from src.user_cipher import UserCipher
|
||||
from src.user_signup_session import UserSignupSession
|
||||
from src.user_keypad import UserKeypad
|
||||
from src.customer_cipher import CustomerCipher
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from dataclasses import dataclass, field
|
||||
from src.models import EncipheredNKode
|
||||
from src.customer_cipher import CustomerCipher
|
||||
from src.user_cipher_keys import UserCipher
|
||||
from src.user_cipher import UserCipher
|
||||
from src.user_keypad import UserKeypad
|
||||
from src.utils import xor_lists
|
||||
|
||||
@@ -17,7 +17,7 @@ class User:
|
||||
def renew_keys(self, sets_xor: list[int], attrs_xor: list[int]):
|
||||
self.renew = True
|
||||
self.user_keys.set_key = xor_lists(self.user_keys.set_key, sets_xor)
|
||||
self.user_keys.alpha_key = xor_lists(self.user_keys.alpha_key, attrs_xor)
|
||||
self.user_keys.prop_key = xor_lists(self.user_keys.prop_key, attrs_xor)
|
||||
|
||||
def refresh_passcode(self, passcode_attr_idx: list[int], customer_attributes: CustomerCipher):
|
||||
self.user_keys = UserCipher.create(
|
||||
|
||||
@@ -9,7 +9,7 @@ from src.utils import generate_random_nonrepeating_list, xor_lists, int_array_to
|
||||
|
||||
@dataclass
|
||||
class UserCipher:
|
||||
alpha_key: list[int]
|
||||
prop_key: list[int]
|
||||
set_key: list[int]
|
||||
pass_key: list[int]
|
||||
mask_key: list[int]
|
||||
@@ -25,7 +25,7 @@ class UserCipher:
|
||||
set_key = xor_lists(set_key, set_values)
|
||||
|
||||
return UserCipher(
|
||||
alpha_key=generate_random_nonrepeating_list(keypad_size.props_per_key * keypad_size.numb_of_keys),
|
||||
prop_key=generate_random_nonrepeating_list(keypad_size.props_per_key * keypad_size.numb_of_keys),
|
||||
pass_key=generate_random_nonrepeating_list(max_nkode_len),
|
||||
mask_key=generate_random_nonrepeating_list(max_nkode_len),
|
||||
set_key=set_key,
|
||||
@@ -63,14 +63,14 @@ class UserCipher:
|
||||
|
||||
def encipher_nkode(
|
||||
self,
|
||||
passcode_attr_idx: list[int],
|
||||
customer_attributes: CustomerCipher
|
||||
passcode_prop_idx: list[int],
|
||||
customer_cipher: CustomerCipher
|
||||
) -> EncipheredNKode:
|
||||
|
||||
passcode_attrs = [customer_attributes.prop_key[idx] for idx in passcode_attr_idx]
|
||||
passcode_sets = [customer_attributes.get_prop_set_val(attr) for attr in passcode_attrs]
|
||||
mask = self.encipher_mask(passcode_sets, customer_attributes)
|
||||
code = self.encipher_salt_hash_code(passcode_attr_idx, customer_attributes)
|
||||
passcode_attrs = [customer_cipher.prop_key[idx] for idx in passcode_prop_idx]
|
||||
passcode_sets = [customer_cipher.get_prop_set_val(attr) for attr in passcode_attrs]
|
||||
mask = self.encipher_mask(passcode_sets, customer_cipher)
|
||||
code = self.encipher_salt_hash_code(passcode_prop_idx, customer_cipher)
|
||||
return EncipheredNKode(
|
||||
code=code,
|
||||
mask=mask
|
||||
@@ -78,19 +78,15 @@ class UserCipher:
|
||||
|
||||
def encipher_salt_hash_code(
|
||||
self,
|
||||
passcode_attr_idx: list[int],
|
||||
customer_attributes: CustomerCipher,
|
||||
passcode_prop_idx: list[int],
|
||||
customer_prop: CustomerCipher,
|
||||
) -> str:
|
||||
passcode_len = len(passcode_attr_idx)
|
||||
passcode_attrs = [customer_attributes.prop_key[idx] for idx in passcode_attr_idx]
|
||||
|
||||
passcode_len = len(passcode_prop_idx)
|
||||
passcode_attrs = [customer_prop.prop_key[idx] for idx in passcode_prop_idx]
|
||||
passcode_cipher = self.pass_key.copy()
|
||||
|
||||
for idx in range(passcode_len):
|
||||
attr_idx = passcode_attr_idx[idx]
|
||||
alpha = self.alpha_key[attr_idx]
|
||||
attr_val = passcode_attrs[idx]
|
||||
passcode_cipher[idx] ^= alpha ^ attr_val
|
||||
attr_idx = passcode_prop_idx[idx]
|
||||
passcode_cipher[idx] ^= self.prop_key[attr_idx] ^ passcode_attrs[idx]
|
||||
return self._hash_passcode(passcode_cipher)
|
||||
|
||||
def encipher_mask(
|
||||
Reference in New Issue
Block a user