diff --git a/darc_substitution.ipynb b/darc_substitution.ipynb new file mode 100644 index 0000000..433094c --- /dev/null +++ b/darc_substitution.ipynb @@ -0,0 +1,92 @@ +{ + "cells": [ + { + "cell_type": "code", + "id": "initial_id", + "metadata": { + "collapsed": true, + "ExecuteTime": { + "end_time": "2024-08-02T22:22:16.261963Z", + "start_time": "2024-08-02T22:22:15.861856Z" + } + }, + "source": "from src.models import SubstitutionKey\n", + "outputs": [], + "execution_count": 2 + }, + { + "metadata": { + "ExecuteTime": { + "end_time": "2024-08-02T22:22:16.442689Z", + "start_time": "2024-08-02T22:22:16.434147Z" + } + }, + "cell_type": "code", + "source": [ + "width = 7\n", + "height = 10\n", + "s1 = SubstitutionKey.init_matrix(width, height)\n", + "s2 = SubstitutionKey.init_matrix(width, height)\n", + "s3 = SubstitutionKey.init_matrix(width, height)\n", + "\n", + "c1 = SubstitutionKey.init_matrix(width, height)\n", + "c2 = SubstitutionKey.init_matrix(width, height)\n", + "c3 = SubstitutionKey.init_matrix(width, height)\n", + "\n", + "m1 = SubstitutionKey.init_matrix(width, height)\n", + "m2 = SubstitutionKey.init_matrix(width, height)\n", + "m3 = SubstitutionKey.init_matrix(width, height)\n", + "m4 = SubstitutionKey.init_matrix(width, height)\n", + "m5 = SubstitutionKey.init_matrix(width, height)\n", + "\n", + "s_m1 = s1 ^ m4\n", + "c_m1 = c1 ^ m4\n", + "s_m4 = s1 ^ m5\n", + "c_m4 = c1 ^ m5\n", + "\n", + "m_c1 = SubstitutionKey.init_matrix(width, height)\n", + "m_s1 = SubstitutionKey.init_matrix(width, height) \n", + "\n", + "m_s2 = m1 ^ m_c1\n", + "m_c2 = m1 ^ m_s1\n", + "\n", + "s_m3 = m_s2 ^ s2 ^ m3\n", + "s_m2 = m1 ^ s2 ^ m2 ^ m_s1\n", + "c_m2 = m_c2 ^ c2 ^ m2\n", + "c_m3 = m1 ^ m_c1 ^ c2 ^ m3\n" + ], + "id": "58883d386ec57cc4", + "outputs": [], + "execution_count": 3 + }, + { + "metadata": {}, + "cell_type": "code", + "outputs": [], + "execution_count": null, + "source": "", + "id": "2e1b925a48925228" + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/spn_algebra_template.md b/docs/spn_algebra_template.md new file mode 100644 index 0000000..843ba4b --- /dev/null +++ b/docs/spn_algebra_template.md @@ -0,0 +1,278 @@ +# Permutation Algebra +This notebook is a prerequisite to following the DARC tutorial + + + +## Key Generation Parameters +- block size: The number of characters we encode in a block. Block size isn't using in this notebook +- key height: The alphabet length. If we want to encode bytes, our alphabet length is 256. + If we want to encode lowercase letters a-z our alphabet length is 26. NKodes {{ height }} key {{ width }} attribute alphabet is {{ total_attr }}. +- key width: The number of bytes an encrypted charter is in our alphabet. + +``` +height = {{ height }} +width = {{ width }} +``` + +## Operand Types +### Inner Permutation Key +An inner permutation key (inner key for short) is a list of `height` rows, each a random permutation of an identity array of length `width`. + +``` +i0 = InnerKey.init_matrix(width, height) +i1 = InnerKey.init_matrix(width, height) +i2 = InnerKey.init_matrix(width, height) +i_identity = InnerKey.init_identity_matrix(width, height) + +i0.matrix: +{% for row in i0.matrix -%} +{{ row }} +{% endfor %} + +i1.matrix: +{% for row in i1.matrix -%} +{{ row }} +{% endfor %} + +i2.matrix: +{% for row in i2.matrix -%} +{{ row }} +{% endfor %} + +i_identity.matrix: +{% for row in i_identity.matrix -%} +{{ row }} +{% endfor %} +``` + + +### Outer Permutation Key +An outer key is a list of `height` columns, each a random permutation of an identity array of length `height`. +It is used to permute the rows of inner, substitution and outer keys. + +``` +o0 = OuterKey.init_matrix(height) +o1 = OuterKey.init_matrix(height) +o2 = OuterKey.init_matrix(height) +o_identity = OuterKey.init_identity_matrix(height) + +o0.matrix: +{{ o0.matrix }} + +o1.matrix: +{{ o1.matrix }} + +o2.matrix: +{{ o2.matrix }} + +o_identity.matrix: +{{ o_identity.matrix }} +``` + +### Substitution Key +Substitution key is a matrix of `height` rows and `width` columns. Each row is a list of randomly generated bytes. + +``` +s0 = SubstitutionKey.init_matrix(width, height) +s1 = SubstitutionKey.init_matrix(width, height) +s2 = SubstitutionKey.init_matrix(width, height) +s_identity = SubstitutionKey.init_identity_matrix(width, height) + +s0.matrix: +{% for row in s0.matrix -%} +{{ row }} +{% endfor %} + +s1.matrix: +{% for row in s1.matrix -%} +{{ row }} +{% endfor %} + +s2.matrix: +{% for row in s2.matrix -%} +{{ row }} +{% endfor %} + +s_identity.matrix: +{% for row in s_identity.matrix -%} +{{ row }} +{% endfor %} +``` + + +## Operators Types +### < Outer Permutation +#### Substitution Key < Outer Key +``` +s0_o0 = s0 < o0 +``` + +| idx |s0|s0| s0_o0 | +|-----|-|-|-------| +{% for idx in range(height) -%} +|{{idx}}|{{ s0.matrix[idx] }}|{{ o0.matrix[0][idx] }}|{{ s0_o0.matrix[idx] }}| +{% endfor %} + +#### Inner Key < Outer Key +i0_o0 = i0 < o0 + +| idx | i0 | o0 | i0_o0 | +|-----|----|----|-------| +{% for idx in range(height) -%} +|{{idx}}|{{ i0.matrix[idx] }}|{{ o0.matrix[0][idx] }}|{{ i0_o0.matrix[idx] }}| +{% endfor %} + +### << Inner Permutation +#### Outer Key << Outer Key +o0_o1 = o0 << o1 + +| idx | o0 | o1 | o0_o1 | +|-----|----|----|-------| +{% for idx in range(height) -%} +|{{idx}}|{{ o0.matrix[0][idx] }}|{{ o1.matrix[0][idx] }}|{{ o0_o1.matrix[0][idx] }}| +{% endfor %} + +#### Inner Key << Inner Key +i0_i1 = i0 << i1 + +| idx | i0 | i1 | i0_i1 | +|-----|----------------------------------------------------------|----|-------| +{% for idx in range(height) -%} +|{{idx}}|{{ i0.matrix[idx] }}|{{ i1.matrix[idx] }}|{{ i0_i1.matrix[idx] }}| +{% endfor %} + +#### Substitution Key << Inner Key +s0_i0 = s0 << i0 + +| idx | s0 | i0 | s0_i0 | +|-----|----|----|-------| +{% for idx in range(height) -%} +|{{idx}}|{{ s0.matrix[idx] }}|{{ i0.matrix[idx] }}|{{ s0_i0.matrix[idx] }}| +{% endfor %} + +### ~Permutation Inversion +#### ~Outer Key +inv_o0 = ~o0 + +| idx | o0 | ~o0 | +|-----|----|-----| +{% for idx in range(height) -%} +|{{idx}}|{{ o0.matrix[0][idx] }}|{{ inv_o0.matrix[0][idx] }}| +{% endfor %} + + +#### ~Inner Key +inv_i0 = ~i0 + +| idx | i0 | ~i0 | +|-----|----|-----| +{% for idx in range(height) -%} +|{{idx}}|{{ i0.matrix[idx] }}|{{ inv_i0.matrix[idx] }}| +{% endfor %} + +### ^ Substitution +#### Substitution Key ^ Substitution Key +s0_s1 = s0 ^ s1 + +| idx | s0 | s1 | s0_s1 | +|-----|----|----|-------| +{% for idx in range(height) -%} +|{{idx}}|{{ s0.matrix[idx] }}|{{ s1.matrix[idx] }}|{{ s0_s1.matrix[idx] }}| +{% endfor %} + +## Substitution Permutation Algebra +#### properites: +- associative: (a + b) + c = a + (b + c) +- commutative: a + b = b + a +- identity: a + 0 = a or a * 1 = a +- inverse: a + (-a) = 0 or a * 1/a = 1 (for all a ~= 0) +- distributive: a(b + c) = ab + ac + +### Associative +#### Outer Key +``` +(o0 << o1 << o2) == ((o0 << o1) << o2) == (o0 << (o1 << o2)) +``` +#### Inner Key +``` +(i0 << i1 << i2) == ((i0 << i1) << i2) == (i0 << (i1 << i2)) +``` + +#### Substitution Key +``` +(s0 ^ s1 ^ s2) == ((s0 ^ s1) ^ s2) == (s0 ^ (s1 ^ s2)) +``` + +### Commutative Property +Substitution is the only key type that is commutative + +#### Substitution Key +``` +(s0 ^ s1) == (s1 ^ s0) +``` + +### Identity Property +#### Outer Key +``` +(o0 << o_identity) == o0 +``` + +#### Inner Key +``` +(i0 << i_identity) == i0 +``` + +#### Substitution Key +``` +(s0 ^ s_identity) == s0 +``` + +### Inverse Property +#### Outer Key +``` +(o0 << ~o0) == o_identity +``` + +#### Inner Key +``` +(i0 << ~i0) == i_identity +``` + +#### Substitution Key +``` +(s0 ^ s0) == s_identity +``` + +### Distributive +#### Inner Key/Outer Key +``` +((i0 << i1) < o0) == ((i0 < o0) << (i1 < o0)) +``` + +#### Substitution Key/Outer Key +``` +((s0 ^ s1) < o0) == ((s0 < o0) ^ (s1 < o0)) +``` +#### Substitution Key/Inner Key +``` +((s0 ^ s1) << i0) == ((s0 << i0) ^ (s1 << i0)) +``` +#### Substitution Key/Inner Key/Outer Key +``` +((s0 << i0) < o0) == ((s0 < o0) << (i0 < o0)) +``` +### Other Examples +``` +(s0 << (i0 < o0)) == (((s0 < ~o0) << i0) < o0) +((s0 < o0) << i0) == ((s0 << (i0 < ~o0)) < o0) +(~(i0 << i1)) == (~i1 << ~i0) +(~(o0 << o1)) == (~o1 << ~o0) +i0 == ((i0 << i2 << i1) << ~(i2 << i1)) == ((i0 << i2 << i1) << ~i1 << ~i2) +``` + +### Becareful about your order of operation +***Always use parenthesis to control the order of operation*** + +``` +i0 < (o0 << o1 << o2) != (i0 < (o0 << o1 << o2)) # not equal !!!!!! +``` diff --git a/render_markdown.py b/render_markdown.py new file mode 100644 index 0000000..5f0ad03 --- /dev/null +++ b/render_markdown.py @@ -0,0 +1,83 @@ +from jinja2 import Environment, FileSystemLoader +from src.models import OuterKey, InnerKey, SubstitutionKey + + +def render_spn_algebra(data: dict): + # Set up the Jinja2 environment and template loader + file_loader = FileSystemLoader('./docs') + env = Environment(loader=file_loader) + + # Load the template + template = env.get_template('spn_algebra_template.md') + # Render the template with the data + output = template.render(data) + + # Print or save the output + output_file = "/Users/donov/Desktop/NKode_documentation/nkode/docs/spn_algebra.md" + with open(output_file, 'w') as fp: + fp.write(output) + print("File written successfully") + + +if __name__ == "__main__": + height = 10 + width = 7 + total_attr = height * width + i0 = InnerKey.init_matrix(width, height) + i1 = InnerKey.init_matrix(width, height) + i2 = InnerKey.init_matrix(width, height) + i_identity = InnerKey.init_identity_matrix(width, height) + + o0 = OuterKey.init_matrix(height) + o1 = OuterKey.init_matrix(height) + o2 = OuterKey.init_matrix(height) + o_identity = OuterKey.init_identity_matrix(height) + + s0 = SubstitutionKey.init_matrix(width, height) + s1 = SubstitutionKey.init_matrix(width, height) + s2 = SubstitutionKey.init_matrix(width, height) + s_identity = SubstitutionKey.init_identity_matrix(width, height) + + s0_o0 = s0 < o0 + + i0_o0 = i0 < o0 + + o0_o1 = o0 << o1 + + i0_i1 = i0 << i1 + + s0_i0 = s0 << i0 + + inv_o0 = ~o0 + + inv_i0 = ~i0 + + s0_s1 = s0 ^ s1 + + data = { + 'height': height, + 'width': width, + 'total_attr': total_attr, + 'i0': i0, + 'i1': i1, + 'i2': i2, + 'i_identity': i_identity, + 'o0': o0, + 'o1': o1, + 'o2': o2, + 'o_identity': o_identity, + 's0': s0, + 's1': s1, + 's2': s2, + 's_identity': s_identity, + 's0_o0': s0_o0, + 'i0_o0': i0_o0, + 'o0_o1': o0_o1, + 'i0_i1': i0_i1, + 's0_i0': s0_i0, + 'inv_o0': inv_o0, + 'inv_i0': inv_i0, + 's0_s1': s0_s1 + } + + render_spn_algebra(data) diff --git a/sp_network_algebra_tutorial.ipynb b/sp_network_algebra_tutorial.ipynb index 132cfed..493f0e9 100644 --- a/sp_network_algebra_tutorial.ipynb +++ b/sp_network_algebra_tutorial.ipynb @@ -12,18 +12,14 @@ }, { "cell_type": "code", - "execution_count": 69, - "outputs": [], "source": [ "from src.models import OuterKey, InnerKey, SubstitutionKey" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.685220Z", - "start_time": "2024-07-04T14:12:16.446987Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -40,19 +36,15 @@ }, { "cell_type": "code", - "execution_count": 70, - "outputs": [], "source": [ "height = 4\n", "width = 3" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.686123Z", - "start_time": "2024-07-04T14:12:16.453332Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -67,17 +59,6 @@ }, { "cell_type": "code", - "execution_count": 71, - "outputs": [ - { - "data": { - "text/plain": "[[0, 1, 2], [1, 0, 2], [1, 0, 2], [2, 1, 0]]" - }, - "execution_count": 71, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ "i0 = InnerKey.init_matrix(width, height)\n", "i1 = InnerKey.init_matrix(width, height)\n", @@ -87,12 +68,10 @@ "i0.matrix" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.830392Z", - "start_time": "2024-07-04T14:12:16.460887Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -106,17 +85,6 @@ }, { "cell_type": "code", - "execution_count": 72, - "outputs": [ - { - "data": { - "text/plain": "[[2, 0, 1, 3]]" - }, - "execution_count": 72, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ "o0 = OuterKey.init_matrix(height)\n", "o1 = OuterKey.init_matrix(height)\n", @@ -126,17 +94,15 @@ "o0.matrix" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.831572Z", - "start_time": "2024-07-04T14:12:16.469310Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", "source": [ - "### Substitution Key (formerly Alphabet Key or alpha_key)\n", + "### Substitution Key\n", "Sub key is ..." ], "metadata": { @@ -145,32 +111,19 @@ }, { "cell_type": "code", - "execution_count": 73, - "outputs": [ - { - "data": { - "text/plain": "[[51, 14, 207], [3, 171, 4], [73, 204, 152], [142, 175, 64]]" - }, - "execution_count": 73, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ - "a0 = SubstitutionKey.init_matrix(width, height)\n", - "a1 = SubstitutionKey.init_matrix(width, height)\n", - "a2 = SubstitutionKey.init_matrix(width, height)\n", - "a_identity = SubstitutionKey.init_identity_matrix(width, height)\n", + "s0 = SubstitutionKey.init_matrix(width, height)\n", + "s1 = SubstitutionKey.init_matrix(width, height)\n", + "s2 = SubstitutionKey.init_matrix(width, height)\n", + "s_identity = SubstitutionKey.init_identity_matrix(width, height)\n", "\n", - "a0.matrix" + "s0.matrix" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.832461Z", - "start_time": "2024-07-04T14:12:16.476713Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -185,31 +138,17 @@ }, { "cell_type": "code", - "execution_count": 74, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[2, 0, 1, 3]]\n", - "[[51, 14, 207], [3, 171, 4], [73, 204, 152], [142, 175, 64]]\n", - "[[73, 204, 152], [51, 14, 207], [3, 171, 4], [142, 175, 64]]\n" - ] - } - ], "source": [ - "a0_o0 = a0 < o0\n", + "s0_o0 = s0 < o0\n", "print(o0.matrix)\n", - "print(a0.matrix)\n", - "print(a0_o0.matrix)" + "print(s0.matrix)\n", + "print(s0_o0.matrix)" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.833320Z", - "start_time": "2024-07-04T14:12:16.484335Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -222,18 +161,6 @@ }, { "cell_type": "code", - "execution_count": 75, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[2, 0, 1, 3]]\n", - "[[0, 1, 2], [1, 0, 2], [1, 0, 2], [2, 1, 0]]\n", - "[[1, 0, 2], [0, 1, 2], [1, 0, 2], [2, 1, 0]]\n" - ] - } - ], "source": [ "i0_o0 = i0 < o0\n", "print(o0.matrix)\n", @@ -241,12 +168,10 @@ "print(i0_o0.matrix)" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.834157Z", - "start_time": "2024-07-04T14:12:16.492114Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -260,18 +185,6 @@ }, { "cell_type": "code", - "execution_count": 76, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[0, 1, 3, 2]]\n", - "[[2, 0, 1, 3]]\n", - "[[2, 0, 3, 1]]\n" - ] - } - ], "source": [ "o0_o1 = o0 << o1\n", "print(o1.matrix)\n", @@ -279,12 +192,10 @@ "print(o0_o1.matrix)" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.834973Z", - "start_time": "2024-07-04T14:12:16.499677Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -297,18 +208,6 @@ }, { "cell_type": "code", - "execution_count": 77, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[1, 0, 2], [0, 1, 2], [0, 2, 1], [2, 1, 0]]\n", - "[[0, 1, 2], [1, 0, 2], [1, 0, 2], [2, 1, 0]]\n", - "[[1, 0, 2], [1, 0, 2], [1, 2, 0], [0, 1, 2]]\n" - ] - } - ], "source": [ "i0_i1 = i0 << i1\n", "print(i1.matrix)\n", @@ -316,12 +215,10 @@ "print(i0_i1.matrix)" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.835789Z", - "start_time": "2024-07-04T14:12:16.507413Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -334,31 +231,17 @@ }, { "cell_type": "code", - "execution_count": 78, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[0, 1, 2], [1, 0, 2], [1, 0, 2], [2, 1, 0]]\n", - "[[51, 14, 207], [3, 171, 4], [73, 204, 152], [142, 175, 64]]\n", - "[[51, 14, 207], [171, 3, 4], [204, 73, 152], [64, 175, 142]]\n" - ] - } - ], "source": [ - "a0_i0 = a0 << i0\n", + "s0_i0 = s0 << i0\n", "print(i0.matrix)\n", - "print(a0.matrix)\n", - "print(a0_i0.matrix)" + "print(s0.matrix)\n", + "print(s0_i0.matrix)" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.854289Z", - "start_time": "2024-07-04T14:12:16.515159Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -372,28 +255,15 @@ }, { "cell_type": "code", - "execution_count": 79, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[2, 0, 1, 3]]\n", - "[[1, 2, 0, 3]]\n" - ] - } - ], "source": [ "print(o0.matrix)\n", "print((~o0).matrix)" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.855384Z", - "start_time": "2024-07-04T14:12:16.522867Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -406,28 +276,15 @@ }, { "cell_type": "code", - "execution_count": 80, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[0, 1, 2], [1, 0, 2], [1, 0, 2], [2, 1, 0]]\n", - "[[0, 1, 2], [1, 0, 2], [1, 0, 2], [2, 1, 0]]\n" - ] - } - ], "source": [ "print(i0.matrix)\n", "print((~i0).matrix)" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.856225Z", - "start_time": "2024-07-04T14:12:16.530564Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -441,33 +298,18 @@ }, { "cell_type": "code", - "execution_count": 81, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[51, 14, 207], [3, 171, 4], [73, 204, 152], [142, 175, 64]]\n", - "[[1, 41, 28], [228, 126, 163], [255, 48, 188], [53, 120, 13]]\n", - "[[50, 39, 211], [231, 213, 167], [182, 252, 36], [187, 215, 77]]\n", - "50\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])" + "s0_s1 = s0 ^ s1\n", + "print(s0.matrix)\n", + "print(s1.matrix)\n", + "print(s0_s1.matrix)\n", + "print(s0.matrix[0][0] ^ s1.matrix[0][0])" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.857040Z", - "start_time": "2024-07-04T14:12:16.538722Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -489,27 +331,14 @@ }, { "cell_type": "code", - "execution_count": 82, - "outputs": [ - { - "data": { - "text/plain": "True" - }, - "execution_count": 82, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ "(o0 << o1 << o2) == ((o0 << o1) << o2) == (o0 << (o1 << o2))" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.858322Z", - "start_time": "2024-07-04T14:12:16.546322Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -522,27 +351,14 @@ }, { "cell_type": "code", - "execution_count": 83, - "outputs": [ - { - "data": { - "text/plain": "True" - }, - "execution_count": 83, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ "(i0 << i1 << i2) == ((i0 << i1) << i2) == (i0 << (i1 << i2))" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.863346Z", - "start_time": "2024-07-04T14:12:16.554187Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -555,27 +371,12 @@ }, { "cell_type": "code", - "execution_count": 84, - "outputs": [ - { - "data": { - "text/plain": "True" - }, - "execution_count": 84, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "(a0 ^ a1 ^ a2) == ((a0 ^ a1) ^ a2) == (a0 ^ (a1 ^ a2))" - ], + "source": "(s0 ^ s1 ^ s2) == ((s0 ^ s1) ^ s2) == (s0 ^ (s1 ^ s2))", "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.864336Z", - "start_time": "2024-07-04T14:12:16.562025Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -590,27 +391,12 @@ }, { "cell_type": "code", - "execution_count": 85, - "outputs": [ - { - "data": { - "text/plain": "True" - }, - "execution_count": 85, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "(a0 ^ a1) == (a1 ^ a0)" - ], + "source": "(s0 ^ s1) == (s1 ^ s0)", "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.865178Z", - "start_time": "2024-07-04T14:12:16.569781Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -624,27 +410,14 @@ }, { "cell_type": "code", - "execution_count": 86, - "outputs": [ - { - "data": { - "text/plain": "True" - }, - "execution_count": 86, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ "(o0 << o_identity) == o0" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.866342Z", - "start_time": "2024-07-04T14:12:16.578046Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -657,27 +430,14 @@ }, { "cell_type": "code", - "execution_count": 87, - "outputs": [ - { - "data": { - "text/plain": "True" - }, - "execution_count": 87, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ "(i0 << i_identity) == i0" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.867309Z", - "start_time": "2024-07-04T14:12:16.589133Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -690,27 +450,12 @@ }, { "cell_type": "code", - "execution_count": 88, - "outputs": [ - { - "data": { - "text/plain": "True" - }, - "execution_count": 88, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "(a0 ^ a_identity) == a0" - ], + "source": "(s0 ^ s_identity) == s0", "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.868143Z", - "start_time": "2024-07-04T14:12:16.599974Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -724,27 +469,14 @@ }, { "cell_type": "code", - "execution_count": 89, - "outputs": [ - { - "data": { - "text/plain": "True" - }, - "execution_count": 89, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ "(o0 << ~o0) == o_identity" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.868953Z", - "start_time": "2024-07-04T14:12:16.608436Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -757,27 +489,14 @@ }, { "cell_type": "code", - "execution_count": 90, - "outputs": [ - { - "data": { - "text/plain": "True" - }, - "execution_count": 90, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ "(i0 << ~i0) == i_identity" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.869884Z", - "start_time": "2024-07-04T14:12:16.619030Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -790,27 +509,12 @@ }, { "cell_type": "code", - "execution_count": 91, - "outputs": [ - { - "data": { - "text/plain": "True" - }, - "execution_count": 91, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "(a0 ^ a0) == a_identity" - ], + "source": "(s0 ^ s0) == s_identity", "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.870708Z", - "start_time": "2024-07-04T14:12:16.629750Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -824,27 +528,14 @@ }, { "cell_type": "code", - "execution_count": 92, - "outputs": [ - { - "data": { - "text/plain": "True" - }, - "execution_count": 92, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ "((i0 << i1) < o0) == ((i0 < o0) << (i1 < o0))" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.871520Z", - "start_time": "2024-07-04T14:12:16.638198Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -857,27 +548,12 @@ }, { "cell_type": "code", - "execution_count": 93, - "outputs": [ - { - "data": { - "text/plain": "True" - }, - "execution_count": 93, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "((a0 ^ a1) < o0) == ((a0 < o0) ^ (a1 < o0))" - ], + "source": "((s0 ^ s1) < o0) == ((s0 < o0) ^ (s1 < o0))", "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.872334Z", - "start_time": "2024-07-04T14:12:16.646323Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -890,27 +566,12 @@ }, { "cell_type": "code", - "execution_count": 94, - "outputs": [ - { - "data": { - "text/plain": "True" - }, - "execution_count": 94, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "((a0 ^ a1) << i0) == ((a0 << i0) ^ (a1 << i0))" - ], + "source": "((s0 ^ s1) << i0) == ((s0 << i0) ^ (s1 << i0))", "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.873134Z", - "start_time": "2024-07-04T14:12:16.654286Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -923,27 +584,12 @@ }, { "cell_type": "code", - "execution_count": 95, - "outputs": [ - { - "data": { - "text/plain": "True" - }, - "execution_count": 95, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "((a0 << i0) < o0) == ((a0 < o0) << (i0 < o0))" - ], + "source": "((s0 << i0) < o0) == ((s0 < o0) << (i0 < o0))", "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.874410Z", - "start_time": "2024-07-04T14:12:16.662231Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -956,123 +602,54 @@ }, { "cell_type": "code", - "execution_count": 96, - "outputs": [ - { - "data": { - "text/plain": "True" - }, - "execution_count": 96, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "(a0 << (i0 < o0)) == (((a0 < ~o0) << i0) < o0)" - ], + "source": "(s0 << (i0 < o0)) == (((s0 < ~o0) << i0) < o0)", "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.882191Z", - "start_time": "2024-07-04T14:12:16.670307Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "code", - "execution_count": 97, - "outputs": [ - { - "data": { - "text/plain": "True" - }, - "execution_count": 97, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "((a0 < o0) << i0) == ((a0 << (i0 < ~o0)) < o0)" - ], + "source": "((s0 < o0) << i0) == ((s0 << (i0 < ~o0)) < o0)", "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.882308Z", - "start_time": "2024-07-04T14:12:16.674096Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "code", - "execution_count": 98, - "outputs": [ - { - "data": { - "text/plain": "True" - }, - "execution_count": 98, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ "(~(i0 << i1)) == (~i1 << ~i0)" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.882394Z", - "start_time": "2024-07-04T14:12:16.677061Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "code", - "execution_count": 99, - "outputs": [ - { - "data": { - "text/plain": "True" - }, - "execution_count": 99, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ "(~(o0 << o1)) == (~o1 << ~o0)" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.883495Z", - "start_time": "2024-07-04T14:12:16.683278Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "code", - "execution_count": 100, - "outputs": [ - { - "data": { - "text/plain": "True" - }, - "execution_count": 100, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ "i0 == ((i0 << i2 << i1) << ~(i2 << i1)) == ((i0 << i2 << i1) << ~i1 << ~i2)" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.883574Z", - "start_time": "2024-07-04T14:12:16.687331Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null }, { "cell_type": "markdown", @@ -1086,27 +663,14 @@ }, { "cell_type": "code", - "execution_count": 101, - "outputs": [ - { - "data": { - "text/plain": "True" - }, - "execution_count": 101, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ "i0 < (o0 << o1 << o2) != (i0 < (o0 << o1 << o2)) # not equal !!!!!!" ], "metadata": { - "collapsed": false, - "ExecuteTime": { - "end_time": "2024-07-04T14:12:16.883645Z", - "start_time": "2024-07-04T14:12:16.690509Z" - } - } + "collapsed": false + }, + "outputs": [], + "execution_count": null } ], "metadata": {