diff --git a/sp_network_algebra_tutorial.ipynb b/sp_network_algebra_tutorial.ipynb index 1e4887d..c36a1ab 100644 --- a/sp_network_algebra_tutorial.ipynb +++ b/sp_network_algebra_tutorial.ipynb @@ -12,7 +12,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 82, "outputs": [], "source": [ "from src.models import OuterKey, InnerKey, SubstitutionKey" @@ -20,8 +20,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T16:38:57.906547Z", - "start_time": "2024-07-03T16:38:57.867931Z" + "end_time": "2024-07-03T17:15:30.365133Z", + "start_time": "2024-07-03T17:15:30.328857Z" } } }, @@ -40,7 +40,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 83, "outputs": [], "source": [ "height = 4\n", @@ -49,8 +49,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T16:38:57.907029Z", - "start_time": "2024-07-03T16:38:57.872544Z" + "end_time": "2024-07-03T17:15:30.365712Z", + "start_time": "2024-07-03T17:15:30.332512Z" } } }, @@ -67,13 +67,13 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 84, "outputs": [ { "data": { - "text/plain": "[[2, 0, 1], [0, 2, 1], [0, 2, 1], [1, 2, 0]]" + "text/plain": "[[1, 2, 0], [0, 1, 2], [2, 1, 0], [2, 0, 1]]" }, - "execution_count": 37, + "execution_count": 84, "metadata": {}, "output_type": "execute_result" } @@ -88,8 +88,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T16:38:57.907507Z", - "start_time": "2024-07-03T16:38:57.876023Z" + "end_time": "2024-07-03T17:15:30.366169Z", + "start_time": "2024-07-03T17:15:30.335990Z" } } }, @@ -105,13 +105,13 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 85, "outputs": [ { "data": { - "text/plain": "[[3, 2, 1, 0]]" + "text/plain": "[[1, 2, 3, 0]]" }, - "execution_count": 38, + "execution_count": 85, "metadata": {}, "output_type": "execute_result" } @@ -126,8 +126,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T16:38:57.954081Z", - "start_time": "2024-07-03T16:38:57.880359Z" + "end_time": "2024-07-03T17:15:30.405313Z", + "start_time": "2024-07-03T17:15:30.341422Z" } } }, @@ -143,13 +143,13 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 106, "outputs": [ { "data": { - "text/plain": "[[21, 62, 42], [151, 171, 33], [31, 131, 141], [100, 202, 161]]" + "text/plain": "[[237, 92, 1], [165, 114, 152], [38, 71, 114], [52, 116, 61]]" }, - "execution_count": 39, + "execution_count": 106, "metadata": {}, "output_type": "execute_result" } @@ -157,13 +157,14 @@ "source": [ "a0 = SubstitutionKey.init_matrix(width, height)\n", "a1 = SubstitutionKey.init_matrix(width, height)\n", + "\n", "a0.matrix" ], "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T16:38:57.954770Z", - "start_time": "2024-07-03T16:38:57.884556Z" + "end_time": "2024-07-03T17:26:59.359984Z", + "start_time": "2024-07-03T17:26:59.355497Z" } } }, @@ -171,7 +172,8 @@ "cell_type": "markdown", "source": [ "## Operators Types\n", - "### ***<<*** Inner Permutation" + "### ***<*** Outer Permutation\n", + "#### Substitution Key < Outer Key" ], "metadata": { "collapsed": false @@ -179,21 +181,36 @@ }, { "cell_type": "code", - "execution_count": 39, - "outputs": [], - "source": [], + "execution_count": 107, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[1, 2, 3, 0]]\n", + "[[237, 92, 1], [165, 114, 152], [38, 71, 114], [52, 116, 61]]\n", + "[[165, 114, 152], [38, 71, 114], [52, 116, 61], [237, 92, 1]]\n" + ] + } + ], + "source": [ + "a0_o0 = a0 < o0\n", + "print(o0.matrix)\n", + "print(a0.matrix)\n", + "print(a0_o0.matrix)" + ], "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T16:38:57.955162Z", - "start_time": "2024-07-03T16:38:57.887640Z" + "end_time": "2024-07-03T17:27:00.733689Z", + "start_time": "2024-07-03T17:27:00.729585Z" } } }, { "cell_type": "markdown", "source": [ - "### ***<*** Outer Permutation" + "#### Inner Key < Outer Key" ], "metadata": { "collapsed": false @@ -201,21 +218,37 @@ }, { "cell_type": "code", - "execution_count": 39, - "outputs": [], - "source": [], + "execution_count": 108, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[1, 2, 3, 0]]\n", + "[[1, 2, 0], [0, 1, 2], [2, 1, 0], [2, 0, 1]]\n", + "[[0, 1, 2], [2, 1, 0], [2, 0, 1], [1, 2, 0]]\n" + ] + } + ], + "source": [ + "i0_o0 = i0 < o0\n", + "print(o0.matrix)\n", + "print(i0.matrix)\n", + "print(i0_o0.matrix)" + ], "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T16:38:57.955526Z", - "start_time": "2024-07-03T16:38:57.890158Z" + "end_time": "2024-07-03T17:27:04.433733Z", + "start_time": "2024-07-03T17:27:04.429380Z" } } }, { "cell_type": "markdown", "source": [ - "### ***^*** Substitution" + "### ***<<*** Inner Permutation\n", + "#### Outer Key << OuterKey" ], "metadata": { "collapsed": false @@ -223,14 +256,143 @@ }, { "cell_type": "code", - "execution_count": 39, - "outputs": [], - "source": [], + "execution_count": 109, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[2, 1, 3, 0]]\n", + "[[1, 2, 3, 0]]\n", + "[[3, 2, 0, 1]]\n" + ] + } + ], + "source": [ + "o0_o1 = o0 << o1\n", + "print(o1.matrix)\n", + "print(o0.matrix)\n", + "print(o0_o1.matrix)" + ], "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T16:38:57.957721Z", - "start_time": "2024-07-03T16:38:57.892476Z" + "end_time": "2024-07-03T17:27:08.293098Z", + "start_time": "2024-07-03T17:27:08.288126Z" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "#### Inner Key << Inner Key" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 110, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[0, 1, 2], [0, 2, 1], [0, 1, 2], [2, 1, 0]]\n", + "[[1, 2, 0], [0, 1, 2], [2, 1, 0], [2, 0, 1]]\n", + "[[1, 2, 0], [0, 2, 1], [2, 1, 0], [1, 0, 2]]\n" + ] + } + ], + "source": [ + "i0_i1 = i0 << i1\n", + "print(i1.matrix)\n", + "print(i0.matrix)\n", + "print(i0_i1.matrix)" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-07-03T17:27:11.574355Z", + "start_time": "2024-07-03T17:27:11.568652Z" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "#### Substitution Key << Inner Key" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 111, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[1, 2, 0], [0, 1, 2], [2, 1, 0], [2, 0, 1]]\n", + "[[237, 92, 1], [165, 114, 152], [38, 71, 114], [52, 116, 61]]\n", + "[[92, 1, 237], [165, 114, 152], [114, 71, 38], [61, 52, 116]]\n" + ] + } + ], + "source": [ + "a0_i0 = a0 << i0\n", + "print(i0.matrix)\n", + "print(a0.matrix)\n", + "print(a0_i0.matrix)" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-07-03T17:27:14.277217Z", + "start_time": "2024-07-03T17:27:14.272132Z" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "### ***^*** Substitution\n", + "#### Substitution Key ^ Substitution Key" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 114, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[237, 92, 1], [165, 114, 152], [38, 71, 114], [52, 116, 61]]\n", + "[[184, 159, 115], [199, 221, 35], [158, 70, 86], [74, 43, 129]]\n", + "[[85, 195, 114], [98, 175, 187], [184, 1, 36], [126, 95, 188]]\n", + "85\n" + ] + } + ], + "source": [ + "a0_a1 = a0 ^ a1\n", + "print(a0.matrix)\n", + "print(a1.matrix)\n", + "print(a0_a1.matrix)\n", + "print(a0.matrix[0][0] ^ a1.matrix[0][0])" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-07-03T17:29:15.922958Z", + "start_time": "2024-07-03T17:29:15.915126Z" } } }, @@ -245,13 +407,13 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 88, "outputs": [ { "data": { "text/plain": "True" }, - "execution_count": 40, + "execution_count": 88, "metadata": {}, "output_type": "execute_result" } @@ -265,20 +427,20 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T16:38:57.957791Z", - "start_time": "2024-07-03T16:38:57.896696Z" + "end_time": "2024-07-03T17:15:30.408639Z", + "start_time": "2024-07-03T17:15:30.361902Z" } } }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 89, "outputs": [ { "data": { "text/plain": "True" }, - "execution_count": 41, + "execution_count": 89, "metadata": {}, "output_type": "execute_result" } @@ -291,20 +453,20 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T16:38:57.958249Z", - "start_time": "2024-07-03T16:38:57.900751Z" + "end_time": "2024-07-03T17:15:30.408838Z", + "start_time": "2024-07-03T17:15:30.365269Z" } } }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 90, "outputs": [ { "data": { "text/plain": "True" }, - "execution_count": 42, + "execution_count": 90, "metadata": {}, "output_type": "execute_result" } @@ -317,20 +479,20 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T16:38:57.958404Z", - "start_time": "2024-07-03T16:38:57.903708Z" + "end_time": "2024-07-03T17:15:30.408892Z", + "start_time": "2024-07-03T17:15:30.368768Z" } } }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 91, "outputs": [ { "data": { "text/plain": "True" }, - "execution_count": 50, + "execution_count": 91, "metadata": {}, "output_type": "execute_result" } @@ -341,20 +503,20 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T16:42:45.756613Z", - "start_time": "2024-07-03T16:42:45.746766Z" + "end_time": "2024-07-03T17:15:30.408977Z", + "start_time": "2024-07-03T17:15:30.371377Z" } } }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 92, "outputs": [ { "data": { "text/plain": "True" }, - "execution_count": 44, + "execution_count": 92, "metadata": {}, "output_type": "execute_result" } @@ -368,20 +530,20 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T16:38:57.958613Z", - "start_time": "2024-07-03T16:38:57.910939Z" + "end_time": "2024-07-03T17:15:30.409076Z", + "start_time": "2024-07-03T17:15:30.375604Z" } } }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 93, "outputs": [ { "data": { "text/plain": "True" }, - "execution_count": 49, + "execution_count": 93, "metadata": {}, "output_type": "execute_result" } @@ -392,20 +554,20 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T16:41:01.725294Z", - "start_time": "2024-07-03T16:41:01.718345Z" + "end_time": "2024-07-03T17:15:30.409139Z", + "start_time": "2024-07-03T17:15:30.378496Z" } } }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 94, "outputs": [ { "data": { "text/plain": "True" }, - "execution_count": 46, + "execution_count": 94, "metadata": {}, "output_type": "execute_result" } @@ -421,8 +583,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T16:38:57.958859Z", - "start_time": "2024-07-03T16:38:57.915888Z" + "end_time": "2024-07-03T17:15:30.409210Z", + "start_time": "2024-07-03T17:15:30.381727Z" } } }, @@ -438,13 +600,13 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 95, "outputs": [ { "data": { "text/plain": "True" }, - "execution_count": 47, + "execution_count": 95, "metadata": {}, "output_type": "execute_result" } @@ -455,8 +617,8 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-07-03T16:38:57.958925Z", - "start_time": "2024-07-03T16:38:57.920831Z" + "end_time": "2024-07-03T17:15:30.409260Z", + "start_time": "2024-07-03T17:15:30.384147Z" } } }