debugging set, confirm
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
import base64
|
||||
import hashlib
|
||||
|
||||
import bcrypt
|
||||
from secrets import choice
|
||||
from pydantic import BaseModel
|
||||
|
||||
from src.models import NKodeAttribute, EncipheredNKode
|
||||
from src.nkode_interface import NKodeInterface
|
||||
from src.utils import generate_random_nonrepeating_list, xor_lists, generate_random_nonrepeating_matrix
|
||||
from src.models import EncipheredNKode
|
||||
from src.nkode_interface import CustomerInterface
|
||||
from src.utils import generate_random_nonrepeating_list, xor_lists
|
||||
|
||||
|
||||
class UserCipherKeys(BaseModel):
|
||||
alpha_key: list[list[int]]
|
||||
alpha_key: list[int]
|
||||
set_key: list[int]
|
||||
pass_key: list[int]
|
||||
mask_key: list[int]
|
||||
@@ -25,7 +24,7 @@ class UserCipherKeys(BaseModel):
|
||||
set_key = xor_lists(set_key, set_values)
|
||||
|
||||
return UserCipherKeys(
|
||||
alpha_key=generate_random_nonrepeating_matrix(attrs_per_key, numb_of_keys),
|
||||
alpha_key=generate_random_nonrepeating_list(attrs_per_key*numb_of_keys),
|
||||
pass_key=generate_random_nonrepeating_list(numb_of_keys),
|
||||
mask_key=generate_random_nonrepeating_list(numb_of_keys),
|
||||
set_key=set_key,
|
||||
@@ -33,9 +32,9 @@ class UserCipherKeys(BaseModel):
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def pad_user_mask(user_mask: list[int], customer_interface: NKodeInterface, max_nkode_len: int) -> list[int]:
|
||||
def pad_user_mask(user_mask: list[int], customer_interface: CustomerInterface, max_nkode_len: int) -> list[int]:
|
||||
assert (len(user_mask) <= max_nkode_len)
|
||||
set_vals = customer_interface.set_
|
||||
set_vals = customer_interface.set_vals
|
||||
padded_user_mask = user_mask.copy()
|
||||
for _ in range(max_nkode_len - len(user_mask)):
|
||||
padded_user_mask.append(choice(set_vals))
|
||||
@@ -61,20 +60,25 @@ class UserCipherKeys(BaseModel):
|
||||
|
||||
def encipher_nkode(
|
||||
self,
|
||||
nkode_attr_index: list[NKodeAttribute],
|
||||
customer_interface: NKodeInterface
|
||||
nkode_attr_index: list[int],
|
||||
customer_interface: CustomerInterface
|
||||
) -> EncipheredNKode:
|
||||
max_nkode_len = 10
|
||||
user_nkode_mask = [attr.set_val for attr in user_nkode_attributes]
|
||||
user_nkode_attrs = [attr.attr_val for attr in user_nkode_attributes]
|
||||
passcode_len = len(nkode_attr_index)
|
||||
user_nkode_attrs = [customer_interface.interface[idx] for idx in nkode_attr_index]
|
||||
user_nkode_mask = [customer_interface.get_attr_set_val(attr) for attr in user_nkode_attrs]
|
||||
mask_cipher = self.pad_user_mask(user_nkode_mask, customer_interface, max_nkode_len)
|
||||
passcode_cipher = self.pad_user_code(user_nkode_attrs, max_nkode_len)
|
||||
passcode_cipher = self.pass_key
|
||||
|
||||
for idx in range(passcode_len):
|
||||
attr_idx = nkode_attr_index[idx]
|
||||
alpha = self.alpha_key[attr_idx]
|
||||
attr_val = user_nkode_attrs[idx]
|
||||
passcode_cipher[idx] ^= alpha ^ attr_val
|
||||
|
||||
for idx in range(max_nkode_len):
|
||||
set_idx = customer_interface.get_set_index(user_nkode_attributes[idx].set_val)
|
||||
attr_idx = customer_interface.get_set_index(user_nkode_attributes[idx].attr_val)
|
||||
passcode_cipher ^= self.alpha_key[set_idx][attr_idx] ^ self.pass_key[idx]
|
||||
mask_cipher ^= self.set_key[set_idx] ^ self.mask_key[idx]
|
||||
set_idx = customer_interface.get_set_index(user_nkode_mask[idx])
|
||||
mask_cipher[idx] ^= self.set_key[set_idx] ^ self.mask_key[idx]
|
||||
|
||||
return EncipheredNKode(
|
||||
code=self._hash_passcode(passcode_cipher),
|
||||
|
||||
Reference in New Issue
Block a user