remove medium identity matrix

This commit is contained in:
2024-07-04 14:33:40 -05:00
parent 8c0f4362ec
commit 9211a922fe
3 changed files with 67 additions and 75 deletions

View File

@@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 36, "execution_count": 121,
"outputs": [], "outputs": [],
"source": [ "source": [
"from src.models import SubstitutionKey, OuterKey, Mask, ServerKeys, MutualKeys, ClientKeys\n", "from src.models import SubstitutionKey, OuterKey, Mask, ServerKeys, MutualKeys, ClientKeys\n",
@@ -11,14 +11,14 @@
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2024-07-04T18:05:07.552043Z", "end_time": "2024-07-04T19:31:39.644601Z",
"start_time": "2024-07-04T18:05:07.542908Z" "start_time": "2024-07-04T19:31:39.628805Z"
} }
} }
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 37, "execution_count": 122,
"outputs": [], "outputs": [],
"source": [ "source": [
"def create_random_message(message_len, height):\n", "def create_random_message(message_len, height):\n",
@@ -28,14 +28,14 @@
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2024-07-04T18:05:07.552147Z", "end_time": "2024-07-04T19:31:39.644729Z",
"start_time": "2024-07-04T18:05:07.546164Z" "start_time": "2024-07-04T19:31:39.630714Z"
} }
} }
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 38, "execution_count": 123,
"outputs": [], "outputs": [],
"source": [ "source": [
"height = 70\n", "height = 70\n",
@@ -46,14 +46,14 @@
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2024-07-04T18:05:07.552308Z", "end_time": "2024-07-04T19:31:39.645110Z",
"start_time": "2024-07-04T18:05:07.549140Z" "start_time": "2024-07-04T19:31:39.634024Z"
} }
} }
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 39, "execution_count": 124,
"outputs": [], "outputs": [],
"source": [ "source": [
"server_substitution_data = SubstitutionKey.init_matrix(width, height)\n", "server_substitution_data = SubstitutionKey.init_matrix(width, height)\n",
@@ -77,20 +77,19 @@
"client_keys.persistent.data.alpha_key = client_substitution_data\n", "client_keys.persistent.data.alpha_key = client_substitution_data\n",
"client_keys.persistent.medium.alpha_key = client_substitution_medium\n", "client_keys.persistent.medium.alpha_key = client_substitution_medium\n",
"\n", "\n",
"alphabet = SubstitutionKey.init_matrix(width, height, 255)\n", "alphabet = SubstitutionKey.init_matrix(width, height, 255)"
"medium = SubstitutionKey(matrix=[[0 for _ in range(width)] for _ in range(height)])"
], ],
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2024-07-04T18:05:07.580066Z", "end_time": "2024-07-04T19:31:39.666246Z",
"start_time": "2024-07-04T18:05:07.553448Z" "start_time": "2024-07-04T19:31:39.638300Z"
} }
} }
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 40, "execution_count": 125,
"outputs": [], "outputs": [],
"source": [ "source": [
"sdi1 = server_keys.persistent.data.inner_key_1 << server_keys.ephemeral.data.inner_key_1\n", "sdi1 = server_keys.persistent.data.inner_key_1 << server_keys.ephemeral.data.inner_key_1\n",
@@ -134,14 +133,14 @@
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2024-07-04T18:05:07.593317Z", "end_time": "2024-07-04T19:31:39.676976Z",
"start_time": "2024-07-04T18:05:07.587709Z" "start_time": "2024-07-04T19:31:39.672058Z"
} }
} }
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 41, "execution_count": 126,
"outputs": [], "outputs": [],
"source": [ "source": [
"cdo1_cdo2 = cdo1 << cdo2\n", "cdo1_cdo2 = cdo1 << cdo2\n",
@@ -152,14 +151,14 @@
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2024-07-04T18:05:07.593468Z", "end_time": "2024-07-04T19:31:39.677097Z",
"start_time": "2024-07-04T18:05:07.590552Z" "start_time": "2024-07-04T19:31:39.674721Z"
} }
} }
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 42, "execution_count": 127,
"outputs": [], "outputs": [],
"source": [ "source": [
"m_func_1 = lambda x: (x < mdo1) << (mdi1 < mdo2)\n", "m_func_1 = lambda x: (x < mdo1) << (mdi1 < mdo2)\n",
@@ -171,35 +170,35 @@
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2024-07-04T18:05:07.595183Z", "end_time": "2024-07-04T19:31:39.679186Z",
"start_time": "2024-07-04T18:05:07.593423Z" "start_time": "2024-07-04T19:31:39.677255Z"
} }
} }
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 43, "execution_count": 128,
"outputs": [], "outputs": [],
"source": [ "source": [
"medium_phase1 = medium ^ m_func_2(spma ^ sema)" "medium_phase1 = m_func_2(spma ^ sema)"
], ],
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2024-07-04T18:05:07.598748Z", "end_time": "2024-07-04T19:31:39.682789Z",
"start_time": "2024-07-04T18:05:07.596986Z" "start_time": "2024-07-04T19:31:39.681048Z"
} }
} }
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 52, "execution_count": 129,
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": "True" "text/plain": "True"
}, },
"execution_count": 52, "execution_count": 129,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -214,7 +213,6 @@
"medium_phase2 == (\n", "medium_phase2 == (\n",
" (\n", " (\n",
" (\n", " (\n",
" medium ^\n",
" m_func_2(server_substitution_medium ^ sema ^ cema)\n", " m_func_2(server_substitution_medium ^ sema ^ cema)\n",
" ) << (cmi1 < mmo3)\n", " ) << (cmi1 < mmo3)\n",
" ) < cmo1_cmo2\n", " ) < cmo1_cmo2\n",
@@ -223,20 +221,20 @@
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2024-07-04T18:05:42.393236Z", "end_time": "2024-07-04T19:31:39.697827Z",
"start_time": "2024-07-04T18:05:42.389787Z" "start_time": "2024-07-04T19:31:39.687941Z"
} }
} }
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 59, "execution_count": 130,
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": "True" "text/plain": "True"
}, },
"execution_count": 59, "execution_count": 130,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -248,7 +246,6 @@
" ) << (mpmi2 < mmo3) < cmo1_cmo2\n", " ) << (mpmi2 < mmo3) < cmo1_cmo2\n",
"\n", "\n",
"medium_phase3 == ((\n", "medium_phase3 == ((\n",
" medium ^\n",
" m_func_2(server_substitution_medium ^ sema ^ cpma ^ mema)\n", " m_func_2(server_substitution_medium ^ sema ^ cpma ^ mema)\n",
" ) << (mpmi2 < mmo3) < cmo1_cmo2\n", " ) << (mpmi2 < mmo3) < cmo1_cmo2\n",
")" ")"
@@ -256,14 +253,14 @@
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2024-07-04T18:16:20.923343Z", "end_time": "2024-07-04T19:31:39.712580Z",
"start_time": "2024-07-04T18:16:20.920280Z" "start_time": "2024-07-04T19:31:39.696392Z"
} }
} }
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 46, "execution_count": 131,
"outputs": [], "outputs": [],
"source": [ "source": [
"translated_alphabet = (\n", "translated_alphabet = (\n",
@@ -279,20 +276,20 @@
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2024-07-04T18:05:07.665047Z", "end_time": "2024-07-04T19:31:39.712704Z",
"start_time": "2024-07-04T18:05:07.639926Z" "start_time": "2024-07-04T19:31:39.704054Z"
} }
} }
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 62, "execution_count": 132,
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": "True" "text/plain": "True"
}, },
"execution_count": 62, "execution_count": 132,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -313,20 +310,20 @@
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2024-07-04T18:29:06.076785Z", "end_time": "2024-07-04T19:31:39.727975Z",
"start_time": "2024-07-04T18:29:06.071174Z" "start_time": "2024-07-04T19:31:39.712372Z"
} }
} }
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 72, "execution_count": 133,
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": "True" "text/plain": "True"
}, },
"execution_count": 72, "execution_count": 133,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -347,14 +344,14 @@
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2024-07-04T18:40:21.743276Z", "end_time": "2024-07-04T19:31:39.742787Z",
"start_time": "2024-07-04T18:40:21.739864Z" "start_time": "2024-07-04T19:31:39.721754Z"
} }
} }
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 47, "execution_count": 134,
"outputs": [], "outputs": [],
"source": [ "source": [
"eof_msg_mask = Mask.init_matrix(width, height, message_len)\n", "eof_msg_mask = Mask.init_matrix(width, height, message_len)\n",
@@ -365,20 +362,20 @@
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2024-07-04T18:05:07.678354Z", "end_time": "2024-07-04T19:31:39.742960Z",
"start_time": "2024-07-04T18:05:07.643198Z" "start_time": "2024-07-04T19:31:39.726783Z"
} }
} }
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 75, "execution_count": 135,
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": "True" "text/plain": "True"
}, },
"execution_count": 75, "execution_count": 135,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -392,7 +389,6 @@
"darc_message == (\n", "darc_message == (\n",
" ((\n", " ((\n",
" ((\n", " ((\n",
" medium ^\n",
" m_func_2(server_substitution_medium ^ sema ^ cpma ^ mema)\n", " m_func_2(server_substitution_medium ^ sema ^ cpma ^ mema)\n",
" ) << (mpmi2 < mmo3)) ^\n", " ) << (mpmi2 < mmo3)) ^\n",
" (((((\n", " (((((\n",
@@ -405,20 +401,20 @@
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2024-07-04T18:46:10.473478Z", "end_time": "2024-07-04T19:31:39.743236Z",
"start_time": "2024-07-04T18:46:10.457255Z" "start_time": "2024-07-04T19:31:39.739866Z"
} }
} }
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 102, "execution_count": 136,
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": "True" "text/plain": "True"
}, },
"execution_count": 102, "execution_count": 136,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -434,14 +430,14 @@
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2024-07-04T19:21:34.911369Z", "end_time": "2024-07-04T19:31:39.761839Z",
"start_time": "2024-07-04T19:21:34.908479Z" "start_time": "2024-07-04T19:31:39.748041Z"
} }
} }
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 49, "execution_count": 137,
"outputs": [], "outputs": [],
"source": [ "source": [
"orignal_message = resolve_message(translated_alphabet, unwrapped_medium)" "orignal_message = resolve_message(translated_alphabet, unwrapped_medium)"
@@ -449,20 +445,20 @@
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2024-07-04T18:05:07.678472Z", "end_time": "2024-07-04T19:31:39.761929Z",
"start_time": "2024-07-04T18:05:07.656814Z" "start_time": "2024-07-04T19:31:39.751011Z"
} }
} }
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 50, "execution_count": 138,
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": "True" "text/plain": "True"
}, },
"execution_count": 50, "execution_count": 138,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -473,8 +469,8 @@
"metadata": { "metadata": {
"collapsed": false, "collapsed": false,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2024-07-04T18:05:07.678731Z", "end_time": "2024-07-04T19:31:39.761994Z",
"start_time": "2024-07-04T18:05:07.659154Z" "start_time": "2024-07-04T19:31:39.753450Z"
} }
} }
} }

View File

@@ -5,7 +5,7 @@ from src.models import (
) )
def darc_phase1(alphabet: SubstitutionKey, medium: SubstitutionKey, server_keys: ServerKeys, mutual_keys: MutualKeys): def darc_phase1(alphabet: SubstitutionKey, server_keys: ServerKeys, mutual_keys: MutualKeys):
alphabet_phase1 = translate_data( alphabet_phase1 = translate_data(
alphabet, alphabet,
server_keys.persistent.data, server_keys.persistent.data,
@@ -14,7 +14,6 @@ def darc_phase1(alphabet: SubstitutionKey, medium: SubstitutionKey, server_keys:
mutual_keys.ephemeral.data mutual_keys.ephemeral.data
) )
medium_phase1 = translate_medium( medium_phase1 = translate_medium(
medium,
server_keys.persistent.medium, server_keys.persistent.medium,
server_keys.ephemeral.medium, server_keys.ephemeral.medium,
mutual_keys.persistent.medium, mutual_keys.persistent.medium,
@@ -49,7 +48,6 @@ def translate_data(
def translate_medium( def translate_medium(
medium: SubstitutionKey,
server_persistent_medium_keys: ServerPersistentMediumKeys, server_persistent_medium_keys: ServerPersistentMediumKeys,
server_ephemeral_medium_keys: ServerEphemeralMediumKeys, server_ephemeral_medium_keys: ServerEphemeralMediumKeys,
mutual_persistent_medium_keys: MutualPersistentMediumKeys, mutual_persistent_medium_keys: MutualPersistentMediumKeys,
@@ -61,7 +59,7 @@ def translate_medium(
spma = server_persistent_medium_keys.alpha_key spma = server_persistent_medium_keys.alpha_key
sema = server_ephemeral_medium_keys.alpha_key sema = server_ephemeral_medium_keys.alpha_key
medium_phase1 = medium ^ (((spma ^ sema) < mmo1) << (mmi1 < mmo2)) medium_phase1 = ((spma ^ sema) < mmo1) << (mmi1 < mmo2)
return medium_phase1 return medium_phase1

View File

@@ -12,13 +12,12 @@ import pytest
) )
def test_darc(height, width, message_len): def test_darc(height, width, message_len):
alphabet = SubstitutionKey.init_matrix(width, height, 255) alphabet = SubstitutionKey.init_matrix(width, height, 255)
medium = SubstitutionKey.init_identity_matrix(width, height)
server_keys, mutual_keys, client_keys = generate_keys(height, width) server_keys, mutual_keys, client_keys = generate_keys(height, width)
original_message = OuterKey.init_matrix(height).matrix[0] original_message = OuterKey.init_matrix(height).matrix[0]
original_message = original_message[:message_len] original_message = original_message[:message_len]
(alphabet_phase1, medium_phase1) = darc_phase1(alphabet, medium, server_keys, mutual_keys) (alphabet_phase1, medium_phase1) = darc_phase1(alphabet, server_keys, mutual_keys)
(alphabet_phase2, medium_phase2) = darc_phase2(alphabet_phase1, medium_phase1, client_keys, mutual_keys) (alphabet_phase2, medium_phase2) = darc_phase2(alphabet_phase1, medium_phase1, client_keys, mutual_keys)
(phase3_alphabet, phase3_medium) = darc_phase3(alphabet_phase2, medium_phase2, client_keys, mutual_keys) (phase3_alphabet, phase3_medium) = darc_phase3(alphabet_phase2, medium_phase2, client_keys, mutual_keys)
@@ -36,13 +35,12 @@ def test_darc(height, width, message_len):
) )
def test_darc_no_client(height, width, message_len): def test_darc_no_client(height, width, message_len):
alphabet = SubstitutionKey.init_matrix(width, height, 255) alphabet = SubstitutionKey.init_matrix(width, height, 255)
medium = SubstitutionKey(matrix=[[0 for _ in range(width)] for _ in range(height)])
server_keys, mutual_keys, client_keys = generate_keys(height, width) server_keys, mutual_keys, client_keys = generate_keys(height, width)
original_message = OuterKey.init_matrix(height).matrix[0] original_message = OuterKey.init_matrix(height).matrix[0]
original_message = original_message[:message_len] original_message = original_message[:message_len]
(alphabet_phase1, medium_phase1) = darc_phase1(alphabet, medium, server_keys, mutual_keys) (alphabet_phase1, medium_phase1) = darc_phase1(alphabet, server_keys, mutual_keys)
(phase3_alphabet, phase3_medium) = darc_phase_2_3(alphabet_phase1, medium_phase1, mutual_keys) (phase3_alphabet, phase3_medium) = darc_phase_2_3(alphabet_phase1, medium_phase1, mutual_keys)
darc_message = merge_message_no_client(phase3_alphabet, phase3_medium, mutual_keys, original_message) darc_message = merge_message_no_client(phase3_alphabet, phase3_medium, mutual_keys, original_message)