initial commit

This commit is contained in:
2024-05-17 14:30:26 -05:00
commit 63f561e1fa
22 changed files with 15642 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
.idea

1966
darc.json Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,10 @@
{
"OuterClientShuffleEphemeralKey": [[1,4,2,9,5,7,8,3,0,6]],
"OuterClientShuffleFunctionEphemeralKey": [[4,3,2,5,1,6,7,8,0,9]],
"ClientEphemeralKey": [[21,149,75,73,228,81,79],[41,189,80,209,45,101,53],[139,238,141,159,30,79,214],[239,234,72,75,80,190,124],[203,225,246,200,205,195,92],[201,185,113,101,176,216,106],[14,210,125,70,53,128,57],[115,27,97,39,199,26,104],[29,4,55,5,13,57,19],[158,184,137,0,221,12,217]],
"ClientShuffleEphemeralKeyA": [[5,0,4,3,2,6,1],[0,6,2,1,5,3,4],[1,2,0,3,5,4,6],[0,2,6,3,4,5,1],[5,1,2,0,3,4,6],[1,0,3,4,5,6,2],[3,0,5,2,6,4,1],[6,4,5,3,0,2,1],[2,4,6,0,3,5,1],[4,6,2,3,5,1,0]],
"OuterClientShuffleMediumEphemeralKey": [[2,3,9,6,5,7,4,1,0,8]],
"OuterClientShuffleFunctionMediumEphemeralKey": [[0,1,6,3,4,5,7,9,2,8]],
"ClientShuffleMediumEphemeralKeyA": [[2,4,1,6,3,0,5],[5,1,6,4,0,2,3],[3,6,5,1,4,0,2],[6,4,5,2,3,1,0],[6,0,3,5,1,2,4],[6,0,3,1,4,2,5],[4,1,3,0,2,5,6],[5,0,2,1,6,4,3],[3,2,4,5,6,0,1],[1,5,0,2,3,6,4]],
"ClientMediumEphemeralKey": [[196,239,0,227,191,41,36],[99,212,122,236,132,38,217],[196,175,206,246,149,100,83],[18,216,7,225,159,221,59],[56,200,125,86,197,39,108],[214,128,152,217,7,138,12],[47,165,141,81,99,208,85],[71,79,10,15,36,139,177],[68,22,52,200,132,0,125],[205,198,219,188,190,238,23]]
}

View File

@@ -0,0 +1,30 @@
{
"OuterFunctionKey": [[9, 7, 4, 2, 5, 3, 0, 6, 1, 8]],
"OuterFunctionFunctionKey": [[8, 1, 4, 5, 2, 3, 7, 6, 0, 9]],
"OuterServerShuffleFunctionKey": [[3, 9, 2, 5, 0, 7, 6, 8, 1, 4]],
"MutualKey": [[197, 126, 66, 64, 226, 18, 153], [28, 15, 172, 73, 132, 222, 220], [110, 115, 107, 210, 52, 23, 116], [178, 122, 168, 93, 146, 206, 80], [22, 191, 165, 251, 58, 135, 166], [137, 78, 235, 223, 179, 194, 64], [134, 130, 154, 214, 225, 215, 97], [60, 41, 193, 9, 197, 108, 87], [198, 134, 72, 146, 247, 223, 166], [104, 81, 159, 34, 29, 200, 196]],
"FunctionKey": [[1, 5, 0, 2, 3, 6, 4], [5, 2, 6, 4, 1, 3, 0], [4, 2, 3, 5, 6, 1, 0], [0, 3, 1, 6, 5, 2, 4], [4, 1, 3, 0, 6, 5, 2], [6, 3, 4, 2, 5, 1, 0], [2, 3, 0, 4, 1, 6, 5], [4, 0, 6, 5, 2, 3, 1], [3, 2, 4, 1, 0, 5, 6], [2, 3, 4, 1, 5, 0, 6]],
"ClientShuffleKeyX": [[6, 3, 1, 4, 5, 0, 2], [6, 5, 0, 2, 3, 4, 1], [1, 4, 0, 6, 3, 2, 5], [6, 1, 4, 5, 3, 2, 0], [2, 0, 1, 4, 3, 5, 6], [3, 0, 6, 2, 1, 4, 5], [3, 2, 0, 1, 6, 4, 5], [6, 2, 3, 0, 1, 5, 4], [3, 0, 6, 5, 4, 1, 2], [3, 2, 5, 0, 4, 1, 6]],
"MutualMediumKey": [[134, 55, 223, 228, 216, 192, 220], [84, 232, 155, 47, 216, 122, 96], [238, 56, 234, 113, 178, 232, 59], [159, 126, 156, 186, 176, 95, 207], [55, 49, 8, 218, 248, 232, 26], [244, 128, 254, 159, 227, 164, 88], [86, 49, 163, 158, 91, 29, 85], [224, 29, 111, 130, 45, 64, 242], [233, 36, 69, 153, 173, 187, 85], [190, 180, 204, 92, 117, 118, 208]],
"OuterFunctionMediumKey": [[1, 6, 0, 2, 9, 5, 8, 4, 7, 3]],
"OuterFunctionFunctionMediumKey": [[4, 1, 7, 8, 9, 6, 0, 2, 3, 5]],
"OuterServerShuffleFunctionMediumKey": [[4, 0, 5, 9, 3, 1, 7, 8, 6, 2]],
"FunctionMediumKey": [[0, 2, 5, 3, 6, 4, 1], [0, 6, 4, 3, 1, 2, 5], [1, 6, 2, 0, 4, 5, 3], [0, 3, 1, 5, 6, 2, 4], [3, 2, 0, 6, 5, 1, 4], [1, 3, 6, 4, 5, 0, 2], [5, 0, 6, 3, 1, 2, 4], [6, 4, 3, 5, 0, 1, 2], [5, 2, 3, 6, 1, 0, 4], [3, 6, 1, 0, 2, 5, 4]],
"ClientShuffleMediumKeyX": [[2, 1, 6, 0, 5, 4, 3], [3, 0, 5, 2, 6, 4, 1], [5, 3, 0, 1, 2, 6, 4], [3, 5, 4, 1, 0, 6, 2], [0, 5, 2, 4, 1, 3, 6], [5, 2, 3, 1, 4, 6, 0], [2, 1, 5, 6, 3, 0, 4], [4, 6, 0, 3, 5, 1, 2], [1, 3, 2, 0, 4, 5, 6], [3, 6, 5, 1, 0, 4, 2]],
"OuterPositionShuffleMediumKey": [[7, 5, 4, 8, 6, 3, 0, 1, 9, 2]],
"OuterPositionShuffleFunctionMediumKey": [[9, 2, 5, 0, 1, 6, 8, 4, 3, 7]],
"OuterPositionFunctionMediumKey": [[7, 2, 0, 8, 1, 6, 3, 5, 9, 4]],
"PositionFunctionMediumKey": [[1, 5, 4, 0, 6, 2, 3], [2, 4, 0, 5, 3, 6, 1], [1, 4, 0, 2, 5, 6, 3], [4, 1, 0, 3, 2, 6, 5], [4, 0, 2, 3, 5, 6, 1], [1, 0, 2, 3, 4, 6, 5], [2, 3, 1, 5, 0, 6, 4], [1, 0, 3, 2, 4, 5, 6], [4, 0, 1, 5, 2, 6, 3], [2, 1, 0, 3, 6, 5, 4]],
"PositionShuffleMediumKey": [[5, 4, 3, 1, 2, 0, 6], [0, 2, 5, 4, 6, 1, 3], [6, 3, 1, 2, 5, 0, 4], [0, 1, 6, 5, 4, 3, 2], [1, 2, 6, 0, 5, 3, 4], [2, 1, 5, 6, 0, 3, 4], [5, 3, 0, 4, 1, 2, 6], [2, 1, 4, 5, 3, 0, 6], [0, 1, 6, 2, 4, 5, 3], [3, 6, 4, 2, 5, 1, 0]],
"ClientKey": [[148, 232, 147, 96, 20, 201, 150], [120, 0, 158, 250, 176, 223, 82], [12, 81, 193, 212, 247, 100, 1], [127, 211, 164, 202, 25, 149, 34], [214, 38, 10, 197, 195, 97, 193], [177, 120, 199, 180, 206, 184, 155], [154, 146, 186, 205, 190, 47, 169], [164, 80, 233, 207, 214, 91, 108], [123, 101, 231, 244, 92, 88, 12], [222, 193, 85, 98, 224, 145, 0]],
"ClientShuffleKeyA": [[6, 0, 3, 5, 2, 1, 4], [4, 3, 2, 5, 0, 1, 6], [5, 4, 1, 0, 2, 3, 6], [3, 6, 1, 4, 5, 2, 0], [3, 5, 4, 2, 0, 1, 6], [6, 1, 5, 4, 2, 3, 0], [0, 4, 6, 3, 5, 1, 2], [0, 6, 4, 3, 1, 2, 5], [5, 0, 6, 3, 4, 1, 2], [3, 2, 0, 4, 1, 6, 5]],
"OuterClientShuffleKey": [[6, 4, 7, 8, 0, 2, 1, 9, 5, 3]],
"OuterClientShuffleFunctionKey": [[4, 2, 1, 0, 5, 7, 8, 9, 3, 6]],
"OuterClientShuffleMediumKey": [[6, 7, 0, 4, 1, 8, 2, 5, 3, 9]],
"OuterClientShuffleFunctionMediumKey": [[3, 2, 9, 5, 4, 7, 0, 6, 8, 1]],
"ClientShuffleMediumKeyA": [[5, 4, 0, 6, 1, 2, 3], [6, 0, 5, 3, 4, 1, 2], [5, 2, 0, 6, 3, 1, 4], [5, 4, 6, 1, 3, 2, 0], [0, 2, 3, 1, 4, 5, 6], [1, 3, 6, 4, 0, 5, 2], [2, 6, 4, 5, 1, 3, 0], [6, 3, 0, 2, 5, 4, 1], [5, 4, 1, 6, 0, 3, 2], [6, 2, 0, 4, 1, 3, 5]],
"ClientMediumKey": [[16, 193, 15, 233, 117, 250, 34], [246, 77, 93, 136, 102, 250, 63], [214, 203, 45, 87, 239, 246, 207], [97, 24, 129, 224, 42, 111, 39], [46, 178, 119, 116, 89, 226, 216], [212, 133, 56, 244, 233, 251, 117], [139, 72, 193, 199, 141, 188, 200], [60, 229, 239, 108, 154, 254, 241], [189, 192, 168, 92, 5, 121, 18], [160, 69, 107, 197, 130, 150, 168]]
}

View File

@@ -0,0 +1,680 @@
{
"MutualEphemeralKey": [
[
106,
113,
9,
54,
49,
4,
207
],
[
184,
3,
232,
179,
15,
113,
142
],
[
129,
44,
164,
54,
1,
32,
201
],
[
106,
50,
246,
140,
149,
179,
109
],
[
210,
11,
69,
193,
77,
245,
62
],
[
37,
76,
137,
24,
220,
30,
165
],
[
40,
57,
147,
225,
24,
176,
103
],
[
37,
212,
189,
203,
218,
138,
168
],
[
73,
227,
38,
164,
20,
239,
24
],
[
7,
194,
254,
76,
0,
244,
215
]
],
"FunctionEphemeralKey": [
[
6,
0,
1,
4,
2,
3,
5
],
[
2,
3,
6,
4,
0,
1,
5
],
[
2,
4,
0,
3,
6,
1,
5
],
[
0,
4,
2,
3,
1,
5,
6
],
[
6,
4,
2,
5,
1,
0,
3
],
[
5,
1,
0,
6,
4,
2,
3
],
[
1,
2,
4,
3,
6,
0,
5
],
[
6,
1,
4,
0,
5,
3,
2
],
[
2,
3,
5,
4,
6,
0,
1
],
[
1,
6,
4,
3,
5,
2,
0
]
],
"OuterFunctionEphemeralKey": [
[
0,
9,
6,
2,
1,
5,
3,
8,
7,
4
]
],
"OuterFunctionFunctionEphemeralKey": [
[
2,
3,
9,
7,
6,
0,
1,
4,
8,
5
]
],
"OuterServerShuffleFunctionEphemeralKey": [
[
0,
8,
5,
9,
7,
3,
1,
4,
6,
2
]
],
"MutualMediumEphemeralKey": [
[
106,
113,
9,
54,
49,
4,
207
],
[
184,
3,
232,
179,
15,
113,
142
],
[
129,
44,
164,
54,
1,
32,
201
],
[
106,
50,
246,
140,
149,
179,
109
],
[
210,
11,
69,
193,
77,
245,
62
],
[
37,
76,
137,
24,
220,
30,
165
],
[
40,
57,
147,
225,
24,
176,
103
],
[
37,
212,
189,
203,
218,
138,
168
],
[
73,
227,
38,
164,
20,
239,
24
],
[
7,
194,
254,
76,
0,
244,
215
]
],
"FunctionMediumEphemeralKey": [
[
1,
0,
5,
6,
4,
3,
2
],
[
4,
0,
1,
5,
3,
2,
6
],
[
6,
4,
0,
3,
1,
5,
2
],
[
6,
3,
4,
1,
2,
5,
0
],
[
4,
5,
2,
3,
1,
6,
0
],
[
4,
6,
1,
0,
3,
2,
5
],
[
5,
0,
6,
4,
2,
1,
3
],
[
3,
5,
2,
6,
0,
1,
4
],
[
0,
1,
3,
6,
2,
4,
5
],
[
6,
3,
4,
2,
5,
0,
1
]
],
"PositionFunctionMediumEphemeralKey": [
[
1,
2,
3,
4,
0,
6,
5
],
[
5,
2,
1,
3,
6,
0,
4
],
[
2,
1,
0,
4,
5,
6,
3
],
[
3,
6,
4,
1,
5,
0,
2
],
[
0,
4,
6,
3,
2,
1,
5
],
[
4,
5,
3,
2,
6,
0,
1
],
[
3,
5,
0,
6,
2,
1,
4
],
[
3,
5,
1,
6,
2,
0,
4
],
[
3,
0,
5,
2,
1,
4,
6
],
[
5,
4,
2,
6,
3,
0,
1
]
],
"OuterFunctionMediumEphemeralKey": [
[
5,
0,
3,
8,
9,
7,
6,
4,
2,
1
]
],
"OuterFunctionFunctionMediumEphemeralKey": [
[
6,
9,
7,
1,
2,
8,
3,
5,
4,
0
]
],
"OuterPositionFunctionMediumEphemeralKey": [
[
6,
8,
2,
1,
0,
5,
7,
9,
3,
4
]
],
"OuterServerShuffleFunctionMediumEphemeralKey": [
[
8,
0,
9,
6,
7,
4,
2,
1,
3,
5
]
],
"OuterPositionShuffleFunctionMediumEphemeralKey": [
[
7,
1,
9,
2,
6,
4,
0,
3,
5,
8
]
],
"PositionShuffleMediumEphemeralKey": [
[
0,
1,
5,
2,
4,
3,
6
],
[
1,
3,
5,
2,
6,
4,
0
],
[
3,
6,
0,
2,
5,
4,
1
],
[
3,
6,
2,
0,
5,
1,
4
],
[
2,
6,
4,
1,
0,
5,
3
],
[
6,
2,
0,
3,
1,
4,
5
],
[
5,
2,
1,
3,
4,
6,
0
],
[
3,
2,
0,
5,
1,
4,
6
],
[
4,
2,
6,
1,
0,
3,
5
],
[
3,
1,
5,
0,
6,
2,
4
]
],
"OuterPositionShuffleMediumEphemeralKey": [
[
1,
9,
6,
4,
0,
5,
7,
2,
8,
3
]
]
}

View File

@@ -0,0 +1,7 @@
{
"OuterServerShuffleEphemeralKey": [[7,5,2,1,8,4,3,6,9,0]],
"ServerEphemeralKey": [[206,101,8,204,115,100,89],[108,247,32,6,2,165,114],[52,169,117,54,230,48,109],[179,218,87,113,86,50,182],[248,53,202,160,133,191,208],[220,64,196,172,113,159,71],[129,99,201,133,213,131,195],[75,151,222,237,193,169,122],[131,125,69,154,243,214,89],[245,65,225,44,226,68,216]],
"ServerShuffleEphemeralKey": [[6,1,3,0,4,2,5],[3,2,1,0,4,5,6],[2,4,3,5,0,6,1],[4,1,3,6,0,2,5],[1,4,2,3,0,5,6],[6,4,5,0,2,3,1],[0,4,2,3,1,5,6],[0,6,3,5,1,2,4],[2,6,3,1,4,5,0],[5,0,4,1,6,3,2]],
"ServerMediumEphemeralKey": [[122,2,181,28,253,157,228],[209,94,236,250,2,133,44],[16,40,112,171,92,121,235],[242,194,137,155,217,175,61],[22,152,73,65,106,43,186],[101,77,107,181,210,24,204],[16,22,46,83,188,106,117],[31,144,220,193,98,30,81],[227,29,136,169,69,9,25],[79,106,14,23,137,61,59]],
"Alphabet": [[253, 144, 217, 190, 1, 49, 154], [103, 69, 139, 148, 17, 244, 36], [84, 171, 243, 99, 236, 46, 251], [128, 123, 182, 14, 176, 65, 31], [92, 241, 32, 224, 48, 223, 145], [222, 39, 131, 33, 233, 127, 73], [156, 101, 208, 162, 105, 169, 107], [80, 0, 83, 61, 125, 177, 164], [134, 64, 212, 111, 172, 26, 60], [242, 78, 245, 137, 115, 120, 149]]
}

View File

@@ -0,0 +1,26 @@
{
"OuterFunctionKey": [[9, 7, 4, 2, 5, 3, 0, 6, 1, 8]],
"OuterFunctionFunctionKey": [[8, 1, 4, 5, 2, 3, 7, 6, 0, 9]],
"OuterServerShuffleFunctionKey": [[3, 9, 2, 5, 0, 7, 6, 8, 1, 4]],
"MutualKey": [[197, 126, 66, 64, 226, 18, 153], [28, 15, 172, 73, 132, 222, 220], [110, 115, 107, 210, 52, 23, 116], [178, 122, 168, 93, 146, 206, 80], [22, 191, 165, 251, 58, 135, 166], [137, 78, 235, 223, 179, 194, 64], [134, 130, 154, 214, 225, 215, 97], [60, 41, 193, 9, 197, 108, 87], [198, 134, 72, 146, 247, 223, 166], [104, 81, 159, 34, 29, 200, 196]],
"FunctionKey": [[1, 5, 0, 2, 3, 6, 4], [5, 2, 6, 4, 1, 3, 0], [4, 2, 3, 5, 6, 1, 0], [0, 3, 1, 6, 5, 2, 4], [4, 1, 3, 0, 6, 5, 2], [6, 3, 4, 2, 5, 1, 0], [2, 3, 0, 4, 1, 6, 5], [4, 0, 6, 5, 2, 3, 1], [3, 2, 4, 1, 0, 5, 6], [2, 3, 4, 1, 5, 0, 6]],
"ClientShuffleKeyX": [[6, 3, 1, 4, 5, 0, 2], [6, 5, 0, 2, 3, 4, 1], [1, 4, 0, 6, 3, 2, 5], [6, 1, 4, 5, 3, 2, 0], [2, 0, 1, 4, 3, 5, 6], [3, 0, 6, 2, 1, 4, 5], [3, 2, 0, 1, 6, 4, 5], [6, 2, 3, 0, 1, 5, 4], [3, 0, 6, 5, 4, 1, 2], [3, 2, 5, 0, 4, 1, 6]],
"MutualMediumKey": [[134, 55, 223, 228, 216, 192, 220], [84, 232, 155, 47, 216, 122, 96], [238, 56, 234, 113, 178, 232, 59], [159, 126, 156, 186, 176, 95, 207], [55, 49, 8, 218, 248, 232, 26], [244, 128, 254, 159, 227, 164, 88], [86, 49, 163, 158, 91, 29, 85], [224, 29, 111, 130, 45, 64, 242], [233, 36, 69, 153, 173, 187, 85], [190, 180, 204, 92, 117, 118, 208]],
"OuterFunctionMediumKey": [[1, 6, 0, 2, 9, 5, 8, 4, 7, 3]],
"OuterFunctionFunctionMediumKey": [[4, 1, 7, 8, 9, 6, 0, 2, 3, 5]],
"OuterServerShuffleFunctionMediumKey": [[4, 0, 5, 9, 3, 1, 7, 8, 6, 2]],
"FunctionMediumKey": [[0, 2, 5, 3, 6, 4, 1], [0, 6, 4, 3, 1, 2, 5], [1, 6, 2, 0, 4, 5, 3], [0, 3, 1, 5, 6, 2, 4], [3, 2, 0, 6, 5, 1, 4], [1, 3, 6, 4, 5, 0, 2], [5, 0, 6, 3, 1, 2, 4], [6, 4, 3, 5, 0, 1, 2], [5, 2, 3, 6, 1, 0, 4], [3, 6, 1, 0, 2, 5, 4]],
"ClientShuffleMediumKeyX": [[2, 1, 6, 0, 5, 4, 3], [3, 0, 5, 2, 6, 4, 1], [5, 3, 0, 1, 2, 6, 4], [3, 5, 4, 1, 0, 6, 2], [0, 5, 2, 4, 1, 3, 6], [5, 2, 3, 1, 4, 6, 0], [2, 1, 5, 6, 3, 0, 4], [4, 6, 0, 3, 5, 1, 2], [1, 3, 2, 0, 4, 5, 6], [3, 6, 5, 1, 0, 4, 2]],
"OuterPositionShuffleMediumKey": [[7, 5, 4, 8, 6, 3, 0, 1, 9, 2]],
"OuterPositionShuffleFunctionMediumKey": [[9, 2, 5, 0, 1, 6, 8, 4, 3, 7]],
"OuterPositionFunctionMediumKey": [[7, 2, 0, 8, 1, 6, 3, 5, 9, 4]],
"PositionFunctionMediumKey": [[1, 5, 4, 0, 6, 2, 3], [2, 4, 0, 5, 3, 6, 1], [1, 4, 0, 2, 5, 6, 3], [4, 1, 0, 3, 2, 6, 5], [4, 0, 2, 3, 5, 6, 1], [1, 0, 2, 3, 4, 6, 5], [2, 3, 1, 5, 0, 6, 4], [1, 0, 3, 2, 4, 5, 6], [4, 0, 1, 5, 2, 6, 3], [2, 1, 0, 3, 6, 5, 4]],
"PositionShuffleMediumKey": [[5, 4, 3, 1, 2, 0, 6], [0, 2, 5, 4, 6, 1, 3], [6, 3, 1, 2, 5, 0, 4], [0, 1, 6, 5, 4, 3, 2], [1, 2, 6, 0, 5, 3, 4], [2, 1, 5, 6, 0, 3, 4], [5, 3, 0, 4, 1, 2, 6], [2, 1, 4, 5, 3, 0, 6], [0, 1, 6, 2, 4, 5, 3], [3, 6, 4, 2, 5, 1, 0]],
"OuterServerShuffleKey": [[4, 9, 6, 0, 7, 5, 3, 1, 2, 8]],
"ServerKey": [[242, 97, 234, 194, 76, 104, 44], [232, 187, 4, 235, 28, 253, 239], [135, 213, 186, 200, 121, 14, 36], [16, 119, 58, 129, 53, 73, 8], [190, 27, 252, 176, 97, 8, 138], [116, 158, 97, 219, 187, 13, 179], [101, 112, 112, 80, 213, 35, 178], [196, 171, 60, 254, 251, 236, 206], [210, 226, 52, 138, 164, 63, 170], [146, 143, 69, 69, 141, 151, 174]],
"ServerShuffleKey": [[5, 2, 3, 0, 6, 4, 1], [5, 2, 6, 3, 0, 1, 4], [1, 3, 5, 0, 2, 6, 4], [6, 2, 1, 4, 5, 0, 3], [2, 3, 4, 1, 5, 6, 0], [3, 2, 0, 1, 5, 4, 6], [2, 6, 0, 3, 4, 1, 5], [3, 0, 4, 6, 2, 5, 1], [5, 3, 2, 0, 6, 4, 1], [1, 4, 5, 3, 2, 6, 0]],
"ServerMediumKey": [[112, 102, 52, 70, 128, 146, 63], [237, 152, 85, 249, 104, 196, 236], [102, 8, 226, 21, 208, 141, 226], [156, 142, 127, 216, 244, 176, 108], [180, 69, 102, 8, 144, 57, 116], [71, 231, 161, 63, 102, 253, 15], [124, 217, 105, 12, 79, 35, 60], [255, 142, 198, 151, 250, 242, 195], [207, 75, 238, 78, 51, 122, 150], [253, 208, 32, 232, 53, 47, 22]]
}

View File

@@ -0,0 +1,51 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true,
"ExecuteTime": {
"end_time": "2024-04-26T18:17:33.998346Z",
"start_time": "2024-04-26T18:17:33.995935Z"
}
},
"outputs": [],
"source": [
"import random"
]
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"random"
],
"metadata": {
"collapsed": false
}
}
],
"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": 0
}

0
src/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

360
src/darc_key.py Normal file
View File

@@ -0,0 +1,360 @@
from src.models import AlphabetKey, OuterShuffleKey, InnerShuffleKey, PersistentKeys, EphemeralKeys, DarcKey, Phase1Session, Session, TxData, Medium
import json
def get_test_keys():
with open("../testDarcKeys.json", 'r') as fp:
test_data = json.load(fp)
persistent_keys = PersistentKeys(
serverKey=AlphabetKey(
matrix=test_data["persistentKeys"]["serverKey"]
),
functionKey=InnerShuffleKey(
matrix=test_data["persistentKeys"]["functionKey"]
),
serverShuffleKey=InnerShuffleKey(
matrix=test_data["persistentKeys"]["serverShuffleKey"]
),
outerFunctionKey=OuterShuffleKey(
matrix=[test_data["persistentKeys"]["outerFunctionKey"]]
),
outerFunctionFunctionKey=OuterShuffleKey(
matrix=[test_data["persistentKeys"]["outerFunctionFunctionKey"]]
),
outerServerShuffleKey=OuterShuffleKey(
matrix=[test_data["persistentKeys"]["outerServerShuffleKey"]]
),
outerServerShuffleFunctionKey=OuterShuffleKey(
matrix=[test_data["persistentKeys"]["outerServerShuffleFunctionKey"]]
),
clientKey=AlphabetKey(
matrix=test_data["persistentKeys"]["clientKey"]
),
sharedKey=AlphabetKey(
matrix=test_data["persistentKeys"]["sharedKey"]
),
clientShuffleKeyX=InnerShuffleKey(
matrix=test_data["persistentKeys"]["clientShuffleKeyX"]
),
clientShuffleKeyA=InnerShuffleKey(
matrix=test_data["persistentKeys"]["clientShuffleKeyA"]
),
functionMediumKey=InnerShuffleKey(
matrix=test_data["persistentKeys"]["functionMediumKey"]
),
clientShuffleMediumKeyX=InnerShuffleKey(
matrix=test_data["persistentKeys"]["clientShuffleMediumKeyX"]
),
inputMediumData=AlphabetKey(
matrix=test_data["persistentKeys"]["inputMediumData"]
),
serverMediumKey=InnerShuffleKey(
matrix=test_data["persistentKeys"]["serverMediumKey"]
),
outerFunctionMediumKey=OuterShuffleKey(
matrix=[test_data["persistentKeys"]["outerFunctionMediumKey"]]
),
outerFunctionFunctionMediumKey=OuterShuffleKey(
matrix=[test_data["persistentKeys"]["outerFunctionFunctionMediumKey"]]
),
outerServerShuffleMediumKey=OuterShuffleKey(
matrix=[test_data["persistentKeys"]["outerServerShuffleMediumKey"]]
),
outerServerShuffleFunctionMediumKey=OuterShuffleKey(
matrix=[test_data["persistentKeys"]["outerServerShuffleFunctionMediumKey"]]
),
sharedMediumKey=AlphabetKey(
matrix=test_data["persistentKeys"]["sharedMediumKey"]
),
outerPositionFunctionMediumKey=OuterShuffleKey(
matrix=[test_data["persistentKeys"]["outerPositionFunctionMediumKey"]]
),
outerPositionShuffleMediumKey=OuterShuffleKey(
matrix=[test_data["persistentKeys"]["outerPositionShuffleMediumKey"]]
),
clientMediumKey=AlphabetKey(
matrix=test_data["persistentKeys"]["clientMediumKey"]
),
positionFunctionMediumKey=InnerShuffleKey(
matrix=test_data["persistentKeys"]["positionFunctionMediumKey"]
),
clientShuffleMediumKeyA=InnerShuffleKey(
matrix=test_data["persistentKeys"]["clientShuffleMediumKeyA"]
)
)
ephemeral_keys = EphemeralKeys(
serverEphemeralKey=AlphabetKey(
matrix=test_data["ephemeralKeys"]["serverEphemeralKey"]
),
sharedEphemeralKey=AlphabetKey(
matrix=test_data["ephemeralKeys"]["sharedEphemeralKey"]
),
functionEphemeralKey=InnerShuffleKey(
matrix=test_data["ephemeralKeys"]["functionEphemeralKey"]
),
outerFunctionEphemeralKey=OuterShuffleKey(
matrix=[test_data["ephemeralKeys"]["outerFunctionEphemeralKey"]]
),
outerFunctionFunctionEphemeralKey=OuterShuffleKey(
matrix=[test_data["ephemeralKeys"]["outerFunctionFunctionEphemeralKey"]]
),
outerServerShuffleFunctionEphemeralKey=OuterShuffleKey(
matrix=[test_data["ephemeralKeys"]["outerServerShuffleFunctionEphemeralKey"]]
),
serverShuffleEphemeralKey=InnerShuffleKey(
matrix=test_data["ephemeralKeys"]["serverShuffleEphemeralKey"]
),
outerServerShuffleEphemeralKey=OuterShuffleKey(
matrix=[test_data["ephemeralKeys"]["outerServerShuffleEphemeralKey"]]
),
serverMediumEphemeralKey=AlphabetKey(
matrix=test_data["ephemeralKeys"]["serverMediumEphemeralKey"]
),
sharedMediumEphemeralKey=AlphabetKey(
matrix=test_data["ephemeralKeys"]["sharedMediumEphemeralKey"]
),
functionMediumEphemeralKey=InnerShuffleKey(
matrix=test_data["ephemeralKeys"]["functionMediumEphemeralKey"]
),
positionFunctionMediumEphemeralKey=InnerShuffleKey(
matrix=test_data["ephemeralKeys"]["positionFunctionMediumEphemeralKey"]
),
outerFunctionMediumEphemeralKey=OuterShuffleKey(
matrix=[test_data["ephemeralKeys"]["outerFunctionMediumEphemeralKey"]]
),
outerFunctionFunctionMediumEphemeralKey=OuterShuffleKey(
matrix=[test_data["ephemeralKeys"]["outerFunctionFunctionMediumEphemeralKey"]]
),
outerPositionFunctionMediumEphemeralKey=OuterShuffleKey(
matrix=[test_data["ephemeralKeys"]["outerPositionFunctionMediumEphemeralKey"]]
),
outerServerShuffleFunctionMediumEphemeralKey=OuterShuffleKey(
matrix=[test_data["ephemeralKeys"]["outerServerShuffleFunctionMediumEphemeralKey"]]
),
outerServerShuffleMediumEphemeralKey=OuterShuffleKey(
matrix=[test_data["ephemeralKeys"]["outerServerShuffleMediumEphemeralKey"]]
),
outerPositionShuffleMediumEphemeralKey=OuterShuffleKey(
matrix=[test_data["ephemeralKeys"]["outerPositionShuffleMediumEphemeralKey"]]
),
interfaceConfig=AlphabetKey(
matrix=test_data["ephemeralKeys"]["interfaceConfig"]
),
outerClientShuffleKey=OuterShuffleKey(
matrix=[test_data["ephemeralKeys"]["outerClientShuffleKey"]]
),
outerClientShuffleMediumKey=OuterShuffleKey(
matrix=[test_data["ephemeralKeys"]["outerClientShuffleMediumKey"]]
),
outerClientShuffleFunctionKey=OuterShuffleKey(
matrix=[test_data["ephemeralKeys"]["outerClientShuffleFunctionKey"]]
),
outerClientShuffleFunctionMediumKey=OuterShuffleKey(
matrix=[test_data["ephemeralKeys"]["outerClientShuffleFunctionMediumKey"]]
),
clientEphemeral=AlphabetKey(
matrix=test_data["ephemeralKeys"]["clientEphemeral"]
),
clientEphemeralMedium=AlphabetKey(
matrix=test_data["ephemeralKeys"]["clientEphemeralMedium"]
),
clientShuffleEphemeralA=InnerShuffleKey(
matrix=test_data["ephemeralKeys"]["clientShuffleEphemeralA"]
),
clientShuffleEphemeralMediumA=InnerShuffleKey(
matrix=test_data["ephemeralKeys"]["clientShuffleEphemeralMediumA"]
)
)
return persistent_keys, ephemeral_keys
def test1():
with open("../darc.json", 'r') as fp:
darc = json.load(fp)
serverEphemeralKey = AlphabetKey(matrix=darc["serverEphemeralKey"])
serverKey = AlphabetKey(matrix=darc["serverKey"])
functionEphemeralKey = InnerShuffleKey(matrix=darc["functionEphemeralKey"])
functionKey = InnerShuffleKey(matrix=darc["functionKey"])
outerFunctionEphemeralKey = OuterShuffleKey(matrix=[darc["outerFunctionEphemeralKey"]])
outerFunctionFunctionEphemeralKey = OuterShuffleKey(matrix=[darc["outerFunctionFunctionEphemeralKey"]])
outerFunctionFunctionKey = OuterShuffleKey(matrix=[darc["outerFunctionFunctionKey"]])
outerServerShuffleEphemeralKey = OuterShuffleKey(matrix=[darc["outerServerShuffleEphemeralKey"]])
outerServerShuffleKey = OuterShuffleKey(matrix=[darc["outerServerShuffleKey"]])
interfaceConfig = AlphabetKey(matrix=darc["interfaceConfig"])
outerFunctionFunctionKeyApplied = outerFunctionFunctionKey << outerFunctionFunctionEphemeralKey
outerFunctionKeyApplied = outerFunctionFunctionKey << outerFunctionEphemeralKey
functionKeyApplied = functionKey << functionEphemeralKey
outerServerShuffleKeyApplied = outerServerShuffleKey << outerServerShuffleEphemeralKey
inputData = interfaceConfig < outerServerShuffleKeyApplied
serverKeyShuffled = serverKey < outerFunctionKeyApplied
serverEphemeralKeyShuffled = serverEphemeralKey < outerFunctionKeyApplied
functionEphemeralKeyAppliedShuffled = functionKeyApplied < outerFunctionFunctionKeyApplied
incoming = ((inputData ^ (serverKeyShuffled << functionEphemeralKeyAppliedShuffled)) ^
(serverEphemeralKeyShuffled << functionEphemeralKeyAppliedShuffled))
def translate(outerFunctionFunction: DarcKey, innerFunction: DarcKey, outerFunction: DarcKey, inputData: DarcKey, repeatKeys: list[DarcKey]):
innerFunctionShuffled = innerFunction < outerFunctionFunction
repeatKeysShuffled = [(darc_key < outerFunction) << innerFunctionShuffled for darc_key in repeatKeys]
result = inputData
for darc_key in repeatKeysShuffled:
result = result ^ darc_key
return result
def compute_incoming(persistent_keys, ephemeral_keys):
functionEphemeralKeyApplied = persistent_keys.functionKey << ephemeral_keys.functionEphemeralKey
outerFunctionEphemeralKeyApplied = persistent_keys.outerFunctionKey << ephemeral_keys.outerFunctionEphemeralKey
outerFunctionFunctionEphemeralKeyApplied = persistent_keys.outerFunctionFunctionKey << ephemeral_keys.outerFunctionFunctionEphemeralKey
outerServerShuffleEphemeralKeyApplied = persistent_keys.outerServerShuffleKey << ephemeral_keys.outerServerShuffleEphemeralKey
outerServerShuffleFunctionEphemeralKeyApplied = persistent_keys.outerServerShuffleFunctionKey << ephemeral_keys.outerServerShuffleFunctionEphemeralKey
inputData = ephemeral_keys.interfaceConfig < outerServerShuffleEphemeralKeyApplied
serverShuffleEphemeralKeyApplied = ephemeral_keys.serverShuffleEphemeralKey << persistent_keys.serverShuffleKey
serverShuffleEphemeralKeyApplied = serverShuffleEphemeralKeyApplied < outerServerShuffleFunctionEphemeralKeyApplied
inputData = inputData << serverShuffleEphemeralKeyApplied
incoming = translate(outerFunctionFunctionEphemeralKeyApplied, functionEphemeralKeyApplied, outerFunctionEphemeralKeyApplied, inputData, [persistent_keys.serverKey, ephemeral_keys.serverEphemeralKey])
return incoming
def compute_medium_temp(persistent_keys, ephemeral_keys):
functionMediumKey = persistent_keys.functionMediumKey
inputMediumData = persistent_keys.inputMediumData
outerFunctionMediumKey = persistent_keys.outerFunctionMediumKey
outerFunctionFunctionMediumKey = persistent_keys.outerFunctionFunctionMediumKey
functionEphemeralKeyApplied = functionMediumKey << ephemeral_keys.functionMediumEphemeralKey
outerFunctionEphemeralKeyApplied = outerFunctionMediumKey << ephemeral_keys.outerFunctionMediumEphemeralKey
outerFunctionFunctionEphemeralKeyApplied = outerFunctionFunctionMediumKey << ephemeral_keys.outerFunctionFunctionMediumEphemeralKey
mediumTemp = translate(outerFunctionFunctionEphemeralKeyApplied, functionEphemeralKeyApplied, outerFunctionEphemeralKeyApplied, inputMediumData, [ephemeral_keys.serverMediumEphemeralKey])
return mediumTemp
def medium_translation(persistent_keys: PersistentKeys, ephemeral_keys: EphemeralKeys, mediumTemp: DarcKey):
clientKey = persistent_keys.clientMediumKey
sharedKey = persistent_keys.sharedMediumKey
functionKey = persistent_keys.functionMediumKey
outerFunctionFunctionKey = persistent_keys.outerFunctionFunctionMediumKey
outerFunctionKey = persistent_keys.outerFunctionMediumKey
outerServerShuffleFunctionKey = persistent_keys.outerServerShuffleFunctionMediumKey
clientShuffleKeyA = persistent_keys.clientShuffleMediumKeyA
outerClientShuffleKey = ephemeral_keys.outerClientShuffleMediumKey
outerClientShuffleFunctionKey = ephemeral_keys.outerClientShuffleFunctionMediumKey
clientEphemeral = ephemeral_keys.clientEphemeralMedium
clientShuffleEphemeralA = ephemeral_keys.clientShuffleEphemeralMediumA
outerFunctionFunctionEphemeral = ephemeral_keys.outerFunctionFunctionMediumEphemeralKey
functionEphemeral = ephemeral_keys.functionMediumEphemeralKey
outerFunctionEphemeral = ephemeral_keys.outerFunctionMediumEphemeralKey
outerServerShuffleFunctionEphemeral = ephemeral_keys.outerServerShuffleFunctionMediumEphemeralKey
appliedOuterServerShuffleFunctionKey = outerServerShuffleFunctionKey << outerServerShuffleFunctionEphemeral
functionSalt = functionKey << functionEphemeral
appliedClientShuffleKeyA = clientShuffleKeyA << clientShuffleEphemeralA
appliedOuterFunctionKey = outerFunctionKey << outerFunctionEphemeral
appliedOuterFunctionFunctionKey = outerFunctionFunctionKey << outerFunctionFunctionEphemeral
valuesArray = mediumTemp
preResult = translate(appliedOuterFunctionFunctionKey, functionSalt, appliedOuterFunctionKey, valuesArray, [clientEphemeral, clientKey, sharedKey])
result = preResult << (appliedClientShuffleKeyA < appliedOuterServerShuffleFunctionKey)
outerClientShuffleKeyShuffled = outerClientShuffleKey << outerClientShuffleFunctionKey
result = result < outerClientShuffleKeyShuffled
return result
def phase1(persistent_keys: PersistentKeys, ephemeral_keys: EphemeralKeys) -> Phase1Session:
incoming = compute_incoming(persistent_keys, ephemeral_keys)
mediumTemp = compute_medium_temp(persistent_keys, ephemeral_keys)
medium_translated = medium_translation(persistent_keys, ephemeral_keys, mediumTemp)
session = Session(
guid="",
interfaceConfig=ephemeral_keys.interfaceConfig,
serverEphemeralKey=ephemeral_keys.serverEphemeralKey,
functionEphemeralKey=ephemeral_keys.functionEphemeralKey,
serverShuffleEphemeralKey=ephemeral_keys.serverShuffleEphemeralKey,
outerServerShuffleEphemeralKey=ephemeral_keys.outerServerShuffleEphemeralKey,
outerFunctionEphemeralKey=ephemeral_keys.outerFunctionEphemeralKey,
outerFunctionFunctionEphemeralKey=ephemeral_keys.outerFunctionFunctionEphemeralKey,
outerServerShuffleFunctionEphemeralKey=ephemeral_keys.outerServerShuffleFunctionEphemeralKey,
serverMediumEphemeralKey=ephemeral_keys.serverMediumEphemeralKey,
functionMediumEphemeralKey=ephemeral_keys.functionMediumEphemeralKey,
outerServerShuffleMediumEphemeralKey=ephemeral_keys.outerServerShuffleMediumEphemeralKey,
outerFunctionMediumEphemeralKey=ephemeral_keys.outerFunctionMediumEphemeralKey,
outerFunctionFunctionMediumEphemeralKey=ephemeral_keys.outerFunctionFunctionMediumEphemeralKey,
outerServerShuffleFunctionMediumEphemeralKey=ephemeral_keys.outerServerShuffleFunctionMediumEphemeralKey,
positionFunctionMediumEphemeralKey=ephemeral_keys.positionFunctionMediumEphemeralKey,
outerPositionFunctionMediumEphemeralKey=ephemeral_keys.outerPositionFunctionMediumEphemeralKey,
sharedEphemeralKey=ephemeral_keys.sharedEphemeralKey,
sharedMediumEphemeralKey=ephemeral_keys.sharedMediumEphemeralKey,
outerPositionShuffleMediumEphemeralKey=ephemeral_keys.outerPositionShuffleMediumEphemeralKey
)
txData = TxData(
data=incoming,
functionEphemeralKey=ephemeral_keys.functionEphemeralKey,
outerServerShuffleEphemeralKey=ephemeral_keys.outerServerShuffleEphemeralKey,
outerFunctionFunctionEphemeralKey=ephemeral_keys.outerFunctionFunctionEphemeralKey,
outerFunctionEphemeralKey=ephemeral_keys.outerFunctionEphemeralKey,
outerServerShuffleFunctionEphemeralKey=ephemeral_keys.outerServerShuffleFunctionEphemeralKey,
sharedEphemeralKey=ephemeral_keys.sharedEphemeralKey,
outerClientShuffleKey=ephemeral_keys.outerClientShuffleKey,
outerClientShuffleFunctionKey=ephemeral_keys.outerClientShuffleFunctionKey,
clientEphemeral=ephemeral_keys.clientEphemeral,
clientShuffleEphemeralA=ephemeral_keys.clientShuffleEphemeralA,
clientShuffleEphemeralB=~ephemeral_keys.clientShuffleEphemeralA
)
medium = Medium(
data=medium_translated,
functionEphemeralKey=ephemeral_keys.functionMediumEphemeralKey,
outerServerShuffleEphemeralKey=ephemeral_keys.outerServerShuffleMediumEphemeralKey,
outerFunctionFunctionEphemeralKey=ephemeral_keys.outerFunctionFunctionMediumEphemeralKey,
outerFunctionEphemeralKey=ephemeral_keys.outerFunctionMediumEphemeralKey,
outerServerShuffleFunctionEphemeralKey=ephemeral_keys.outerServerShuffleFunctionMediumEphemeralKey,
sharedEphemeralKey=ephemeral_keys.sharedMediumEphemeralKey,
positionFunctionMediumEphemeralKey=ephemeral_keys.positionFunctionMediumEphemeralKey,
outerPositionFunctionMediumEphemeralKey=ephemeral_keys.outerPositionFunctionMediumEphemeralKey,
outerPositionShuffleMediumEphemeralKey=ephemeral_keys.outerPositionShuffleMediumEphemeralKey,
outerClientShuffleMediumKey=ephemeral_keys.outerClientShuffleMediumKey,
outerClientShuffleFunctionMediumKey=ephemeral_keys.outerClientShuffleFunctionMediumKey,
clientEphemeralMedium=ephemeral_keys.clientEphemeralMedium,
clientShuffleEphemeralMediumA=ephemeral_keys.clientShuffleEphemeralMediumA,
clientShuffleEphemeralMediumB=~ephemeral_keys.clientShuffleEphemeralMediumA
)
return Phase1Session(session=session, tx_data=txData, medium=medium)
def encrypted_alphabet(persistent_keys: PersistentKeys, txdata: TxData) -> AlphabetKey:
""" generateDataTranslationFixedKeys = function (persistantKeys, inputData) """
appliedOuterServerShuffleFunctionKey = persistent_keys.outerServerShuffleFunctionKey << txdata.outerServerShuffleFunctionEphemeralKey
functionSalt = persistent_keys.functionKey << txdata.functionEphemeralKey
appliedClientShuffleKeyA = persistent_keys.clientShuffleKeyA << txdata.clientShuffleEphemeralA
appliedOuterFunctionKey = persistent_keys.outerFunctionKey << txdata.outerFunctionEphemeralKey
appliedOuterFunctionFunctionKey = persistent_keys.outerFunctionFunctionKey << txdata.outerFunctionFunctionEphemeralKey
appliedClientShuffleKeyAShuffled = appliedClientShuffleKeyA < appliedOuterServerShuffleFunctionKey
outerClientShuffleKeyShuffled = txdata.outerClientShuffleKey << txdata.outerClientShuffleFunctionKey
result = translate(appliedOuterFunctionFunctionKey, functionSalt, appliedOuterFunctionKey, txdata.data, [txdata.clientEphemeral, persistent_keys.clientKey, persistent_keys.sharedKey])
result = result << appliedClientShuffleKeyAShuffled
result = result < outerClientShuffleKeyShuffled
return result
def compute_outgoing(persistent_keys: PersistentKeys, txdata: TxData, message: str, session: Session) -> AlphabetKey:
pass
if __name__ == "__main__":
persistent_keys, ephemeral_keys = get_test_keys()
phase1_output = phase1(persistent_keys, ephemeral_keys)
alphabet = encrypted_alphabet(persistent_keys, phase1_output.tx_data)

389
src/mimick_csharp_test.py Normal file
View File

@@ -0,0 +1,389 @@
from src.models import ServerEphemeralKeys, ServerPersistentKeys, ClientEphemeralKeys, ClientPersistentKeys, \
MutualEphemeralKeys, AlphabetKey, DarcKey, OuterShuffleKey
import json
height = 10
width = 7
block_size = 10
def translate_data(server_persistent_keys: ServerPersistentKeys, server_ephemeral_keys: ServerEphemeralKeys, mutual_ephemeral_keys: MutualEphemeralKeys):
function_ephemeral_key_applied = server_persistent_keys.FunctionKey << mutual_ephemeral_keys.FunctionEphemeralKey
outer_function_ephemeral_key_applied = server_persistent_keys.OuterFunctionKey << mutual_ephemeral_keys.OuterFunctionEphemeralKey
outer_function_function_ephemeral_key_applied = server_persistent_keys.OuterFunctionFunctionKey << mutual_ephemeral_keys.OuterFunctionFunctionEphemeralKey
outer_server_shuffle_ephemeral_key_applied = server_persistent_keys.OuterServerShuffleKey << server_ephemeral_keys.OuterServerShuffleEphemeralKey
outer_server_shuffle_function_ephemeral_key_applied = server_persistent_keys.OuterServerShuffleFunctionKey << mutual_ephemeral_keys.OuterServerShuffleFunctionEphemeralKey
input_data = server_ephemeral_keys.Alphabet < outer_server_shuffle_ephemeral_key_applied
server_shuffle_ephemeral_key_applied = server_ephemeral_keys.ServerShuffleEphemeralKey << server_persistent_keys.ServerShuffleKey # TODO: should this be the other way around?
server_shuffle_ephemeral_key_applied = server_shuffle_ephemeral_key_applied < outer_server_shuffle_function_ephemeral_key_applied
input_data = input_data << server_shuffle_ephemeral_key_applied
# substitute_function_operands
outer_function_function = outer_function_function_ephemeral_key_applied
inner_function = function_ephemeral_key_applied
outer_function = outer_function_ephemeral_key_applied
operand = input_data
operand1 = server_persistent_keys.ServerKey < outer_function
operand2 = server_ephemeral_keys.ServerEphemeralKey < outer_function
inner_function_shuffled = inner_function < outer_function_function
operand = operand ^ (operand1 << inner_function_shuffled) ^ (operand2 << inner_function_shuffled)
return operand
def translate_medium(server_persistent_keys: ServerPersistentKeys, server_ephemeral_keys: ServerEphemeralKeys, mutual_ephemeral_keys: MutualEphemeralKeys):
function_ephemeral_key_applied = server_persistent_keys.FunctionMediumKey << mutual_ephemeral_keys.FunctionMediumEphemeralKey
outer_function_ephemeral_key_applied = server_persistent_keys.OuterFunctionMediumKey << mutual_ephemeral_keys.OuterFunctionMediumEphemeralKey
outer_function_function_ephemeral_key_applied = server_persistent_keys.OuterFunctionFunctionMediumKey << mutual_ephemeral_keys.OuterFunctionFunctionMediumEphemeralKey
input_data = AlphabetKey(matrix=[[0 for _ in range(width)] for _ in range(height)])
# substitute_function_operands
outer_function_function = outer_function_function_ephemeral_key_applied
inner_function = function_ephemeral_key_applied
outer_function = outer_function_ephemeral_key_applied
operand = input_data
operand1 = server_persistent_keys.ServerMediumKey < outer_function
operand2 = server_ephemeral_keys.ServerMediumEphemeralKey < outer_function
inner_function_shuffled = inner_function < outer_function_function
operand = operand ^ (operand1 << inner_function_shuffled) ^ (operand2 << inner_function_shuffled)
return operand
def darc_phase1(server_persistent_keys: ServerPersistentKeys, server_ephemeral_keys: ServerEphemeralKeys, mutual_ephemeral_keys: MutualEphemeralKeys):
alphabet = translate_data(server_persistent_keys, server_ephemeral_keys, mutual_ephemeral_keys)
medium = translate_medium(server_persistent_keys, server_ephemeral_keys, mutual_ephemeral_keys)
return alphabet, medium
def receive_alphabet(alphabet: DarcKey, client_persistent_keys: ClientPersistentKeys, client_ephemeral_keys: ClientEphemeralKeys, mutual_ephemeral_keys: MutualEphemeralKeys):
function_key_applied = client_persistent_keys.FunctionKey << mutual_ephemeral_keys.FunctionEphemeralKey
outer_function_key_applied = client_persistent_keys.OuterFunctionKey << mutual_ephemeral_keys.OuterFunctionEphemeralKey
outer_function_function_key_applied = client_persistent_keys.OuterFunctionFunctionKey << mutual_ephemeral_keys.OuterFunctionFunctionEphemeralKey
inner_function_key_applied = function_key_applied < outer_function_function_key_applied
operand = alphabet
operand1 = client_ephemeral_keys.ClientEphemeralKey < outer_function_key_applied
operand2 = client_persistent_keys.ClientKey < outer_function_key_applied
operand3 = client_persistent_keys.MutualKey < outer_function_key_applied
result = operand ^ (operand1 << inner_function_key_applied) ^ (operand2 << inner_function_key_applied) ^ (operand3 << inner_function_key_applied)
outer_server_shuffle_function_key_applied = client_persistent_keys.OuterServerShuffleFunctionKey << mutual_ephemeral_keys.OuterServerShuffleFunctionEphemeralKey
client_shuffle_key_a_applied = client_persistent_keys.ClientShuffleKeyA << client_ephemeral_keys.ClientShuffleEphemeralKeyA
result = result << (client_shuffle_key_a_applied < outer_server_shuffle_function_key_applied)
outer_client_shuffle_key_applied = client_persistent_keys.OuterClientShuffleKey << client_ephemeral_keys.OuterClientShuffleEphemeralKey
outer_client_shuffle_function_key_applied = client_persistent_keys.OuterClientShuffleFunctionKey << client_ephemeral_keys.OuterClientShuffleFunctionEphemeralKey
outer_client_shuffle_key_applied = outer_client_shuffle_key_applied << outer_client_shuffle_function_key_applied
result = result < outer_client_shuffle_key_applied
return result
def receive_medium(medium: DarcKey, client_peristent_keys: ClientPersistentKeys, client_ephemeral_keys: ClientEphemeralKeys, mutual_ephemeral_keys: MutualEphemeralKeys):
function_key_applied = client_peristent_keys.FunctionMediumKey << mutual_ephemeral_keys.FunctionMediumEphemeralKey
outer_function_key_applied = client_peristent_keys.OuterFunctionMediumKey << mutual_ephemeral_keys.OuterFunctionMediumEphemeralKey
outer_function_function_key_applied = client_peristent_keys.OuterFunctionFunctionMediumKey << mutual_ephemeral_keys.OuterFunctionFunctionMediumEphemeralKey
inner_function_key_applied = function_key_applied < outer_function_function_key_applied
operand = medium
operand1 = client_ephemeral_keys.ClientMediumEphemeralKey < outer_function_key_applied
operand2 = client_peristent_keys.ClientMediumKey < outer_function_key_applied
operand3 = client_peristent_keys.MutualMediumKey < outer_function_key_applied
result = operand ^ (operand1 << inner_function_key_applied) ^ (operand2 << inner_function_key_applied) ^ (operand3 << inner_function_key_applied)
client_shuffle_key_a_applied = client_peristent_keys.ClientShuffleMediumKeyA << client_ephemeral_keys.ClientShuffleMediumEphemeralKeyA
outer_server_shuffle_function_key_applied = client_peristent_keys.OuterServerShuffleFunctionMediumKey << mutual_ephemeral_keys.OuterServerShuffleFunctionMediumEphemeralKey
client_shuffle_key_a_applied = client_shuffle_key_a_applied < outer_server_shuffle_function_key_applied
result = result << client_shuffle_key_a_applied
outer_client_shuffle_key_applied = client_peristent_keys.OuterClientShuffleMediumKey << client_ephemeral_keys.OuterClientShuffleMediumEphemeralKey
outer_client_shuffle_function_key_applied = client_peristent_keys.OuterClientShuffleFunctionMediumKey << client_ephemeral_keys.OuterClientShuffleFunctionMediumEphemeralKey
outer_client_shuffle_key_applied = outer_client_shuffle_key_applied << outer_client_shuffle_function_key_applied
result = result < outer_client_shuffle_key_applied
return result
def darc_phase2(alphabet: DarcKey, medium: DarcKey, client_peristent_keys: ClientPersistentKeys, client_ephemeral_keys: ClientEphemeralKeys, mutual_ephemeral_keys: MutualEphemeralKeys):
alphabet = receive_alphabet(alphabet, client_peristent_keys, client_ephemeral_keys, mutual_ephemeral_keys)
medium = receive_medium(medium, client_peristent_keys, client_ephemeral_keys, mutual_ephemeral_keys)
return alphabet, medium
def transmit_alphabet(alphabet: DarcKey, client_peristent_keys: ClientPersistentKeys, client_ephemeral_keys: ClientEphemeralKeys, mutual_ephemeral_keys: MutualEphemeralKeys):
outer_server_shuffle_function_key_applied = client_peristent_keys.OuterServerShuffleFunctionKey << mutual_ephemeral_keys.OuterServerShuffleFunctionEphemeralKey
outer_client_shuffle_key_applied = client_peristent_keys.OuterClientShuffleKey << client_ephemeral_keys.OuterClientShuffleEphemeralKey
outer_client_shuffle_function_key_applied = client_peristent_keys.OuterClientShuffleFunctionKey << client_ephemeral_keys.OuterClientShuffleFunctionEphemeralKey
input_outer_client_shuffle_key = outer_client_shuffle_key_applied << outer_client_shuffle_function_key_applied
input_outer_server_shuffle_function_key = outer_server_shuffle_function_key_applied << input_outer_client_shuffle_key
outer_function_function_key_applied = client_peristent_keys.OuterFunctionFunctionKey << mutual_ephemeral_keys.OuterFunctionFunctionEphemeralKey
outer_function_function_key_applied = outer_function_function_key_applied << input_outer_client_shuffle_key
function_key_applied = client_peristent_keys.FunctionKey << mutual_ephemeral_keys.FunctionEphemeralKey
function_key_applied = function_key_applied < outer_function_function_key_applied
reordered_shuffle_key_x = client_peristent_keys.ClientShuffleKeyX < input_outer_server_shuffle_function_key
function_ephemeral_key_applied = function_key_applied << reordered_shuffle_key_x
client_shuffle_key_b = (~client_persistent_keys.ClientShuffleKeyA) << client_peristent_keys.ClientShuffleKeyX
client_shuffle_ephemeral_key_b = ~client_ephemeral_keys.ClientShuffleEphemeralKeyA
input_client_shuffle_key_b = client_shuffle_ephemeral_key_b << client_shuffle_key_b
input_client_shuffle_key_b = input_client_shuffle_key_b < input_outer_server_shuffle_function_key
shuffled_items = alphabet << input_client_shuffle_key_b
outer_function_key_applied = client_peristent_keys.OuterFunctionKey << mutual_ephemeral_keys.OuterFunctionEphemeralKey
input_outer_function_key = outer_function_key_applied << input_outer_client_shuffle_key
inner_function_key_applied = function_ephemeral_key_applied
operand = shuffled_items
operand1 = client_ephemeral_keys.ClientEphemeralKey < input_outer_function_key
operand2 = client_peristent_keys.ClientKey < input_outer_function_key
operand3 = mutual_ephemeral_keys.MutualEphemeralKey < input_outer_function_key
result = operand ^ (operand1 << inner_function_key_applied) ^ (operand2 << inner_function_key_applied) ^ (operand3 << inner_function_key_applied)
return result
def transmit_medium(medium: DarcKey, client_peristent_keys: ClientPersistentKeys, client_ephemeral_keys: ClientEphemeralKeys, mutual_ephemeral_keys: MutualEphemeralKeys):
client_shuffle_ephemeral_key_b = ~client_ephemeral_keys.ClientShuffleMediumEphemeralKeyA
outer_server_shuffle_function_key_applied = client_peristent_keys.OuterServerShuffleFunctionMediumKey << mutual_ephemeral_keys.OuterServerShuffleFunctionMediumEphemeralKey
outer_client_shuffle_key_applied = client_peristent_keys.OuterClientShuffleMediumKey << client_ephemeral_keys.OuterClientShuffleMediumEphemeralKey
outer_client_suffle_function_key_applied = client_peristent_keys.OuterClientShuffleFunctionMediumKey << client_ephemeral_keys.OuterClientShuffleFunctionMediumEphemeralKey
input_outer_client_shuffle_key = outer_client_shuffle_key_applied << outer_client_suffle_function_key_applied
input_outer_server_shuffle_function_key = outer_server_shuffle_function_key_applied << input_outer_client_shuffle_key
outer_function_function_key_applied = client_peristent_keys.OuterFunctionFunctionMediumKey << mutual_ephemeral_keys.OuterFunctionFunctionMediumEphemeralKey
outer_function_function_key_applied = outer_function_function_key_applied << input_outer_client_shuffle_key
function_key_applied = client_peristent_keys.FunctionMediumKey << mutual_ephemeral_keys.FunctionMediumEphemeralKey
function_key_applied = function_key_applied < outer_function_function_key_applied
reordered_shuffle_key_x = client_peristent_keys.ClientShuffleMediumKeyX < input_outer_server_shuffle_function_key
function_ephemeral_key_applied = function_key_applied << reordered_shuffle_key_x
client_shuffle_key_b = (~client_peristent_keys.ClientShuffleMediumKeyA) << client_peristent_keys.ClientShuffleMediumKeyX
input_client_shuffle_key_b = client_shuffle_ephemeral_key_b << client_shuffle_key_b
input_client_shuffle_key_b = input_client_shuffle_key_b < input_outer_server_shuffle_function_key
shuffled_items = medium << input_client_shuffle_key_b
outer_function_key_applied = client_peristent_keys.OuterFunctionMediumKey << mutual_ephemeral_keys.OuterFunctionMediumEphemeralKey
input_outer_function_key = outer_function_key_applied << input_outer_client_shuffle_key
inner_function_key_applied = function_ephemeral_key_applied
operand = shuffled_items
operand1 = client_ephemeral_keys.ClientMediumEphemeralKey < input_outer_function_key
operand2 = client_peristent_keys.ClientMediumKey < input_outer_function_key
operand3 = mutual_ephemeral_keys.MutualMediumEphemeralKey < input_outer_function_key
result = operand ^ (operand1 << inner_function_key_applied) ^ (operand2 << inner_function_key_applied) ^ (operand3 << inner_function_key_applied)
return result
def darc_phase3(alphabet: DarcKey, medium: DarcKey, client_peristent_keys: ClientPersistentKeys, client_ephemeral_keys: ClientEphemeralKeys, mutual_ephemeral_keys: MutualEphemeralKeys):
alphabet = transmit_alphabet(alphabet, client_peristent_keys, client_ephemeral_keys, mutual_ephemeral_keys)
medium = transmit_medium(medium, client_peristent_keys, client_ephemeral_keys, mutual_ephemeral_keys)
return alphabet, medium
def merge_message(alphabet: DarcKey, medium: DarcKey, client_peristent_keys: ClientPersistentKeys, client_ephemeral_keys: ClientEphemeralKeys, mutual_ephemeral_keys: MutualEphemeralKeys, input_sequence: list[int]):
outer_client_shuffle_alphabet_key_applied = client_peristent_keys.OuterClientShuffleKey << client_ephemeral_keys.OuterClientShuffleEphemeralKey
outer_client_shuffle_function_alphabet_key_applied = client_peristent_keys.OuterClientShuffleFunctionKey << client_ephemeral_keys.OuterClientShuffleFunctionEphemeralKey
outer_client_shuffle_alphabet_key_applied = ~(outer_client_shuffle_alphabet_key_applied << outer_client_shuffle_function_alphabet_key_applied)
msg_len = len(input_sequence)
eof_arr = AlphabetKey.init_matrix(width, height, 255).matrix[0]
if msg_len < height:
padded_input_sequence = OuterShuffleKey.init_matrix(height)
padded_input_sequence.matrix = [input_sequence + padded_input_sequence.matrix[0][msg_len:]]
else:
padded_input_sequence = OuterShuffleKey(matrix=[input_sequence])
input_sequence_applied = outer_client_shuffle_alphabet_key_applied << padded_input_sequence
outer_client_shuffle_medium_key_applied = client_peristent_keys.OuterClientShuffleMediumKey << client_ephemeral_keys.OuterClientShuffleMediumEphemeralKey
outer_client_shuffle_function_medium_key_applied = client_peristent_keys.OuterClientShuffleFunctionMediumKey << client_ephemeral_keys.OuterClientShuffleFunctionMediumEphemeralKey
outer_client_shuffle_medium_key_applied = outer_client_shuffle_medium_key_applied << outer_client_shuffle_function_medium_key_applied
input_sequence_applied = input_sequence_applied << outer_client_shuffle_medium_key_applied
message = alphabet < input_sequence_applied
message_pad_key = ~outer_client_shuffle_medium_key_applied
if msg_len < height:
message.matrix[message_pad_key.matrix[0][msg_len]] = eof_arr
position_function_key_applied = client_peristent_keys.PositionFunctionMediumKey << mutual_ephemeral_keys.PositionFunctionMediumEphemeralKey
outer_position_function_key_applied = client_peristent_keys.OuterPositionFunctionMediumKey << mutual_ephemeral_keys.OuterPositionFunctionMediumEphemeralKey
outer_position_shuffle_key_applied = client_peristent_keys.OuterPositionShuffleMediumKey << mutual_ephemeral_keys.OuterPositionShuffleMediumEphemeralKey
outer_position_function_key_applied = outer_position_shuffle_key_applied << outer_position_function_key_applied
outer_client_shuffle_medium_key_applied = ~outer_client_shuffle_medium_key_applied
outer_position_function_key_applied = ~(outer_client_shuffle_medium_key_applied << outer_position_function_key_applied)
inner_function_key_applied = position_function_key_applied < outer_position_function_key_applied
operand = medium
operand1 = message
message = operand ^ (operand1 << inner_function_key_applied)
outer_position_shuffle_function_key_applied = client_peristent_keys.OuterPositionShuffleFunctionMediumKey << mutual_ephemeral_keys.OuterPositionShuffleFunctionMediumEphemeralKey
position_shuffle_key_applied = client_peristent_keys.PositionShuffleMediumKey << mutual_ephemeral_keys.PositionShuffleMediumEphemeralKey
outer_position_shuffle_key_applied = outer_client_shuffle_medium_key_applied << outer_position_shuffle_key_applied
outer_position_shuffle_function_key_applied = outer_position_shuffle_function_key_applied << outer_position_function_key_applied
message = message << (position_shuffle_key_applied < outer_position_shuffle_function_key_applied)
message = message < outer_position_shuffle_key_applied
return message
def darc_phase_4(darc_message: DarcKey, server_persistent_keys: ServerPersistentKeys, server_ephemeral_keys: ServerEphemeralKeys, mutual_ephemeral_keys: MutualEphemeralKeys):
outer_position_function_ephemeral_key_applied = server_persistent_keys.OuterPositionFunctionMediumKey << mutual_ephemeral_keys.OuterPositionFunctionMediumEphemeralKey
outer_position_shuffle_ephemeral_key_applied = server_persistent_keys.OuterPositionShuffleMediumKey << mutual_ephemeral_keys.OuterPositionShuffleMediumEphemeralKey
outer_position_function_ephemeral_key_applied = ~(outer_position_shuffle_ephemeral_key_applied << outer_position_function_ephemeral_key_applied)
outer_position_shuffle_ephemeral_key_applied = ~outer_position_shuffle_ephemeral_key_applied
outer_position_shuffle_function_ephemeral_key_applied = server_persistent_keys.OuterPositionShuffleFunctionMediumKey << mutual_ephemeral_keys.OuterPositionShuffleFunctionMediumEphemeralKey
outer_position_shuffle_function_ephemeral_key_applied = outer_position_shuffle_function_ephemeral_key_applied << outer_position_function_ephemeral_key_applied
outer_function_function_medium_ephemeral_key_applied = server_persistent_keys.OuterFunctionFunctionMediumKey << mutual_ephemeral_keys.OuterFunctionFunctionMediumEphemeralKey
outer_server_shuffle_function_ephemeral_key_applied = server_persistent_keys.OuterServerShuffleFunctionKey << mutual_ephemeral_keys.OuterServerShuffleFunctionEphemeralKey
outer_server_shuffle_function_medium_ephemeral_key_applied = server_persistent_keys.OuterServerShuffleFunctionMediumKey << mutual_ephemeral_keys.OuterServerShuffleFunctionMediumEphemeralKey
function_medium_ephemeral_key_applied = server_persistent_keys.FunctionMediumKey << mutual_ephemeral_keys.FunctionMediumEphemeralKey
client_shuffle_medium_key_x = server_persistent_keys.ClientShuffleMediumKeyX < outer_server_shuffle_function_medium_ephemeral_key_applied
client_shuffle_medium_key_x = (function_medium_ephemeral_key_applied < outer_function_function_medium_ephemeral_key_applied) << client_shuffle_medium_key_x
position_shuffle_ephemeral_key_applied = server_persistent_keys.PositionShuffleMediumKey << mutual_ephemeral_keys.PositionShuffleMediumEphemeralKey
position_shuffle_ephemeral_key_applied = position_shuffle_ephemeral_key_applied < outer_position_shuffle_function_ephemeral_key_applied
client_shuffle_medium_key_x = client_shuffle_medium_key_x << position_shuffle_ephemeral_key_applied
outer_function_medium_ephemeral_key_applied = server_persistent_keys.OuterFunctionMediumKey << mutual_ephemeral_keys.OuterFunctionMediumEphemeralKey
rx_data = darc_message < outer_position_shuffle_ephemeral_key_applied
inner_key = client_shuffle_medium_key_x
operand = rx_data
operand1 = server_persistent_keys.ServerMediumKey < outer_function_medium_ephemeral_key_applied
operand2 = server_ephemeral_keys.ServerMediumEphemeralKey < outer_function_medium_ephemeral_key_applied
operand3 = server_persistent_keys.MutualMediumKey < outer_function_medium_ephemeral_key_applied
operand4 = mutual_ephemeral_keys.MutualMediumEphemeralKey < outer_function_medium_ephemeral_key_applied
rx_data = operand ^ (operand1 << inner_key) ^ (operand2 << inner_key) ^ (operand3 << inner_key) ^ (operand4 << inner_key)
"""
FunctionTranslation PositionFunctionKey = ServerPersistentKeys.PositionFunctionMediumKey;
FunctionTranslation PositionFunctionEphemeralKey = MutualEphemeralKeys.PositionFunctionMediumEphemeralKey;
FunctionTranslation PositionFunctionEphemeralKeyApplied = new FunctionTranslation { Data = Transform.TransformationCompliment(Transform.PermuteInnerTransformation(PositionFunctionKey.Data, PositionFunctionEphemeralKey.Data)) };
#region Inner Shuffle
RxData = Transform.PermuteInnerTransformation(
RxData.Convert<int>(),
Transform.PermuteInnerTransformation(
Transform.TransformationCompliment(
PositionShuffleEphemeralKeyApplied.Data
),
Transform.PermuteOuterTransformation(
PositionFunctionEphemeralKeyApplied.Data.Convert<byte>(),
OuterPositionFunctionEphemeralKeyApplied.Data).Convert<int>())).Convert<byte>();
"""
position_function_ephemeral_key_applied = server_persistent_keys.PositionFunctionMediumKey << mutual_ephemeral_keys.PositionFunctionMediumEphemeralKey
rx_data = rx_data << (~(position_shuffle_ephemeral_key_applied) << (~position_function_ephemeral_key_applied < outer_position_function_ephemeral_key_applied))
client_shuffle_key_x = server_persistent_keys.ClientShuffleKeyX < outer_server_shuffle_function_ephemeral_key_applied
outer_function_function_ephemeral_key_applied = server_persistent_keys.OuterFunctionFunctionKey << mutual_ephemeral_keys.OuterFunctionFunctionEphemeralKey
function_ephemeral_key_applied = server_persistent_keys.FunctionKey << mutual_ephemeral_keys.FunctionEphemeralKey
function_ephemeral_key_applied = (function_ephemeral_key_applied < outer_function_function_ephemeral_key_applied) << client_shuffle_key_x
server_shuffle_ephemeral_key_applied = ~(server_persistent_keys.ServerShuffleKey << server_persistent_keys.ClientShuffleKeyX) << ~(server_ephemeral_keys.ServerShuffleEphemeralKey)
server_shuffle_ephemeral_key_applied = ~(server_shuffle_ephemeral_key_applied < outer_server_shuffle_function_ephemeral_key_applied)
outer_server_shuffle_ephemeral_key_applied = server_persistent_keys.OuterServerShuffleKey << server_ephemeral_keys.OuterServerShuffleEphemeralKey
alphabet = server_ephemeral_keys.Alphabet
alpha_prep = (alphabet < outer_server_shuffle_ephemeral_key_applied) << server_shuffle_ephemeral_key_applied
outer_function_ephemeral_key_applied = server_persistent_keys.OuterFunctionKey << mutual_ephemeral_keys.OuterFunctionEphemeralKey
inner_key = function_ephemeral_key_applied
operand = alpha_prep
operand1 = server_persistent_keys.ServerKey < outer_function_ephemeral_key_applied
operand2 = server_ephemeral_keys.ServerEphemeralKey < outer_function_ephemeral_key_applied
operand3 = server_persistent_keys.MutualKey < outer_function_ephemeral_key_applied
operand4 = mutual_ephemeral_keys.MutualEphemeralKey < outer_function_ephemeral_key_applied
alpha_prep = operand ^ (operand1 << inner_key) ^ (operand2 << inner_key) ^ (operand3 << inner_key) ^ (operand4 << inner_key)
return resolve_message(alpha_prep.matrix, rx_data.matrix)
def resolve_message(translated_alphabet, translated_messasge):
alphabet_map = {str(key): idx for idx, key in enumerate(translated_alphabet)}
encoded_message = [str(alpha) for alpha in translated_messasge]
message = []
for alpha in encoded_message:
if alpha in alphabet_map.keys():
message.append(alphabet_map[alpha])
else:
break
return message
if __name__ == "__main__":
with open("../darc_key_json/client_persistent_keys.json") as fp:
client_persistent_keys = json.load(fp)
with open("../darc_key_json/client_ephemeral_keys.json") as fp:
client_ephemeral_keys = json.load(fp)
with open("../darc_key_json/server_persistent_keys.json") as fp:
server_persistent_keys = json.load(fp)
with open("../darc_key_json/server_ephemeral_keys.json") as fp:
server_ephemeral_keys = json.load(fp)
with open("../darc_key_json/mutual_ephemeral_keys.json") as fp:
mutual_ephemeral_keys = json.load(fp)
client_persistent_keys = {k: {"matrix": v} for k, v in client_persistent_keys.items()}
client_ephemeral_keys = {k: {"matrix": v} for k, v in client_ephemeral_keys.items()}
server_persistent_keys = {k: {"matrix": v} for k, v in server_persistent_keys.items()}
server_ephemeral_keys = {k: {"matrix": v} for k, v in server_ephemeral_keys.items()}
mutual_ephemeral_keys = {k: {"matrix": v} for k, v in mutual_ephemeral_keys.items()}
client_persistent_keys = ClientPersistentKeys(**client_persistent_keys)
client_ephemeral_keys = ClientEphemeralKeys(**client_ephemeral_keys)
server_persistent_keys = ServerPersistentKeys(**server_persistent_keys)
server_ephemeral_keys = ServerEphemeralKeys(**server_ephemeral_keys)
mutual_ephemeral_keys = MutualEphemeralKeys(**mutual_ephemeral_keys)
(phase1_alphabet, phase1_medium) = darc_phase1(server_persistent_keys, server_ephemeral_keys, mutual_ephemeral_keys)
(phase2_alphabet, phase2_medium) = darc_phase2(phase1_alphabet, phase1_medium, client_persistent_keys, client_ephemeral_keys, mutual_ephemeral_keys)
(phase3_alphabet, phase3_medium) = darc_phase3(phase2_alphabet, phase2_medium, client_persistent_keys, client_ephemeral_keys, mutual_ephemeral_keys)
# original_message = [0, 2, 4, 6, 0, 5, 9, 9, 1, 7]
original_message = [0, 2, 4, 6]
darc_message = merge_message(phase3_alphabet, phase3_medium, client_persistent_keys, client_ephemeral_keys, mutual_ephemeral_keys, original_message)
message = darc_phase_4(darc_message, server_persistent_keys, server_ephemeral_keys, mutual_ephemeral_keys)
print(original_message)
print(message)

1030
src/mimick_excel.py Normal file

File diff suppressed because it is too large Load Diff

487
src/mimick_excel_cleaned.py Normal file
View File

@@ -0,0 +1,487 @@
from src.models import DarcKey, DarcKeyTypes
if __name__ == "__main__":
height = 10
width = 7
# B_o_m
# 2 Outer (Mutual) (Substitution) Function Key
outer_mutual_substitution_function_key = DarcKey(matrix=[['9', '7', '4', '2', '5', '3', '0', '6', '1', '8']], key_type=DarcKeyTypes.outer_shuffle)
# 3 Outer (Mutual) (Substitution) Function Function Key
outer_mutual_substitution_function_function_key = DarcKey(matrix=[['8', '1', '4', '5', '2', '3', '7', '6', '0', '9']], key_type=DarcKeyTypes.outer_shuffle)
# 4 Outer Server (Mutual) Shuffle (Permutation) Function Key
outer_mutual_shuffle_permutation_function_key = DarcKey(matrix=[['3', '9', '2', '5', '0', '7', '6', '8', '1', '4']], key_type=DarcKeyTypes.outer_shuffle)
# 5 Outer Client Shuffle (Permutation) Key
outer_client_shuffle_permutation_key = DarcKey(matrix=[['6', '4', '7', '8', '0', '2', '1', '9', '5', '3']], key_type=DarcKeyTypes.outer_shuffle)
# 6 Outer Client Shuffle (Permutation) Function Key
outer_client_shuffle_permutation_function_key = DarcKey(matrix=[['4', '2', '1', '0', '5', '7', '8', '9', '3', '6']], key_type=DarcKeyTypes.outer_shuffle)
# 7 Outer Server Shuffle (Permutation) Key
outer_server_shuffle_permutation_key = DarcKey(matrix=[['4', '9', '6', '0', '7', '5', '3', '1', '2', '8']], key_type=DarcKeyTypes.outer_shuffle)
# 15 Outer (Mutual) (Substitution) Function Ephemeral Key
outer_mutual_substitution_function_ephemeral_key = DarcKey(matrix=[
['0', '9', '6', '2', '1', '5', '3', '8', '7', '4']
], key_type=DarcKeyTypes.outer_shuffle)
# 16 Outer (Mutual) (Substitution) Function Function Ephemeral Key
outer_mutual_substitution_function_function_ephemeral_key = DarcKey(matrix=[
['2', '3', '9', '7', '6', '0', '1', '4', '8', '5']
], key_type=DarcKeyTypes.outer_shuffle)
# 17 Outer Server (Mutual) Shuffle (Permutation) Function Ephemeral Key
outer_server_mutual_shuffle_permutation_function_ephemeral_key = DarcKey(matrix=[
['0', '8', '5', '9', '7', '3', '1', '4', '6', '2']
], key_type=DarcKeyTypes.outer_shuffle)
# 18 Outer Client Shuffle (Permutation) Ephemeral Key
outer_client_shuffle_permutation_ephemeral_key = DarcKey(matrix=[
['1', '4', '2', '9', '5', '7', '8', '3', '0', '6']
], key_type=DarcKeyTypes.outer_shuffle)
# 19 Outer Client Shuffle (Permutation) Function Ephemeral Key
outer_client_shuffle_permutation_function_ephemeral_key = DarcKey(matrix=[
['4', '3', '2', '5', '1', '6', '7', '8', '0', '9']
], key_type=DarcKeyTypes.outer_shuffle)
# 20 Outer Server Shuffle (Permutation) Ephemeral Key
outer_server_shuffle_permutation_ephemeral_key = DarcKey(matrix=[
['7', '5', '2', '1', '8', '4', '3', '6', '9', '0']
], key_type=DarcKeyTypes.outer_shuffle)
# 29 Alphabet Input Sequence the message
alphabet_input_sequence = DarcKey(matrix=[
['0', '2', '4', '6', '8', '1', '3', '5', '7', '9']
], key_type=DarcKeyTypes.outer_shuffle)
# 1 Alphabet Values
alphabet_values = DarcKey(matrix=[
['10', '28', '38', '41', '51', '64', '70'],
['15', '25', '33', '48', '56', '69', '71'],
['13', '22', '36', '47', '54', '60', '72'],
['12', '24', '31', '43', '58', '63', '73'],
['11', '21', '39', '49', '53', '65', '74'],
['18', '20', '32', '45', '52', '61', '75'],
['14', '29', '37', '44', '57', '68', '76'],
['19', '23', '34', '40', '59', '62', '77'],
['17', '27', '35', '42', '55', '67', '78'],
['16', '26', '30', '46', '50', '66', '79']
], key_type=DarcKeyTypes.alphabet)
# 8 (Mutual) (Substitution) Function Key
mutual_substitution_function_key = DarcKey(matrix=[
['1', '5', '0', '2', '3', '6', '4'],
['5', '2', '6', '4', '1', '3', '0'],
['4', '2', '3', '5', '6', '1', '0'],
['0', '3', '1', '6', '5', '2', '4'],
['4', '1', '3', '0', '6', '5', '2'],
['6', '3', '4', '2', '5', '1', '0'],
['2', '3', '0', '4', '1', '6', '5'],
['4', '0', '6', '5', '2', '3', '1'],
['3', '2', '4', '1', '0', '5', '6'],
['2', '3', '4', '1', '5', '0', '6']
], key_type=DarcKeyTypes.inner_shuffle)
# 9 Client Shuffle (Permutation) Key X
client_shuffle_permutation_key_x = DarcKey(matrix=[
['6', '3', '1', '4', '5', '0', '2'],
['6', '5', '0', '2', '3', '4', '1'],
['1', '4', '0', '6', '3', '2', '5'],
['6', '1', '4', '5', '3', '2', '0'],
['2', '0', '1', '4', '3', '5', '6'],
['3', '0', '6', '2', '1', '4', '5'],
['3', '2', '0', '1', '6', '4', '5'],
['6', '2', '3', '0', '1', '5', '4'],
['3', '0', '6', '5', '4', '1', '2'],
['3', '2', '5', '0', '4', '1', '6']
], key_type=DarcKeyTypes.inner_shuffle)
# 10 Client Shuffle (Permutation) Key A (remove A)
client_shuffle_permutation_key_a = DarcKey(matrix=[
['6', '0', '3', '5', '2', '1', '4'],
['4', '3', '2', '5', '0', '1', '6'],
['5', '4', '1', '0', '2', '3', '6'],
['3', '6', '1', '4', '5', '2', '0'],
['3', '5', '4', '2', '0', '1', '6'],
['6', '1', '5', '4', '2', '3', '0'],
['0', '4', '6', '3', '5', '1', '2'],
['0', '6', '4', '3', '1', '2', '5'],
['5', '0', '6', '3', '4', '1', '2'],
['3', '2', '0', '4', '1', '6', '5']
], key_type=DarcKeyTypes.inner_shuffle)
# 11 Server Shuffle (Permutation) Key
server_shuffle_permutation_key = DarcKey(matrix=[
['5', '2', '3', '0', '6', '4', '1'],
['5', '2', '6', '3', '0', '1', '4'],
['1', '3', '5', '0', '2', '6', '4'],
['6', '2', '1', '4', '5', '0', '3'],
['2', '3', '4', '1', '5', '6', '0'],
['3', '2', '0', '1', '5', '4', '6'],
['2', '6', '0', '3', '4', '1', '5'],
['3', '0', '4', '6', '2', '5', '1'],
['5', '3', '2', '0', '6', '4', '1'],
['1', '4', '5', '3', '2', '6', '0']
], key_type=DarcKeyTypes.inner_shuffle)
# 21 (Mutual) (Substitution) Function Ephemeral Key
mutual_substitution_function_ephemeral_key = DarcKey(matrix=[
['6', '0', '1', '4', '2', '3', '5'],
['2', '3', '6', '4', '0', '1', '5'],
['2', '4', '0', '3', '6', '1', '5'],
['0', '4', '2', '3', '1', '5', '6'],
['6', '4', '2', '5', '1', '0', '3'],
['5', '1', '0', '6', '4', '2', '3'],
['1', '2', '4', '3', '6', '0', '5'],
['6', '1', '4', '0', '5', '3', '2'],
['2', '3', '5', '4', '6', '0', '1'],
['1', '6', '4', '3', '5', '2', '0']
], key_type=DarcKeyTypes.inner_shuffle)
# 22 Client Shuffle (Permutation) Ephemeral Key A (remove A)
client_shuffle_permutation_ephemeral_key_a = DarcKey(matrix=[
['5', '0', '4', '3', '2', '6', '1'],
['0', '6', '2', '1', '5', '3', '4'],
['1', '2', '0', '3', '5', '4', '6'],
['0', '2', '6', '3', '4', '5', '1'],
['5', '1', '2', '0', '3', '4', '6'],
['1', '0', '3', '4', '5', '6', '2'],
['3', '0', '5', '2', '6', '4', '1'],
['6', '4', '5', '3', '0', '2', '1'],
['2', '4', '6', '0', '3', '5', '1'],
['4', '6', '2', '3', '5', '1', '0']
], key_type=DarcKeyTypes.inner_shuffle)
# 23 Server Shuffle (Permutation) Ephemeral Key 1 (remove 1)
server_shuffle_permutation_ephemeral_key_1 = DarcKey(matrix=[
['6', '1', '3', '0', '4', '2', '5'],
['3', '2', '1', '0', '4', '5', '6'],
['2', '4', '3', '5', '0', '6', '1'],
['4', '1', '3', '6', '0', '2', '5'],
['1', '4', '2', '3', '0', '5', '6'],
['6', '4', '5', '0', '2', '3', '1'],
['0', '4', '2', '3', '1', '5', '6'],
['0', '6', '3', '5', '1', '2', '4'],
['2', '6', '3', '1', '4', '5', '0'],
['5', '0', '4', '1', '6', '3', '2']
], key_type=DarcKeyTypes.inner_shuffle)
# 12 Shared (Mutual) (Substitution) Component 1
shared_mutual_substitution_component_1 = DarcKey(matrix=[
['81', '150', '209', '32', '246', '219', '15'],
['100', '15', '50', '179', '52', '1', '142'],
['98', '34', '170', '6', '195', '115', '117'],
['205', '169', '12', '151', '139', '91', '114'],
['192', '153', '175', '62', '249', '230', '103'],
['56', '54', '44', '107', '125', '122', '219'],
['28', '16', '32', '27', '95', '248', '200'],
['152', '121', '40', '198', '19', '55', '59'],
['189', '227', '175', '102', '171', '135', '170'],
['182', '144', '202', '64', '253', '89', '196']
], key_type=DarcKeyTypes.alphabet)
# 13 Client (Substitution) Key
client_substitution_key = DarcKey(matrix=[
['148', '232', '147', '96', '20', '201', '150'],
['120', '0', '158', '250', '176', '223', '82'],
['12', '81', '193', '212', '247', '100', '1'],
['127', '211', '164', '202', '25', '149', '34'],
['214', '38', '10', '197', '195', '97', '193'],
['177', '120', '199', '180', '206', '184', '155'],
['154', '146', '186', '205', '190', '47', '169'],
['164', '80', '233', '207', '214', '91', '108'],
['123', '101', '231', '244', '92', '88', '12'],
['222', '193', '85', '98', '224', '145', '0']
], key_type=DarcKeyTypes.alphabet)
# 14 Server (Substitution) Key
server_substitution_key = DarcKey(matrix=[
['163', '247', '59', '226', '186', '179', '35'],
['140', '180', '54', '88', '40', '252', '97'],
['229', '247', '16', '206', '186', '125', '81'],
['221', '222', '54', '22', '190', '18', '122'],
['126', '130', '83', '142', '152', '238', '237'],
['76', '168', '77', '176', '198', '119', '104'],
['121', '96', '80', '75', '138', '219', '122'],
['92', '210', '20', '56', '232', '219', '245'],
['111', '1', '155', '236', '15', '184', '0'],
['36', '31', '143', '5', '112', '206', '106']
],
key_type=DarcKeyTypes.alphabet
)
# 24 Server (Substitution) Ephemeral Unique Component Function
server_substitution_ephemeral_unique_component_function = 5
# 25 Shared (Mutual) (Substitution) Ephemeral Key
shared_mutual_substitution_ephemeral_key = DarcKey(matrix=[
['106', '113', '9', '54', '49', '4', '207'],
['184', '3', '232', '179', '15', '113', '142'],
['129', '44', '164', '54', '1', '32', '201'],
['106', '50', '246', '140', '149', '179', '109'],
['210', '11', '69', '193', '77', '245', '62'],
['37', '76', '137', '24', '220', '30', '165'],
['40', '57', '147', '225', '24', '176', '103'],
['37', '212', '189', '203', '218', '138', '168'],
['73', '227', '38', '164', '20', '239', '24'],
['7', '194', '254', '76', '0', '244', '215']
], key_type=DarcKeyTypes.alphabet)
# 26 Client (Substitution) Ephemeral Key
client_substitution_ephemeral_key = DarcKey(matrix=[
['21', '149', '75', '73', '228', '81', '79'],
['41', '189', '80', '209', '45', '101', '53'],
['139', '238', '141', '159', '30', '79', '214'],
['239', '234', '72', '75', '80', '190', '124'],
['203', '225', '246', '200', '205', '195', '92'],
['201', '185', '113', '101', '176', '216', '106'],
['14', '210', '125', '70', '53', '128', '57'],
['115', '27', '97', '39', '199', '26', '104'],
['29', '4', '55', '5', '13', '57', '19'],
['158', '184', '137', '0', '221', '12', '217']
], key_type=DarcKeyTypes.alphabet)
# 27 Server (Substitution) Ephemeral Random Component
server_substitution_ephemeral_random_component = DarcKey(matrix=[
['191', '50', '229', '60', '201', '64', '45'],
['31', '88', '90', '8', '153', '6', '228'],
['117', '63', '38', '90', '236', '207', '254'],
['64', '219', '36', '3', '119', '205', '171'],
['172', '138', '153', '52', '161', '137', '216'],
['49', '150', '210', '129', '174', '190', '54'],
['81', '230', '135', '200', '218', '31', '52'],
['128', '253', '177', '220', '1', '83', '3'],
['204', '199', '43', '50', '148', '215', '6'],
['79', '124', '128', '30', '74', '242', '85']
], key_type=DarcKeyTypes.alphabet)
# 28 Server (Substitution) Ephemeral Unique Component
server_substitution_ephemeral_unique_component = DarcKey(matrix=[
['7', '190', '58', '75', '135', '15', '214', '149', '244', '224']
], key_type=DarcKeyTypes.alphabet)
# 30 Shared (Mutual) (Substitution) Key
shared_mutual_substitution_key = shared_mutual_substitution_component_1 ^ client_substitution_key
# 31 Outer (Mutual) Function Function Ephemeral Key Applied = Outer (Mutual) (Substitution) Function Function Key << Outer (Mutual) (Substitution) Function Function Ephemeral Key
outer_mutual_function_function_ephemeral_key_applied = outer_mutual_substitution_function_function_key << outer_mutual_substitution_function_function_ephemeral_key
# 32 Inner (Mutual) Function Applied Key = (Mutual) (Substitution) Function Key << (Mutual) (Substitution) Function Ephemeral Key
inner_mutual_function_applied_key = mutual_substitution_function_key << mutual_substitution_function_ephemeral_key
# 33 Inner (Mutual) Function Key Scratch = Inner (Mutual) Function Applied Key << Outer (Mutual) Function Function Ephemeral Key Applied
inner_mutual_function_key_scratch = inner_mutual_function_applied_key < outer_mutual_function_function_ephemeral_key_applied
# 34 Outer Server (Mutual) Shuffle (Permutation) Function Ephemeral Key Applied = Outer Server (Mutual) Shuffle (Permutation) Function Key << Outer Server (Mutual) Shuffle (Permutation) Function Ephemeral Key
outer_server_mutual_shuffle_permutation_function_ephemeral_key_applied = outer_mutual_shuffle_permutation_function_key << outer_server_mutual_shuffle_permutation_function_ephemeral_key
# 35 Client Shuffle (Permutation) Key X Scratch = Client Shuffle (Permutation) Key X < Outer Server (Mutual) Shuffle (Permutation) Function Ephemeral Key Applied
client_shuffle_permutation_key_x_scratch = client_shuffle_permutation_key_x < outer_server_mutual_shuffle_permutation_function_ephemeral_key_applied
# 36 Inner Function Key Scratch 2 = Inner (Mutual) Function Key Scratch << Client Shuffle (Permutation) Key X Scratch
inner_function_key_scratch_2 = inner_mutual_function_key_scratch << client_shuffle_permutation_key_x_scratch
# 37 Outer (Mutual) Function Ephemeral Key Applied = Outer (Mutual) (Substitution) Function Key < Outer (Mutual) (Substitution) Function Ephemeral Key
outer_mutual_function_ephemeral_key_applied = outer_mutual_substitution_function_key << outer_mutual_substitution_function_ephemeral_key
# 38 Server (Substitution) Key Scratch = Server (Substitution) Key < Outer (Mutual) Function Ephemeral Key Applied
server_substitution_key_scratch = server_substitution_key < outer_mutual_function_ephemeral_key_applied
# 39 Shared (Mutual) (Substitution) Key Scratch = Shared (Mutual) (Substitution) Key < Outer (Mutual) Function Ephemeral Key Applied
shared_mutual_substitution_key_scratch = shared_mutual_substitution_key < outer_mutual_function_ephemeral_key_applied
# 40 Shared (Mutual) (Substitution) Ephemeral Key Server Scratch = Shared (Mutual) (Substitution) Ephemeral Key < Outer (Mutual) Function Ephemeral Key Applied
shared_mutual_substitution_ephemeral_key_server_scratch = shared_mutual_substitution_ephemeral_key < outer_mutual_function_ephemeral_key_applied
# line 78
# 41 Server Client Shuffle (Permutation) = Server Shuffle (Permutation) Key << Client Shuffle (Permutation) Key X
server_client_shuffle_permutation = server_shuffle_permutation_key << client_shuffle_permutation_key_x
# 42 Server Client Shuffle (Permutation) Inverse
server_client_shuffle_permutation_inverse = ~server_client_shuffle_permutation
# 43 Server Shuffle (Permutation) Ephemeral Key 1 Inverse (remove 1) = ~(Server Shuffle (Permutation) Ephemeral Key 1 (remove 1))
server_shuffle_permutation_ephemeral_key_1_inverse = ~server_shuffle_permutation_ephemeral_key_1
# 44 Server Shuffle (Permutation) Ephemeral Key Applied = Server Client Shuffle (Permutation) Inverse < Server Shuffle (Permutation) Ephemeral Key 1 Inverse (remove 1)
server_shuffle_permutation_ephemeral_key_applied = server_client_shuffle_permutation_inverse << server_shuffle_permutation_ephemeral_key_1_inverse
# line 82
# 45 Server Shuffle (Permutation) Ephemeral Key Applied Scratch = Server Shuffle (Permutation) Ephemeral Key Applied < Outer Server (Mutual) Shuffle (Permutation) Function Ephemeral Key Applied
server_shuffle_permutation_ephemeral_key_applied_scratch = server_shuffle_permutation_ephemeral_key_applied < outer_server_mutual_shuffle_permutation_function_ephemeral_key_applied
# 46 Server Shuffle (Permutation) Ephemeral Key Applied Scratch Inverse = ~Server Shuffle (Permutation) Ephemeral Key Applied Scratch
server_shuffle_permutation_ephemeral_key_applied_scratch_inverse = ~server_shuffle_permutation_ephemeral_key_applied_scratch
# 47 Outer Server Shuffle (Permutation) Ephemeral Key Applied = Outer Server Shuffle (Permutation) Key < Outer Server Shuffle (Permutation) Ephemeral Key
outer_server_shuffle_permutation_ephemeral_key_applied = outer_server_shuffle_permutation_key << outer_server_shuffle_permutation_ephemeral_key
# 48 Alphabet Scratch 1 = Alphabet Values < Outer Server Shuffle (Permutation) Ephemeral Key Applied
alphabet_scratch_1 = alphabet_values < outer_server_shuffle_permutation_ephemeral_key_applied
# 49 Alphabet Scratch 2 = Alphabet Scratch 1 << Server Shuffle (Permutation) Ephemeral Key Applied Scratch Inverse
alphabet_scratch_2 = alphabet_scratch_1 << server_shuffle_permutation_ephemeral_key_applied_scratch_inverse
# 50 Server (Substitution) Ephemeral Component Scratch 1 = Server (Substitution) Ephemeral Random Component.column_substitution( Server (Substitution) Ephemeral Unique Component Function ,Server (Substitution) Ephemeral Unique Component)
server_substitution_ephemeral_component_scratch_1 = server_substitution_ephemeral_random_component.column_substitution(
server_substitution_ephemeral_unique_component_function,
server_substitution_ephemeral_unique_component.matrix[0]
)
# 51 Server (Substitution) Ephemeral Component Scratch 2 = Server (Substitution) Ephemeral Component Scratch 1 < Outer (Mutual) Function Ephemeral Key Applied
server_substitution_ephemeral_component_scratch_2 = server_substitution_ephemeral_component_scratch_1 < outer_mutual_function_ephemeral_key_applied
# 52 Server (Substitution) Ephemeral Component Scratch 3 = Alphabet Scratch 2 ^ (Server (Substitution) Key Scratch << Inner Function Key Scratch 2) ^ (Server (Substitution) Ephemeral Component Scratch 2 << Inner Function Key Scratch 2) ^ (Shared (Mutual) (Substitution) Key Scratch << Inner Function Key Scratch 2) ^ (Shared (Mutual) (Substitution) Ephemeral Key Server Scratch << Inner Function Key Scratch 2)
server_substitution_ephemeral_component_scratch_3 = alphabet_scratch_2 ^ (server_substitution_key_scratch << inner_function_key_scratch_2) ^ (server_substitution_ephemeral_component_scratch_2 << inner_function_key_scratch_2) ^ (shared_mutual_substitution_key_scratch << inner_function_key_scratch_2) ^ (shared_mutual_substitution_ephemeral_key_server_scratch << inner_function_key_scratch_2)
# 52 Inner Function Key Scratch 2 Inverse = ~Inner Function Key Scratch 2
inner_function_key_scratch_2_inverse = ~inner_function_key_scratch_2
# 54 Server (Substitution) Ephemeral Key Scratch = Server (Substitution) Ephemeral Component Scratch 3 << Inner Function Key Scratch 2 Inverse
server_substitution_ephemeral_key_scratch = server_substitution_ephemeral_component_scratch_3 << inner_function_key_scratch_2_inverse
# 55 Outer (Mutual) Function Ephemeral Key Applied Inverse = ~Outer (Mutual) Function Ephemeral Key Applied
outer_mutual_function_ephemeral_key_applied_inverse = ~outer_mutual_function_ephemeral_key_applied
# 56 Server (Substitution) Ephemeral Key = Server (Substitution) Ephemeral Key Scratch < Outer (Mutual) Function Ephemeral Key Applied Inverse
server_substitution_ephemeral_key = server_substitution_ephemeral_key_scratch < outer_mutual_function_ephemeral_key_applied_inverse
# line 94
""" Server Tx (Phase 1) """
# 57 Inner Server Shuffle (Permutation) Key Applied = Server Shuffle (Permutation) Ephemeral Key 1 (remove 1) << Server Shuffle (Permutation) Key
inner_server_shuffle_permutation_key_applied = server_shuffle_permutation_ephemeral_key_1 << server_shuffle_permutation_key
# 58 Outer Server Shuffle (Permutation) Key Applied = Inner Server Shuffle (Permutation) Key Applied < Outer Server (Mutual) Shuffle (Permutation) Function Ephemeral Key Applied
outer_server_shuffle_permutation_key_applied = inner_server_shuffle_permutation_key_applied < outer_server_mutual_shuffle_permutation_function_ephemeral_key_applied
# 59 Server (Substitution) Ephemeral Key Scratch = Server (Substitution) Ephemeral Key < Outer (Mutual) Function Ephemeral Key Applied
server_substitution_ephemeral_key_scratch = server_substitution_ephemeral_key < outer_mutual_function_ephemeral_key_applied
# 86 Outer Shuffle (Permutation) = Alphabet Values << Outer Server Shuffle (Permutation) Ephemeral Key Applied
#outer_shuffle_permutation = alphabet_values < outer_server_shuffle_permutation_ephemeral_key_applied
## 87 Inner Shuffle (Permutation) = Outer Shuffle (Permutation) << Outer Server Shuffle (Permutation) Key Applied
#inner_shuffle_permutation = outer_shuffle_permutation << outer_server_shuffle_permutation_key_applied
## 88 Translation (Substitution) = Inner Shuffle (Permutation) ^ (Server (Substitution) Ephemeral Key Scratch << Inner (Mutual) Function Key Scratch) ^ (Server (Substitution) Key Scratch << Inner (Mutual) Function Key Scratch)
#translation_substitution = inner_shuffle_permutation ^ (
# server_substitution_ephemeral_key_scratch << inner_mutual_function_key_scratch) ^ (
# server_substitution_key_scratch << inner_mutual_function_key_scratch)
# line 108
""" Client Rx (Phase 2) """
# 62 Client (Substitution) Key A Scratch = Client (Substitution) Key < Outer (Mutual) Function Ephemeral Key Applied
client_substitution_key_a_scratch = client_substitution_key < outer_mutual_function_ephemeral_key_applied
# 63 Client (Substitution) Ephemeral Key A Scratch = Client (Substitution) Ephemeral Key < Outer (Mutual) Function Ephemeral Key Applied
client_substitution_ephemeral_key_a_scratch = client_substitution_ephemeral_key < outer_mutual_function_ephemeral_key_applied
# 64 Client Shuffle (Permutation) Key A Applied (remove A) = Client Shuffle (Permutation) Key A Applied (remove A) << Client Shuffle (Permutation) Ephemeral Key A (remove A)
client_shuffle_permutation_key_a_applied = client_shuffle_permutation_key_a << client_shuffle_permutation_ephemeral_key_a
# 65 Client Shuffle (Permutation) Key A Scratch (remove A) = Client Shuffle (Permutation) Key A Applied (remove A) < Outer Server (Mutual) Shuffle (Permutation) Function Ephemeral Key Applied
client_shuffle_permutation_key_a_scratch = client_shuffle_permutation_key_a_applied < outer_server_mutual_shuffle_permutation_function_ephemeral_key_applied
# 66 Outer Client Shuffle (Permutation) Ephemeral Key Applied = Outer Client Shuffle (Permutation) Key << Outer Client Shuffle (Permutation) Ephemeral Key
outer_client_shuffle_permutation_ephemeral_key_applied = outer_client_shuffle_permutation_key << outer_client_shuffle_permutation_ephemeral_key
# 67 Outer Client Shuffle (Permutation) Function Ephemeral Key Applied = Outer Client Shuffle (Permutation) Function Key << Outer Client Shuffle (Permutation) Function Ephemeral Key
outer_client_shuffle_permutation_function_ephemeral_key_applied = outer_client_shuffle_permutation_function_key << outer_client_shuffle_permutation_function_ephemeral_key
# 68 Outer Client Shuffle (Permutation) Function Key Applied = Outer Client Shuffle (Permutation) Ephemeral Key Applied << Outer Client Shuffle (Permutation) Function Ephemeral Key Applied
outer_client_shuffle_permutation_function_key_applied = outer_client_shuffle_permutation_ephemeral_key_applied << outer_client_shuffle_permutation_function_ephemeral_key_applied
# 69 Outer Client Shuffle (Permutation) Function Key Applied Inverse = ~Outer Client Shuffle (Permutation) Function Key Applied
outer_client_shuffle_permutation_function_key_applied_inverse = ~outer_client_shuffle_permutation_function_key_applied
# 70 Alphabet Input Sequence Scratch = Outer Client Shuffle (Permutation) Function Key Applied Inverse << Alphabet Input Sequence
alphabet_input_sequence_scratch = outer_client_shuffle_permutation_function_key_applied_inverse << alphabet_input_sequence
# 89 Translation (Substitution) - Client Data = Translation (Substitution) ^ (Shared (Mutual) (Substitution) Key Scratch << Inner (Mutual) Function Key Scratch) ^ (Client (Substitution) Key A Scratch << Inner (Mutual) Function Key Scratch) ^ (Client (Substitution) Ephemeral Key A Scratch << Inner (Mutual) Function Key Scratch)
#translation_substitution_client_data = translation_substitution ^ (
# shared_mutual_substitution_key_scratch << inner_mutual_function_key_scratch) ^ (
# client_substitution_key_a_scratch << inner_mutual_function_key_scratch) ^ (
# client_substitution_ephemeral_key_a_scratch << inner_mutual_function_key_scratch)
## 90 Inner Shuffle (Permutation) - CSKA+CSEKA = Translation (Substitution) - Client Data << Client Shuffle (Permutation) Key A Scratch (remove A)
#inner_shuffle_permutation_cska_cseka = translation_substitution_client_data << client_shuffle_permutation_key_a_scratch
## 91 Outer Shuffle (Permutation) - Client Rest = Inner Shuffle (Permutation) - CSKA+CSEKA << Outer Client Shuffle (Permutation) Function Key Applied
#outer_shuffle_permutation_client_rest = inner_shuffle_permutation_cska_cseka < outer_client_shuffle_permutation_function_key_applied
# line 130
""" Client Tx (Phase 3) """
# 71 Client Shuffle (Permutation) Key A Inverse (remove A) = ~Client Shuffle (Permutation) Key A (remove A)
client_shuffle_permutation_key_a_inverse = ~client_shuffle_permutation_key_a
# 72 Client Shuffle (Permutation) Key B (remove B) = Client Shuffle (Permutation) Key A Inverse (remove A) << Client Shuffle (Permutation) Key X
client_shuffle_permutation_key_b = client_shuffle_permutation_key_a_inverse << client_shuffle_permutation_key_x
# 73 Client Shuffle (Permutation) Ephemeral Key A (remove A) Inverse = ~Client Shuffle (Permutation) Ephemeral Key A (remove A)
client_shuffle_permutation_ephemeral_key_a_inverse = ~client_shuffle_permutation_ephemeral_key_a
# 74 Client Shuffle (Permutation) Key B Applied = Client Shuffle (Permutation) Ephemeral Key B << Client Shuffle (Permutation) Key B (remove B)
client_shuffle_permutation_key_b_applied = client_shuffle_permutation_ephemeral_key_a_inverse << client_shuffle_permutation_key_b
# 75 Outer Server (Mutual) Shuffle (Permutation) Function Key Scratch = Outer Server (Mutual) Shuffle (Permutation) Function Ephemeral Key Applied << Outer Client Shuffle (Permutation) Function Key Applied
outer_server_mutual_shuffle_permutation_function_key_scratch = outer_server_mutual_shuffle_permutation_function_ephemeral_key_applied << outer_client_shuffle_permutation_function_key_applied
# 76 Client Shuffle (Permutation) Key B Scratch = Client Shuffle (Permutation) Key B Applied < Outer Server (Mutual) Shuffle (Permutation) Function Key Scratch
client_shuffle_permutation_key_b_scratch = client_shuffle_permutation_key_b_applied < outer_server_mutual_shuffle_permutation_function_key_scratch
# 77 Client Shuffle (Permutation) Key X Scratch 2 = Client Shuffle (Permutation) Key X < Outer Server (Mutual) Shuffle (Permutation) Function Key Scratch
client_shuffle_permutation_key_x_scratch_2 = client_shuffle_permutation_key_x < outer_server_mutual_shuffle_permutation_function_key_scratch
# line 144
# 78 Outer Function Function Key Scratch = Outer (Mutual) Function Function Ephemeral Key Applied << Outer Client Shuffle (Permutation) Function Key Applied
outer_function_function_key_scratch = outer_mutual_function_function_ephemeral_key_applied << outer_client_shuffle_permutation_function_key_applied
# 79 Inner (Mutual) Function Key Client Scratch = Inner (Mutual) Function Applied Key < Outer Function Function Key Scratch
inner_mutual_function_key_client_scratch = inner_mutual_function_applied_key < outer_function_function_key_scratch
# line 147
# 80 (Mutual) Function Key Scratch 2 = Inner (Mutual) Function Key Client Scratch << client_shuffle_permutation_key_x_scratch_2
mutual_function_key_scratch_2 = inner_mutual_function_key_client_scratch << client_shuffle_permutation_key_x_scratch_2
# 81 Outer (Mutual) Function Key Scratch = Outer (Mutual) Function Ephemeral Key Applied << Outer Client Shuffle (Permutation) Function Key Applied
outer_mutual_function_key_scratch = outer_mutual_function_ephemeral_key_applied << outer_client_shuffle_permutation_function_key_applied
# 82 Client (Substitution) Key B Scratch = Client (Substitution) Key < Outer (Mutual) Function Key Scratch
client_substitution_key_b_scratch = client_substitution_key < outer_mutual_function_key_scratch
# 83 Client (Substitution) Ephemeral Key B Scratch = Client (Substitution) Ephemeral Key < Outer (Mutual) Function Key Scratch
client_substitution_ephemeral_key_b_scratch = client_substitution_ephemeral_key < outer_mutual_function_key_scratch
# 84 Shared (Mutual) (Substitution) Ephemeral Key Client Scratch = Shared (Mutual) (Substitution) Ephemeral Key < Outer (Mutual) Function Key Scratch
shared_mutual_substitution_ephemeral_key_client_scratch = shared_mutual_substitution_ephemeral_key < outer_mutual_function_key_scratch
# 92 Inner Shuffle (Permutation) - CSEKB +CSKB = Outer Shuffle (Permutation) - Client Rest << Client Shuffle (Permutation) Key B Scratch
#inner_shuffle_permutation_csekb_cskb = outer_shuffle_permutation_client_rest << client_shuffle_permutation_key_b_scratch
## 93 Translation (Substitution) DARC Data = Inner Shuffle (Permutation) - CSEKB +CSKB ^ (Client (Substitution) Key B Scratch << (Mutual) Function Key Scratch 2) ^ (Client (Substitution) Ephemeral Key B Scratch << (Mutual) Function Key Scratch 2) ^ (Shared (Mutual) (Substitution) Ephemeral Key Client Scratch << (Mutual) Function Key Scratch 2)
#translation_substitution_darc_data = inner_shuffle_permutation_csekb_cskb ^ (
# client_substitution_key_b_scratch << mutual_function_key_scratch_2) ^ (
# client_substitution_ephemeral_key_b_scratch << mutual_function_key_scratch_2) ^ (
# shared_mutual_substitution_ephemeral_key_client_scratch << mutual_function_key_scratch_2)
# line 175
""" Server Rx (Phase 4) """
# 85 Translation (Substitution) = Alphabet Scratch 2 ^ (Server (Substitution) Key Scratch << Inner Function Key Scratch 2) ^ (Server (Substitution) Ephemeral Key Scratch << Inner Function Key Scratch 2) ^ (Shared (Mutual) (Substitution) Key Scratch << Inner Function Key Scratch 2) ^ (Shared (Mutual) (Substitution) Ephemeral Key Server Scratch << Inner Function Key Scratch 2)
translation_substitution = (
alphabet_scratch_2 ^
(server_substitution_key_scratch << inner_function_key_scratch_2) ^
(server_substitution_ephemeral_key_scratch << inner_function_key_scratch_2) ^
(shared_mutual_substitution_key_scratch << inner_function_key_scratch_2) ^
(shared_mutual_substitution_ephemeral_key_server_scratch << inner_function_key_scratch_2)
)
a = 1

361
src/models.py Normal file
View File

@@ -0,0 +1,361 @@
import secrets
from enum import Enum
from pydantic import BaseModel
class DarcKeyTypes(str, Enum):
outer_shuffle = "outer_shuffle"
inner_shuffle = "inner_shuffle"
alphabet = "alphabet"
other = "other"
class DarcKey(BaseModel):
matrix: list[list[int]]
key_type: DarcKeyTypes
@classmethod
def _random_shuffle(cls, array: list[int]) -> list[int]:
for i in range(len(array) - 1, 0, -1):
j = cls._random_number(0, i)
array[i], array[j] = array[j], array[i]
return array
@classmethod
def _random_mask(cls, array_len: int, max_val: int) -> list[int]:
return [cls._random_number(0, max_val) for _ in range(array_len)]
@staticmethod
def _random_number(min_val: int, max_val: int) -> int:
""" originally secure_rand """
return min_val + secrets.randbelow(max_val - min_val + 1)
def __lshift__(self, other):
assert len(self.matrix) == len(other.matrix)
assert len(self.matrix[0]) == len(other.matrix[0])
assert other.key_type == DarcKeyTypes.inner_shuffle or other.key_type == DarcKeyTypes.outer_shuffle
output = []
for i, el in enumerate(self.matrix):
row = []
for j, el2 in enumerate(el):
other_el = other.matrix[i][j]
row.append(self.matrix[i][other_el])
output.append(row)
return DarcKey(
matrix=output,
key_type=self.key_type
)
def __lt__(self, other):
assert len(other.matrix) == 1
assert len(self.matrix) == len(other.matrix[0])
assert other.key_type == DarcKeyTypes.outer_shuffle
output = []
for i, _ in enumerate(self.matrix):
output.append(self.matrix[other.matrix[0][i]])
return DarcKey(
matrix=output,
key_type=self.key_type
)
def __xor__(self, other):
assert len(self.matrix) == len(other.matrix)
assert len(self.matrix[0]) == len(other.matrix[0])
assert self.key_type == DarcKeyTypes.alphabet
assert other.key_type == DarcKeyTypes.alphabet
output = []
for i, el in enumerate(self.matrix):
row = []
for j, el2 in enumerate(el):
row.append(el2 ^ other.matrix[i][j])
output.append(row)
return DarcKey(
matrix=output,
key_type=self.key_type
)
def __invert__(self):
assert self.key_type == DarcKeyTypes.inner_shuffle or self.key_type == DarcKeyTypes.outer_shuffle
output = []
for i, el in enumerate(self.matrix):
row = [(j, el2) for j, el2 in enumerate(el)]
row.sort(key=lambda x: x[1])
output.append([el2[0] for el2 in row])
return DarcKey(
matrix=output,
key_type=self.key_type
)
def column_substitution(self, column: int, substitution: list[int]):
assert len(substitution) == len(self.matrix)
assert len(self.matrix[0]) > column >= 0
output = []
for i, el in enumerate(self.matrix):
row = []
for j, el2 in enumerate(el):
if j == column:
row.append(substitution[i])
else:
row.append(el2)
output.append(row)
return DarcKey(
matrix=output,
key_type=self.key_type
)
class OuterShuffleKey(DarcKey):
key_type = DarcKeyTypes.outer_shuffle
@classmethod
def init_matrix(cls, row_length: int):
""" originally buildRandom """
matrix = [cls._random_shuffle(list(range(row_length)))]
return OuterShuffleKey(
matrix=matrix,
)
class InnerShuffleKey(DarcKey):
key_type = DarcKeyTypes.inner_shuffle
@classmethod
def init_matrix(cls, row_length: int, column_length: int):
""" originally buildRandom """
matrix = [cls._random_shuffle(list(range(row_length))) for _ in range(column_length)]
return InnerShuffleKey(
matrix=matrix,
)
class AlphabetKey(DarcKey):
key_type = DarcKeyTypes.alphabet
max_value: int = 255
@classmethod
def init_matrix(cls, row_length: int, column_length: int, max_value: int):
""" originally buildScramble """
matrix = [cls._random_mask(row_length, max_value) for _ in range(column_length)]
return AlphabetKey(
matrix=matrix,
max_value=max_value
)
class EphemeralKeys(BaseModel):
serverEphemeralKey: AlphabetKey
sharedEphemeralKey: AlphabetKey
functionEphemeralKey: InnerShuffleKey
outerFunctionEphemeralKey: OuterShuffleKey
outerFunctionFunctionEphemeralKey: OuterShuffleKey
outerServerShuffleFunctionEphemeralKey: OuterShuffleKey
serverShuffleEphemeralKey: InnerShuffleKey
outerServerShuffleEphemeralKey: OuterShuffleKey
serverMediumEphemeralKey: AlphabetKey
sharedMediumEphemeralKey: AlphabetKey
functionMediumEphemeralKey: InnerShuffleKey
positionFunctionMediumEphemeralKey: InnerShuffleKey
outerFunctionMediumEphemeralKey: OuterShuffleKey
outerFunctionFunctionMediumEphemeralKey: OuterShuffleKey
outerPositionFunctionMediumEphemeralKey: OuterShuffleKey
outerServerShuffleFunctionMediumEphemeralKey: OuterShuffleKey
outerServerShuffleMediumEphemeralKey: OuterShuffleKey
outerPositionShuffleMediumEphemeralKey: OuterShuffleKey
interfaceConfig: AlphabetKey
outerClientShuffleKey: OuterShuffleKey
outerClientShuffleMediumKey: OuterShuffleKey
outerClientShuffleFunctionKey: OuterShuffleKey
outerClientShuffleFunctionMediumKey: OuterShuffleKey
clientEphemeral: AlphabetKey
clientEphemeralMedium: AlphabetKey
clientShuffleEphemeralA: InnerShuffleKey
clientShuffleEphemeralMediumA: InnerShuffleKey
class PersistentKeys(BaseModel):
serverKey: AlphabetKey
functionKey: InnerShuffleKey
serverShuffleKey: InnerShuffleKey
outerFunctionKey: OuterShuffleKey
outerFunctionFunctionKey: OuterShuffleKey
outerServerShuffleKey: OuterShuffleKey
outerServerShuffleFunctionKey: OuterShuffleKey
clientKey: AlphabetKey
sharedKey: AlphabetKey
clientShuffleKeyX: InnerShuffleKey
clientShuffleKeyA: InnerShuffleKey
functionMediumKey: InnerShuffleKey
clientShuffleMediumKeyX: InnerShuffleKey
inputMediumData: AlphabetKey
serverMediumKey: OuterShuffleKey
outerFunctionMediumKey: OuterShuffleKey
outerFunctionFunctionMediumKey: OuterShuffleKey
outerServerShuffleMediumKey: OuterShuffleKey
outerServerShuffleFunctionMediumKey: OuterShuffleKey
sharedMediumKey: AlphabetKey
outerPositionFunctionMediumKey: OuterShuffleKey
outerPositionShuffleMediumKey: OuterShuffleKey
clientMediumKey: AlphabetKey
positionFunctionMediumKey: InnerShuffleKey
clientShuffleMediumKeyA: InnerShuffleKey
class Session(BaseModel):
guid: str
interfaceConfig: AlphabetKey
serverEphemeralKey: AlphabetKey
functionEphemeralKey: InnerShuffleKey
serverShuffleEphemeralKey: InnerShuffleKey
outerServerShuffleEphemeralKey: OuterShuffleKey
outerFunctionEphemeralKey: OuterShuffleKey
outerFunctionFunctionEphemeralKey: OuterShuffleKey
outerServerShuffleFunctionEphemeralKey: OuterShuffleKey
serverMediumEphemeralKey: AlphabetKey
functionMediumEphemeralKey: InnerShuffleKey
outerServerShuffleMediumEphemeralKey: OuterShuffleKey
outerFunctionMediumEphemeralKey: OuterShuffleKey
outerFunctionFunctionMediumEphemeralKey: OuterShuffleKey
outerServerShuffleFunctionMediumEphemeralKey: OuterShuffleKey
positionFunctionMediumEphemeralKey: InnerShuffleKey
outerPositionFunctionMediumEphemeralKey: OuterShuffleKey
sharedEphemeralKey: AlphabetKey
sharedMediumEphemeralKey: AlphabetKey
outerPositionShuffleMediumEphemeralKey: OuterShuffleKey
class TxData(BaseModel):
data: AlphabetKey
functionEphemeralKey: InnerShuffleKey
outerServerShuffleEphemeralKey: OuterShuffleKey
outerFunctionFunctionEphemeralKey: OuterShuffleKey
outerFunctionEphemeralKey: OuterShuffleKey
outerServerShuffleFunctionEphemeralKey: OuterShuffleKey
sharedEphemeralKey: AlphabetKey
outerClientShuffleKey: OuterShuffleKey
outerClientShuffleFunctionKey: OuterShuffleKey
clientEphemeral: AlphabetKey
clientShuffleEphemeralA: InnerShuffleKey
clientShuffleEphemeralB: InnerShuffleKey
class Medium(BaseModel):
data: AlphabetKey
functionEphemeralKey: InnerShuffleKey
outerServerShuffleEphemeralKey: OuterShuffleKey
outerFunctionFunctionEphemeralKey: OuterShuffleKey
outerFunctionEphemeralKey: OuterShuffleKey
outerServerShuffleFunctionEphemeralKey: OuterShuffleKey
sharedEphemeralKey: AlphabetKey
positionFunctionMediumEphemeralKey: InnerShuffleKey
outerPositionFunctionMediumEphemeralKey: OuterShuffleKey
outerPositionShuffleMediumEphemeralKey: OuterShuffleKey
outerClientShuffleMediumKey: OuterShuffleKey
outerClientShuffleFunctionMediumKey: OuterShuffleKey
clientEphemeralMedium: AlphabetKey
clientShuffleEphemeralMediumA: InnerShuffleKey
clientShuffleEphemeralMediumB: InnerShuffleKey
class Phase1Session(BaseModel):
session: Session
tx_data: TxData
medium: Medium
alphabet: list[list[int]] | None = None
class ServerPersistentKeys(BaseModel):
OuterFunctionKey: OuterShuffleKey
OuterFunctionFunctionKey: OuterShuffleKey
OuterServerShuffleFunctionKey: OuterShuffleKey
MutualKey: AlphabetKey
FunctionKey: InnerShuffleKey
ClientShuffleKeyX: InnerShuffleKey
MutualMediumKey: AlphabetKey
OuterFunctionMediumKey: OuterShuffleKey
OuterFunctionFunctionMediumKey: OuterShuffleKey
OuterServerShuffleFunctionMediumKey: OuterShuffleKey
FunctionMediumKey: InnerShuffleKey
ClientShuffleMediumKeyX: InnerShuffleKey
OuterPositionShuffleMediumKey: OuterShuffleKey
OuterPositionShuffleFunctionMediumKey: OuterShuffleKey
OuterPositionFunctionMediumKey: OuterShuffleKey
PositionFunctionMediumKey: InnerShuffleKey
PositionShuffleMediumKey: InnerShuffleKey
OuterServerShuffleKey: OuterShuffleKey
ServerKey: AlphabetKey
ServerShuffleKey: InnerShuffleKey
ServerMediumKey: AlphabetKey
class ClientPersistentKeys(BaseModel):
OuterFunctionKey: OuterShuffleKey
OuterFunctionFunctionKey: OuterShuffleKey
OuterServerShuffleFunctionKey: OuterShuffleKey
MutualKey: AlphabetKey
FunctionKey: InnerShuffleKey
ClientShuffleKeyX: InnerShuffleKey
MutualMediumKey: AlphabetKey
OuterFunctionMediumKey: OuterShuffleKey
OuterFunctionFunctionMediumKey: OuterShuffleKey
OuterServerShuffleFunctionMediumKey: OuterShuffleKey
FunctionMediumKey: InnerShuffleKey
ClientShuffleMediumKeyX: InnerShuffleKey
OuterPositionShuffleMediumKey: OuterShuffleKey
OuterPositionShuffleFunctionMediumKey: OuterShuffleKey
OuterPositionFunctionMediumKey: OuterShuffleKey
PositionFunctionMediumKey: InnerShuffleKey
PositionShuffleMediumKey: InnerShuffleKey
ClientKey: AlphabetKey
ClientShuffleKeyA: InnerShuffleKey
OuterClientShuffleKey: OuterShuffleKey
OuterClientShuffleFunctionKey: OuterShuffleKey
OuterClientShuffleMediumKey: OuterShuffleKey
OuterClientShuffleFunctionMediumKey: OuterShuffleKey
ClientShuffleMediumKeyA: InnerShuffleKey
ClientMediumKey: AlphabetKey
class ServerEphemeralKeys(BaseModel):
OuterServerShuffleEphemeralKey: OuterShuffleKey
ServerEphemeralKey: AlphabetKey
ServerShuffleEphemeralKey: InnerShuffleKey
ServerMediumEphemeralKey: AlphabetKey
Alphabet: AlphabetKey
class MutualEphemeralKeys(BaseModel):
MutualEphemeralKey: AlphabetKey
FunctionEphemeralKey: InnerShuffleKey
OuterFunctionEphemeralKey: OuterShuffleKey
OuterFunctionFunctionEphemeralKey: OuterShuffleKey
OuterServerShuffleFunctionEphemeralKey: OuterShuffleKey
MutualMediumEphemeralKey: AlphabetKey
FunctionMediumEphemeralKey: InnerShuffleKey
PositionFunctionMediumEphemeralKey: InnerShuffleKey
OuterFunctionMediumEphemeralKey: OuterShuffleKey
OuterFunctionFunctionMediumEphemeralKey: OuterShuffleKey
OuterPositionFunctionMediumEphemeralKey: OuterShuffleKey
OuterServerShuffleFunctionMediumEphemeralKey: OuterShuffleKey
OuterPositionShuffleFunctionMediumEphemeralKey: OuterShuffleKey
PositionShuffleMediumEphemeralKey: InnerShuffleKey
OuterPositionShuffleMediumEphemeralKey: OuterShuffleKey
class ClientEphemeralKeys(BaseModel):
OuterClientShuffleEphemeralKey: OuterShuffleKey
OuterClientShuffleFunctionEphemeralKey: OuterShuffleKey
ClientEphemeralKey: AlphabetKey
ClientShuffleEphemeralKeyA: InnerShuffleKey
OuterClientShuffleMediumEphemeralKey: OuterShuffleKey
OuterClientShuffleFunctionMediumEphemeralKey: OuterShuffleKey
ClientShuffleMediumEphemeralKeyA: InnerShuffleKey
ClientMediumEphemeralKey: AlphabetKey

13
src/test.py Normal file
View File

@@ -0,0 +1,13 @@
from models import OuterShuffleKey
outer_shuffle_key = OuterShuffleKey(
matrix=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]],
)
random_outer_shuffle_key = OuterShuffleKey.init_matrix(10)
applied_outer_shuffle_key = outer_shuffle_key << random_outer_shuffle_key
print(applied_outer_shuffle_key)
print(applied_outer_shuffle_key << outer_shuffle_key)

90
src/utils.py Normal file
View File

@@ -0,0 +1,90 @@
import secrets
def random_number(min_val: int, max_val: int) -> int:
""" originally secure_rand """
return min_val + secrets.randbelow(max_val - min_val + 1)
def random_shuffle(array: list[int]) -> list[int]:
for i in range(len(array) - 1, 0, -1):
j = random_number(0, i)
array[i], array[j] = array[j], array[i]
return array
def mask_array(array_len: int) -> list[int]:
new_array = []
for i in range(array_len):
random_val = random_number(0, array_len)
new_array.append(random_val)
return new_array
def build_shuffle_matrix(row_length: int, column_length: int) -> list[list[int]]:
""" originally buildRandom """
output = []
for i in range(column_length):
output.append(random_shuffle(list(range(row_length))))
return output
def build_mask_matrix(row_length: int, column_length: int, max_value: int) -> list[list[int]]:
""" originally buildScramble """
output = []
for i in range(column_length):
row = [random_number(0, max_value - 1) for _ in range(row_length)]
output.append(row)
return output
def mapped_transform(operand: list[list[int]], function_map: list[list[int]]):
""" originally transpose """
assert len(operand) == len(function_map)
assert len(operand[0]) == len(function_map[0])
output = []
for i, el in enumerate(function_map):
row = []
for j, el2 in enumerate(el):
row.append(operand[el2][j])
output.append(row)
return output
def chain_map_transform(functions: list[list[list[int]]]) -> list[list[int]]:
""" originally chainMap """
output = functions[0]
for i in range(1, len(functions)):
output = mapped_transform(output, functions[i])
return output
if __name__ == "__main__":
alphabet = "abcd"
bytes_per_char = 4
alphabet_len = len(alphabet)
functionKey = build_shuffle_matrix(bytes_per_char, alphabet_len)
functionEphemeralKey = build_shuffle_matrix(bytes_per_char, alphabet_len)
outerFunctionFunctionKey = build_shuffle_matrix(alphabet_len, 1)
outerFunctionFunctionEphemeralKey = build_shuffle_matrix(alphabet_len, 1)
outerServerShuffleKey = build_shuffle_matrix(alphabet_len, 1)
outerServerShuffleEphemeralKey = build_shuffle_matrix(alphabet_len, 1)
serverKey = build_mask_matrix(bytes_per_char, alphabet_len, 255)
serverEphemeralKey = build_mask_matrix(bytes_per_char, alphabet_len, 255)
interfaceConfig = build_mask_matrix(bytes_per_char, alphabet_len, alphabet_len)
outerFunctionFunctionEphemeralKeyApplied = mapped_transform(outerFunctionFunctionKey,
outerFunctionFunctionEphemeralKey)
outerServerShuffleEphemeralKeyApplied = mapped_transform(outerServerShuffleKey, outerServerShuffleEphemeralKey)
inputData = mapped_transform(interfaceConfig, outerServerShuffleEphemeralKeyApplied)

10020
testDarcKeys.json Normal file

File diff suppressed because it is too large Load Diff

120
utils_test.ipynb Normal file
View File

@@ -0,0 +1,120 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true,
"ExecuteTime": {
"end_time": "2023-12-27T16:48:00.857374Z",
"start_time": "2023-12-27T16:48:00.827545Z"
}
},
"outputs": [],
"source": [
"from src.darc_key import DarcKey"
]
},
{
"cell_type": "code",
"execution_count": 2,
"outputs": [],
"source": [
"rows = 4\n",
"columns = 26\n",
"input_block_length = 10"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-12-27T16:48:01.105305Z",
"start_time": "2023-12-27T16:48:01.097428Z"
}
}
},
{
"cell_type": "code",
"execution_count": 3,
"outputs": [],
"source": [
"serverEphemeralKey = DarcKey.init_mask_matrix(rows, columns, 255)"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2023-12-27T16:48:02.630012Z",
"start_time": "2023-12-27T16:48:02.626613Z"
}
}
},
{
"cell_type": "code",
"execution_count": 3,
"outputs": [],
"source": [
"a = \"8\t\t\t\t\t\t\t\t\t1\t\t\t\t\t\t\t\t\t4\t\t\t\t\t\t\t\t\t5\t\t\t\t\t\t\t\t\t2\t\t\t\t\t\t\t\t\t3\t\t\t\t\t\t\t\t\t7\t\t\t\t\t\t\t\t\t6\t\t\t\t\t\t\t\t\t0\t\t\t\t\t\t\t\t\t9\t\t\t\t\t\t\t\t\""
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-01-16T01:13:13.747045Z",
"start_time": "2024-01-16T01:13:13.739449Z"
}
}
},
{
"cell_type": "code",
"execution_count": 4,
"outputs": [
{
"data": {
"text/plain": "['8', '1', '4', '5', '2', '3', '7', '6', '0', '9']"
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a.split()"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-01-16T01:13:14.470781Z",
"start_time": "2024-01-16T01:13:14.467313Z"
}
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [],
"metadata": {
"collapsed": false
}
}
],
"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": 0
}