Refactor AlphabetKet to SubstitutionKey

This commit is contained in:
2024-07-03 13:04:31 -05:00
parent 8527caced0
commit 957d4a4953

View File

@@ -2,24 +2,24 @@
"cells": [
{
"cell_type": "code",
"execution_count": 718,
"execution_count": 3,
"outputs": [],
"source": [
"from src.key_generation import generate_keys\n",
"from src.models import AlphabetKey, OuterKey, Mask\n",
"from src.models import SubstitutionKey, OuterKey, Mask\n",
"from src.server_darc import resolve_message"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-07-03T14:42:19.329136Z",
"start_time": "2024-07-03T14:42:19.325881Z"
"end_time": "2024-07-03T15:44:47.863976Z",
"start_time": "2024-07-03T15:44:47.828314Z"
}
}
},
{
"cell_type": "code",
"execution_count": 705,
"execution_count": 4,
"outputs": [],
"source": [
"def create_random_message(message_len, height):\n",
@@ -29,14 +29,14 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-07-03T00:47:13.503333Z",
"start_time": "2024-07-03T00:47:13.499467Z"
"end_time": "2024-07-03T15:44:47.864152Z",
"start_time": "2024-07-03T15:44:47.831989Z"
}
}
},
{
"cell_type": "code",
"execution_count": 706,
"execution_count": 5,
"outputs": [],
"source": [
"height = 70\n",
@@ -47,31 +47,31 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-07-03T00:47:13.505703Z",
"start_time": "2024-07-03T00:47:13.503057Z"
"end_time": "2024-07-03T15:44:47.864191Z",
"start_time": "2024-07-03T15:44:47.834823Z"
}
}
},
{
"cell_type": "code",
"execution_count": 707,
"execution_count": 6,
"outputs": [],
"source": [
"server_keys, mutual_keys, client_keys = generate_keys(height, width)\n",
"alphabet = AlphabetKey.init_matrix(width, height, 255)\n",
"medium = AlphabetKey(matrix=[[0 for _ in range(width)] for _ in range(height)])"
"alphabet = SubstitutionKey.init_matrix(width, height, 255)\n",
"medium = SubstitutionKey(matrix=[[0 for _ in range(width)] for _ in range(height)])"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-07-03T00:47:13.536496Z",
"start_time": "2024-07-03T00:47:13.506896Z"
"end_time": "2024-07-03T15:44:47.870926Z",
"start_time": "2024-07-03T15:44:47.838679Z"
}
}
},
{
"cell_type": "code",
"execution_count": 708,
"execution_count": 7,
"outputs": [],
"source": [
"sdi1 = server_keys.persistent.data.inner_key_1 << server_keys.ephemeral.data.inner_key_1\n",
@@ -115,14 +115,14 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-07-03T00:47:13.541138Z",
"start_time": "2024-07-03T00:47:13.539201Z"
"end_time": "2024-07-03T15:44:47.913517Z",
"start_time": "2024-07-03T15:44:47.870246Z"
}
}
},
{
"cell_type": "code",
"execution_count": 709,
"execution_count": 8,
"outputs": [],
"source": [
"cdo1_cdo2 = cdo1 << cdo2\n",
@@ -133,14 +133,14 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-07-03T00:47:13.553403Z",
"start_time": "2024-07-03T00:47:13.541940Z"
"end_time": "2024-07-03T15:44:47.913738Z",
"start_time": "2024-07-03T15:44:47.873170Z"
}
}
},
{
"cell_type": "code",
"execution_count": 710,
"execution_count": 9,
"outputs": [],
"source": [
"m_func_1 = lambda x: (x < mdo1) << (mdi1 < mdo2)\n",
@@ -152,14 +152,14 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-07-03T00:47:13.553530Z",
"start_time": "2024-07-03T00:47:13.544750Z"
"end_time": "2024-07-03T15:44:47.913781Z",
"start_time": "2024-07-03T15:44:47.875550Z"
}
}
},
{
"cell_type": "code",
"execution_count": 711,
"execution_count": 10,
"outputs": [],
"source": [
"medium_phase1 = medium ^ m_func_2(spma ^ sema)\n",
@@ -180,14 +180,14 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-07-03T00:47:13.569014Z",
"start_time": "2024-07-03T00:47:13.553586Z"
"end_time": "2024-07-03T15:44:47.913820Z",
"start_time": "2024-07-03T15:44:47.884399Z"
}
}
},
{
"cell_type": "code",
"execution_count": 712,
"execution_count": 11,
"outputs": [],
"source": [
"translated_alphabet = (\n",
@@ -218,14 +218,14 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-07-03T00:47:13.574463Z",
"start_time": "2024-07-03T00:47:13.568318Z"
"end_time": "2024-07-03T15:44:47.917104Z",
"start_time": "2024-07-03T15:44:47.899159Z"
}
}
},
{
"cell_type": "code",
"execution_count": 713,
"execution_count": 12,
"outputs": [],
"source": [
"eof_msg_mask = Mask.init_matrix(width, height, message_len)\n",
@@ -244,14 +244,14 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-07-03T00:47:13.604020Z",
"start_time": "2024-07-03T00:47:13.571898Z"
"end_time": "2024-07-03T15:44:47.917166Z",
"start_time": "2024-07-03T15:44:47.902305Z"
}
}
},
{
"cell_type": "code",
"execution_count": 714,
"execution_count": 13,
"outputs": [],
"source": [
"unwrapped_medium = (\n",
@@ -262,22 +262,29 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-07-03T00:47:13.604168Z",
"start_time": "2024-07-03T00:47:13.581481Z"
"end_time": "2024-07-03T15:44:47.917330Z",
"start_time": "2024-07-03T15:44:47.911658Z"
}
}
},
{
"cell_type": "code",
"execution_count": 715,
"execution_count": 14,
"outputs": [],
"source": [
"darc_message = (\n",
"darc_message = ((\n",
" (\n",
" (medium_phase3 < ~cmo1_cmo2) ^\n",
" ((((alphabet_phase3 < ~cdo1_cdo2) < padded_input_sequence) ^ eof_msg_mask) << (mmi3 < nmmo6_nmmo4))\n",
" ) < mmo4\n",
" ) << (mmi4 < (mmo5 << ~mmo6)) < ~mmo4\n",
" ) << (mmi4 < (mmo5 << ~mmo6))) < ~mmo4\n",
"\n",
"darc_message = ((\n",
" (\n",
" (medium_phase3 < ~cmo1_cmo2) ^\n",
" ((((alphabet_phase3 < ~cdo1_cdo2) < padded_input_sequence) ^ eof_msg_mask) << (mmi3 < nmmo6_nmmo4))\n",
" )\n",
" ) << (mmi4 < (mmo5 << ~mmo6 << ~mmo4)))\n",
"\n",
"unwrapped_medium = (\n",
" (darc_message << ~(mmi4 < (mmo5 << nmmo6_nmmo4))) ^\n",
@@ -287,14 +294,14 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-07-03T00:47:13.604250Z",
"start_time": "2024-07-03T00:47:13.589989Z"
"end_time": "2024-07-03T15:44:47.929257Z",
"start_time": "2024-07-03T15:44:47.914223Z"
}
}
},
{
"cell_type": "code",
"execution_count": 716,
"execution_count": 15,
"outputs": [],
"source": [
"orignal_message = resolve_message(translated_alphabet, unwrapped_medium)"
@@ -302,20 +309,20 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-07-03T00:47:13.608055Z",
"start_time": "2024-07-03T00:47:13.593458Z"
"end_time": "2024-07-03T15:44:47.929422Z",
"start_time": "2024-07-03T15:44:47.927326Z"
}
}
},
{
"cell_type": "code",
"execution_count": 717,
"execution_count": 16,
"outputs": [
{
"data": {
"text/plain": "False"
"text/plain": "True"
},
"execution_count": 717,
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
@@ -326,34 +333,34 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-07-03T00:47:13.608198Z",
"start_time": "2024-07-03T00:47:13.597454Z"
"end_time": "2024-07-03T15:44:47.945605Z",
"start_time": "2024-07-03T15:44:47.932864Z"
}
}
},
{
"cell_type": "code",
"execution_count": 717,
"execution_count": 16,
"outputs": [],
"source": [],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-07-03T00:47:13.608236Z",
"start_time": "2024-07-03T00:47:13.600039Z"
"end_time": "2024-07-03T15:44:47.945779Z",
"start_time": "2024-07-03T15:44:47.935609Z"
}
}
},
{
"cell_type": "code",
"execution_count": 717,
"execution_count": 16,
"outputs": [],
"source": [],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-07-03T00:47:13.608276Z",
"start_time": "2024-07-03T00:47:13.601932Z"
"end_time": "2024-07-03T15:44:47.965022Z",
"start_time": "2024-07-03T15:44:47.937832Z"
}
}
}