fix split shuffle
This commit is contained in:
@@ -205,12 +205,14 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"### User Signup\n",
|
"### User Signup\n",
|
||||||
"To create a new must call this endpoints in order:\n",
|
"To create a new must call this endpoints in order:\n",
|
||||||
"1. Generate Keypad\n",
|
"1. Generate a randomly shuffled keypad\n",
|
||||||
"2. Set User NKode\n",
|
"2. Set user nKode\n",
|
||||||
"3. Confirm User NKode\n",
|
"3. Confirm user nKode\n",
|
||||||
"\n",
|
"\n",
|
||||||
"#### Generate Keypad\n",
|
"#### Generate Keypad\n",
|
||||||
" For the server to determine the users nkode, the user's keypad must be dispersable. To make the keypad dispersable, the server will randomly drop properties sets to the number of properties is equal to the number of keys. In our case, the server drops 1 properties set to give us a 5 X 5 keypad with possible index values ranging from 0-29.\n",
|
" For the server to determine the users nkode, the user's keypad must be dispersable.\n",
|
||||||
|
" To make the keypad dispersable, the server will randomly drop properties sets to the number of properties is equal to the number of keys.\n",
|
||||||
|
" In our case, the server drops 1 properties set to give us a 5 X 5 keypad with possible index values ranging from 0-29.\n",
|
||||||
" - Run the cell below over and over to see it change. Notice that values never move out of their columns just their rows.\n",
|
" - Run the cell below over and over to see it change. Notice that values never move out of their columns just their rows.\n",
|
||||||
" - each value in the keypad is the index value of a customer properties\n",
|
" - each value in the keypad is the index value of a customer properties\n",
|
||||||
" - the user never learns what their \"real\" properties is. All they do is specify an index in the customer keypad\n"
|
" - the user never learns what their \"real\" properties is. All they do is specify an index in the customer keypad\n"
|
||||||
@@ -248,7 +250,12 @@
|
|||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"source": [
|
"source": [
|
||||||
"#### Set nKode\n",
|
"#### Set nKode\n",
|
||||||
"The user identifies properties in the keypad they want in their nkode. Each properties in the gui has an index value. Below the user has selected 16, 9, 6, 19. Graphically represent with anything. The only requirement is that the graphical properties must be associated with the same index value everytime the user goes to login. If the user wants to change anything about their keypad(the number of keys, properties or graphical properties), they must also change their nkode."
|
"The user identifies properties in the keypad they want in their nkode.\n",
|
||||||
|
"Each properties in the gui has an index value.\n",
|
||||||
|
"Below the user has selected 16, 9, 6, 19.\n",
|
||||||
|
"Graphically represent with anything.\n",
|
||||||
|
"The only requirement is that the graphical properties must be associated with the same index value everytime the user goes to login.\n",
|
||||||
|
"If the user wants to change anything about their keypad(the number of keys, properties or graphical properties), they must also change their nkode."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -63,9 +63,13 @@ class UserKeypad:
|
|||||||
self.keypad = dispersed_keypad.reshape(-1)
|
self.keypad = dispersed_keypad.reshape(-1)
|
||||||
|
|
||||||
def split_shuffle(self):
|
def split_shuffle(self):
|
||||||
|
# shuffle all keys
|
||||||
|
keypad_view = self.keypad_matrix()
|
||||||
|
np.random.shuffle(keypad_view)
|
||||||
|
# select half the property sets
|
||||||
prop_permutation = np.random.permutation(self.keypad_size.props_per_key)[: self.keypad_size.props_per_key // 2]
|
prop_permutation = np.random.permutation(self.keypad_size.props_per_key)[: self.keypad_size.props_per_key // 2]
|
||||||
key_permutation = np.random.permutation(self.keypad_size.numb_of_keys)
|
key_permutation = np.random.permutation(self.keypad_size.numb_of_keys)
|
||||||
keypad_view = self.keypad_matrix().copy()
|
# shuffle the selected property sets to new keys as a group
|
||||||
keypad_view[:, prop_permutation] = keypad_view[key_permutation, :][:, prop_permutation]
|
keypad_view[:, prop_permutation] = keypad_view[key_permutation, :][:, prop_permutation]
|
||||||
self.keypad = keypad_view.reshape(-1)
|
self.keypad = keypad_view.reshape(-1)
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from src.models import KeypadSize
|
|||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def user_keypad():
|
def user_keypad():
|
||||||
return UserKeypad.create(keypad_size=KeypadSize(props_per_key=8, numb_of_keys=8))
|
return UserKeypad.create(keypad_size=KeypadSize(props_per_key=5, numb_of_keys=5))
|
||||||
|
|
||||||
|
|
||||||
def test_dispersion(user_keypad):
|
def test_dispersion(user_keypad):
|
||||||
@@ -25,8 +25,11 @@ def test_shuffle_props(user_keypad):
|
|||||||
- the order in which the cipher move from key to key is random (i.e. the distance traveled is uniform)
|
- the order in which the cipher move from key to key is random (i.e. the distance traveled is uniform)
|
||||||
"""
|
"""
|
||||||
pre_shuffle_keypad = user_keypad.keypad.copy()
|
pre_shuffle_keypad = user_keypad.keypad.copy()
|
||||||
|
print("")
|
||||||
|
print(user_keypad.keypad_matrix())
|
||||||
user_keypad.split_shuffle()
|
user_keypad.split_shuffle()
|
||||||
post_shuffle_keypad = user_keypad.keypad.copy()
|
post_shuffle_keypad = user_keypad.keypad.copy()
|
||||||
|
print(user_keypad.keypad_matrix())
|
||||||
assert (not all(
|
assert (not all(
|
||||||
post_shuffle_keypad[idx] == pre_shuffle_keypad[idx] for idx in range(len(post_shuffle_keypad))
|
post_shuffle_keypad[idx] == pre_shuffle_keypad[idx] for idx in range(len(post_shuffle_keypad))
|
||||||
))
|
))
|
||||||
|
|||||||
Reference in New Issue
Block a user