diff --git a/notebooks/nkode_tutorial.ipynb b/notebooks/nkode_tutorial.ipynb index f53c722..4557afa 100644 --- a/notebooks/nkode_tutorial.ipynb +++ b/notebooks/nkode_tutorial.ipynb @@ -30,12 +30,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2025-03-20T10:38:44.577863Z", - "start_time": "2025-03-20T10:38:44.572040Z" + "end_time": "2025-03-20T12:00:21.292663Z", + "start_time": "2025-03-20T12:00:21.253426Z" } }, "outputs": [], - "execution_count": 75 + "execution_count": 2 }, { "cell_type": "code", @@ -53,12 +53,12 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2025-03-20T10:38:44.585583Z", - "start_time": "2025-03-20T10:38:44.582961Z" + "end_time": "2025-03-20T12:00:21.298357Z", + "start_time": "2025-03-20T12:00:21.296258Z" } }, "outputs": [], - "execution_count": 76 + "execution_count": 3 }, { "metadata": {}, @@ -75,10 +75,10 @@ "source": [ "#### Customer Cipher Keys\n", "Each customer has unique cipher keys.\n", - "These keys are used to encipher and decipher user nKode.\n", + "These keys are used to encipher and decipher a user's nKode.\n", "There are two types of Customer Cipher Keys:\n", "1. property key: Combined with the user property key to get the server-side representation of a users icons.\n", - "2. position key: Combined with the user position key to the server-side representation the position in each key.\n" + "2. position key: Combined with the user position key to get the server-side representation the position in each key.\n" ], "metadata": { "collapsed": false @@ -112,8 +112,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2025-03-20T10:38:44.601079Z", - "start_time": "2025-03-20T10:38:44.595017Z" + "end_time": "2025-03-20T12:00:21.317747Z", + "start_time": "2025-03-20T12:00:21.306163Z" } }, "outputs": [ @@ -121,30 +121,30 @@ "name": "stdout", "output_type": "stream", "text": [ - "Customer Position Key: [10895 31772 47823 53466 56263 49352]\n", + "Customer Position Key: [37938 42486 36680 47679 5944 46439]\n", "Customer Properties Key:\n", - "[32913 31208 39571 1116 2737 19900]\n", - "[ 4026 23392 64571 25864 56877 34756]\n", - "[56837 8582 51951 34890 37611 61978]\n", - "[55074 11623 3931 21342 53702 21700]\n", - "[26922 1472 49420 42668 7254 41918]\n", + "[14469 12272 54942 53713 60529 64319]\n", + "[49129 65121 60219 33860 48996 57925]\n", + "[61464 3328 59612 33957 62738 42039]\n", + "[ 3074 46306 41956 4712 59250 7730]\n", + "[23724 39640 530 27472 33903 26824]\n", "Position to Properties Map:\n", - "10895: [32913 4026 56837 55074 26922]\n", - "31772: [31208 23392 8582 11623 1472]\n", - "47823: [39571 64571 51951 3931 49420]\n", - "53466: [ 1116 25864 34890 21342 42668]\n", - "56263: [ 2737 56877 37611 53702 7254]\n", - "49352: [19900 34756 61978 21700 41918]\n" + "37938: [14469 49129 61464 3074 23724]\n", + "42486: [12272 65121 3328 46306 39640]\n", + "36680: [54942 60219 59612 41956 530]\n", + "47679: [53713 33860 33957 4712 27472]\n", + "5944: [60529 48996 62738 59250 33903]\n", + "46439: [64319 57925 42039 7730 26824]\n" ] } ], - "execution_count": 77 + "execution_count": 4 }, { "metadata": { "ExecuteTime": { - "end_time": "2025-03-20T10:38:44.612692Z", - "start_time": "2025-03-20T10:38:44.610267Z" + "end_time": "2025-03-20T12:00:21.325478Z", + "start_time": "2025-03-20T12:00:21.322970Z" } }, "cell_type": "code", @@ -161,41 +161,41 @@ "output_type": "stream", "text": [ "Position Value to Icons Map:\n", - "10895: ['😀' '🥺' '🤔' '🐱' '🦄']\n", - "31772: ['😂' '😡' '🙃' '🐶' '🌟']\n", - "47823: ['🥳' '😱' '😇' '🦁' '⚡']\n", - "53466: ['😍' '🤯' '🤖' '🐻' '🔥']\n", - "56263: ['🤓' '🥰' '👽' '🐸' '🍕']\n", - "49352: ['😎' '😴' '👾' '🐙' '🎉']\n" + "37938: ['😀' '🥺' '🤔' '🐱' '🦄']\n", + "42486: ['😂' '😡' '🙃' '🐶' '🌟']\n", + "36680: ['🥳' '😱' '😇' '🦁' '⚡']\n", + "47679: ['😍' '🤯' '🤖' '🐻' '🔥']\n", + "5944: ['🤓' '🥰' '👽' '🐸' '🍕']\n", + "46439: ['😎' '😴' '👾' '🐙' '🎉']\n" ] } ], - "execution_count": 78 + "execution_count": 5 }, { "metadata": {}, "cell_type": "markdown", "source": [ "### User Signup\n", - "Users can create an nkode with these steps:\n", + "Users can create an nKode with these steps:\n", "1. Generate a randomly shuffled keypad\n", "2. Set user nKode\n", "3. Confirm user nKode\n", "\n", "#### Generate Keypad\n", - " For the server to determine the users nkode, the user's keypad must be dispersable.\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 key positions so the number of properties per key is equal to the number of keys.\n", " In our case, the server drops 1 key position 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", " - each value in the keypad is the index value of a customer properties\n", - " - the user never learns what their server-side properties" + " - the user never learns their server-side properties" ] }, { "metadata": { "ExecuteTime": { - "end_time": "2025-03-20T10:38:44.636348Z", - "start_time": "2025-03-20T10:38:44.630660Z" + "end_time": "2025-03-20T12:00:21.349267Z", + "start_time": "2025-03-20T12:00:21.342655Z" } }, "cell_type": "code", @@ -223,11 +223,11 @@ "name": "stdout", "output_type": "stream", "text": [ - "Key 0: ['🐱' '🌟' '🤖' '🤓' '🎉']\n", - "Key 1: ['🥺' '🙃' '🔥' '🍕' '😎']\n", - "Key 2: ['🦄' '🐶' '🤯' '👽' '🐙']\n", - "Key 3: ['😀' '😂' '😍' '🥰' '😴']\n", - "Key 4: ['🤔' '😡' '🐻' '🐸' '👾']\n" + "Key 0: ['🐱' '🐶' '😱' '😍' '🍕']\n", + "Key 1: ['🦄' '😡' '⚡' '🤯' '🐸']\n", + "Key 2: ['😀' '🙃' '😇' '🔥' '👽']\n", + "Key 3: ['🥺' '😂' '🥳' '🐻' '🥰']\n", + "Key 4: ['🤔' '🌟' '🦁' '🤖' '🤓']\n" ] }, { @@ -244,11 +244,11 @@ "name": "stdout", "output_type": "stream", "text": [ - "Key 0: [18 25 15 4 29]\n", - "Key 1: [ 6 13 27 28 5]\n", - "Key 2: [24 19 9 16 23]\n", - "Key 3: [ 0 1 3 10 11]\n", - "Key 4: [12 7 21 22 17]\n" + "Key 0: [18 19 8 3 28]\n", + "Key 1: [24 7 26 9 22]\n", + "Key 2: [ 0 13 14 27 16]\n", + "Key 3: [ 6 1 2 21 10]\n", + "Key 4: [12 25 20 15 4]\n" ] }, { @@ -265,29 +265,29 @@ "name": "stdout", "output_type": "stream", "text": [ - "Key 0: [55074 1472 34890 2737 41918]\n", - "Key 1: [ 4026 8582 42668 7254 19900]\n", - "Key 2: [26922 11623 25864 37611 21700]\n", - "Key 3: [32913 31208 1116 56877 34756]\n", - "Key 4: [56837 23392 21342 53702 61978]\n" + "Key 0: [ 3074 46306 60219 53713 33903]\n", + "Key 1: [23724 65121 530 33860 59250]\n", + "Key 2: [14469 3328 59612 27472 62738]\n", + "Key 3: [49129 12272 54942 4712 48996]\n", + "Key 4: [61464 39640 41956 33957 60529]\n" ] } ], - "execution_count": 79 + "execution_count": 6 }, { "metadata": {}, "cell_type": "markdown", "source": [ - "## Set nKode\n", + "### Set nKode\n", "The client receives `user_icons`, `set_signup_keypad`\n" ] }, { "metadata": { "ExecuteTime": { - "end_time": "2025-03-20T10:38:44.674025Z", - "start_time": "2025-03-20T10:38:44.671302Z" + "end_time": "2025-03-20T12:00:21.372390Z", + "start_time": "2025-03-20T12:00:21.369564Z" } }, "cell_type": "code", @@ -306,20 +306,28 @@ "name": "stdout", "output_type": "stream", "text": [ - "User Passcode Indices: [28, 13, 9, 10]\n", - "User Passcode Icons: ['🍕' '🙃' '🤯' '🥰']\n", - "User Passcode Server-side properties: [ 7254 8582 25864 56877]\n", - "Selected Keys: [1, 1, 2, 3]\n" + "User Passcode Indices: [19, 28, 22, 18]\n", + "User Passcode Icons: ['🐶' '🍕' '🐸' '🐱']\n", + "User Passcode Server-side properties: [46306 33903 59250 3074]\n", + "Selected Keys: [0, 0, 1, 0]\n" ] } ], - "execution_count": 80 + "execution_count": 7 + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": [ + "### Confirm nKode\n", + "Submit the set key entry to render the confirm keypad." + ] }, { "metadata": { "ExecuteTime": { - "end_time": "2025-03-20T10:38:44.700525Z", - "start_time": "2025-03-20T10:38:44.697597Z" + "end_time": "2025-03-20T12:00:21.631111Z", + "start_time": "2025-03-20T12:00:21.391841Z" } }, "cell_type": "code", @@ -327,40 +335,71 @@ "confirm_keypad = api.set_nkode(username, customer_id, selected_keys_set, signup_session_id)\n", "keypad_view(confirm_keypad, keypad_size.numb_of_keys)\n", "selected_keys_confirm = select_keys_with_passcode_values(passcode_property_indices, confirm_keypad, keypad_size.numb_of_keys)\n", - "print(f\"Selected Keys\\n{selected_keys_confirm}\")" + "print(f\"Selected Keys\\n{selected_keys_confirm}\")\n", + "success = api.confirm_nkode(username, customer_id, selected_keys_confirm, signup_session_id)\n", + "assert success" ], "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Key 0: [ 6 7 3 4 23]\n", - "Key 1: [24 1 15 28 17]\n", - "Key 2: [12 25 27 16 11]\n", - "Key 3: [ 0 13 9 22 29]\n", - "Key 4: [18 19 21 10 5]\n", + "Key 0: [0 7 2 3 4]\n", + "Key 1: [ 6 25 26 27 28]\n", + "Key 2: [24 19 20 21 16]\n", + "Key 3: [12 13 8 9 10]\n", + "Key 4: [18 1 14 15 22]\n", "Selected Keys\n", - "[1, 3, 3, 4]\n" + "[2, 1, 4, 4]\n" ] } ], - "execution_count": 81 + "execution_count": 8 + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": "### Inferring an nKode selection" }, { "metadata": { "ExecuteTime": { - "end_time": "2025-03-20T10:38:44.947744Z", - "start_time": "2025-03-20T10:38:44.709897Z" + "end_time": "2025-03-20T12:08:59.799827Z", + "start_time": "2025-03-20T12:08:59.796887Z" } }, "cell_type": "code", "source": [ - "# the session is deleted after the nkode is confirmed. To rerun this cell, rerun the cells above starting with cell 8 where the username is created\n", - "success = api.confirm_nkode(username, customer_id, selected_keys_confirm, signup_session_id)\n", - "assert success" + "for idx in range(passcode_len):\n", + " selected_key_set = selected_keys_set[idx]\n", + " selected_set_key_idx = set_signup_keypad.reshape(-1, keypad_size.numb_of_keys)[selected_key_set]\n", + " print(f\"Set Key {idx}: {user_icons[selected_set_key_idx]}\")\n", + " selected_key_confirm = selected_keys_confirm[idx]\n", + " selected_confirm_key_idx = confirm_keypad.reshape(-1, keypad_size.numb_of_keys)[selected_key_confirm]\n", + " print(f\"Confirm Key {idx}: {user_icons[selected_confirm_key_idx]}\")\n", + " print(f\"Overlapping icon {user_icons[passcode_property_indices[idx]]}\")" ], - "outputs": [], - "execution_count": 82 + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Set Key 0: ['🐱' '🐶' '😱' '😍' '🍕']\n", + "Confirm Key 0: ['🦄' '🐶' '🦁' '🐻' '👽']\n", + "Overlapping icon 🐶\n", + "Set Key 1: ['🐱' '🐶' '😱' '😍' '🍕']\n", + "Confirm Key 1: ['🥺' '🌟' '⚡' '🔥' '🍕']\n", + "Overlapping icon 🍕\n", + "Set Key 2: ['🦄' '😡' '⚡' '🤯' '🐸']\n", + "Confirm Key 2: ['🐱' '😂' '😇' '🤖' '🐸']\n", + "Overlapping icon 🐸\n", + "Set Key 3: ['🐱' '🐶' '😱' '😍' '🍕']\n", + "Confirm Key 3: ['🐱' '😂' '😇' '🤖' '🐸']\n", + "Overlapping icon 🐱\n" + ] + } + ], + "execution_count": 15 }, { "metadata": {}, @@ -380,7 +419,7 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-03-20T10:38:44.959614Z", + "end_time": "2025-03-20T12:00:21.680780Z", "start_time": "2025-03-20T10:38:44.954840Z" } }, @@ -396,7 +435,7 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-03-20T10:38:44.968863Z", + "end_time": "2025-03-20T12:00:21.683788Z", "start_time": "2025-03-20T10:38:44.966571Z" } }, @@ -421,7 +460,7 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-03-20T10:38:44.985451Z", + "end_time": "2025-03-20T12:00:21.684015Z", "start_time": "2025-03-20T10:38:44.983449Z" } }, @@ -441,7 +480,7 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-03-20T10:38:45.007753Z", + "end_time": "2025-03-20T12:00:21.689867Z", "start_time": "2025-03-20T10:38:45.005712Z" } }, @@ -461,7 +500,7 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-03-20T10:38:45.026885Z", + "end_time": "2025-03-20T12:00:21.690242Z", "start_time": "2025-03-20T10:38:45.024649Z" } }, @@ -481,7 +520,7 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-03-20T10:38:45.041101Z", + "end_time": "2025-03-20T12:00:21.694701Z", "start_time": "2025-03-20T10:38:45.038985Z" } }, @@ -501,7 +540,7 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-03-20T10:38:45.059433Z", + "end_time": "2025-03-20T12:00:21.696066Z", "start_time": "2025-03-20T10:38:45.056942Z" } }, @@ -544,7 +583,7 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-03-20T10:38:45.070036Z", + "end_time": "2025-03-20T12:00:21.696415Z", "start_time": "2025-03-20T10:38:45.068009Z" } }, @@ -574,7 +613,7 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-03-20T10:38:45.320480Z", + "end_time": "2025-03-20T12:00:21.696640Z", "start_time": "2025-03-20T10:38:45.087096Z" } }, @@ -603,7 +642,7 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-03-20T10:38:45.559945Z", + "end_time": "2025-03-20T12:00:21.696764Z", "start_time": "2025-03-20T10:38:45.326214Z" } }, @@ -662,7 +701,7 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-03-20T10:38:45.570140Z", + "end_time": "2025-03-20T12:00:21.696874Z", "start_time": "2025-03-20T10:38:45.567396Z" } }, @@ -706,7 +745,7 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-03-20T10:38:45.809575Z", + "end_time": "2025-03-20T12:00:21.697134Z", "start_time": "2025-03-20T10:38:45.576610Z" } }, @@ -732,7 +771,7 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-03-20T10:38:46.286081Z", + "end_time": "2025-03-20T12:00:21.697273Z", "start_time": "2025-03-20T10:38:45.816688Z" } }, @@ -780,7 +819,7 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-03-20T10:38:46.296985Z", + "end_time": "2025-03-20T12:00:21.697386Z", "start_time": "2025-03-20T10:38:46.293584Z" } }, @@ -814,7 +853,7 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-03-20T10:38:46.312031Z", + "end_time": "2025-03-20T12:00:21.697503Z", "start_time": "2025-03-20T10:38:46.310019Z" } }, @@ -841,7 +880,7 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-03-20T10:38:46.553807Z", + "end_time": "2025-03-20T12:00:21.697608Z", "start_time": "2025-03-20T10:38:46.318482Z" } },