Skip to content

Commit bc657ec

Browse files
author
sushmit
committed
SR: adding
1 parent 14231e7 commit bc657ec

18 files changed

+4727
-288
lines changed

.DS_Store

4 KB
Binary file not shown.

new_notebook.ipynb renamed to .ipynb_checkpoints/Chapter7-checkpoint.ipynb

Lines changed: 70 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 1,
5+
"execution_count": 14,
66
"metadata": {
77
"collapsed": false
88
},
@@ -16,7 +16,7 @@
1616
" Vec({0, 1, 2, 3, 4},{0: 0.0, 1: 0.0, 2: 0.0, 3: 0.0, 4: 3.0})]"
1717
]
1818
},
19-
"execution_count": 1,
19+
"execution_count": 14,
2020
"metadata": {},
2121
"output_type": "execute_result"
2222
}
@@ -27,6 +27,8 @@
2727
"from mat import Mat\n",
2828
"from matutil import *\n",
2929
"from echelon import *\n",
30+
"from vecutil import *\n",
31+
"from GF2 import one\n",
3032
"#import ipdb\n",
3133
"new_rowlist = []\n",
3234
"\n",
@@ -64,7 +66,7 @@
6466
},
6567
{
6668
"cell_type": "code",
67-
"execution_count": 6,
69+
"execution_count": 10,
6870
"metadata": {
6971
"collapsed": false
7072
},
@@ -110,22 +112,36 @@
110112
},
111113
{
112114
"cell_type": "code",
113-
"execution_count": null,
115+
"execution_count": 4,
114116
"metadata": {
115117
"collapsed": false
116118
},
117-
"outputs": [],
119+
"outputs": [
120+
{
121+
"name": "stdout",
122+
"output_type": "stream",
123+
"text": [
124+
"\n",
125+
" 0 1 2 3\n",
126+
" ---------\n",
127+
" 0 | 0 2 4 2\n",
128+
" 1 | 2 1 0 0\n",
129+
" 2 | 0 0 0 0\n",
130+
" 3 | 0 0 0 0\n",
131+
"\n"
132+
]
133+
}
134+
],
118135
"source": [
119-
"\n",
120136
"Bd = (set([0,1,2,3]), set([0,1,2,3]))\n",
121-
"Bf = {(0,1):2, (0,2):4,(0,3):2,(0,4):8,(1,0):2,(1:1):1}\n",
137+
"Bf = {(0,1):2, (0,2):4,(0,3):2,(0,4):8,(1,0):2,(1,1):1}\n",
122138
"B=Mat(Bd, Bf)\n",
123139
"print(B)"
124140
]
125141
},
126142
{
127143
"cell_type": "code",
128-
"execution_count": 2,
144+
"execution_count": 6,
129145
"metadata": {
130146
"collapsed": false
131147
},
@@ -134,49 +150,41 @@
134150
"name": "stdout",
135151
"output_type": "stream",
136152
"text": [
137-
"Enter the entry for row: 0 col: 0 \n",
138-
"Enter the entry for row: 0 col: 1 2\n",
139-
"Enter the entry for row: 0 col: 2 4\n",
140-
"Enter the entry for row: 0 col: 3 2\n",
141-
"Enter the entry for row: 0 col: 4 8\n",
142-
"Enter the entry for row: 1 col: 0 2\n",
143-
"Enter the entry for row: 1 col: 1 1\n",
144-
"Enter the entry for row: 1 col: 2 0\n",
145-
"Enter the entry for row: 1 col: 3 5\n",
146-
"Enter the entry for row: 1 col: 4 4\n",
147-
"Enter the entry for row: 2 col: 0 4\n",
148-
"Enter the entry for row: 2 col: 1 1\n",
149-
"Enter the entry for row: 2 col: 2 2\n",
150-
"Enter the entry for row: 2 col: 3 4\n",
151-
"Enter the entry for row: 2 col: 4 2\n",
152-
"Enter the entry for row: 3 col: 0 5\n",
153-
"Enter the entry for row: 3 col: 1 0\n",
154-
"Enter the entry for row: 3 col: 2 0\n",
155-
"Enter the entry for row: 3 col: 3 2\n",
156-
"Enter the entry for row: 3 col: 4 8\n",
157-
"\n",
158-
" 0 1 2 3 4\n",
159-
" -----------\n",
160-
" 0 | 0 2 4 2 8\n",
161-
" 1 | 2 1 0 5 4\n",
162-
" 2 | 4 1 2 4 2\n",
163-
" 3 | 5 0 0 2 8\n",
164-
"\n"
153+
"Enter the entry for row: 0 col: 0 1\n",
154+
"Enter the entry for row: 0 col: 1 1\n",
155+
"Enter the entry for row: 0 col: 2 1\n",
156+
"Enter the entry for row: 0 col: 3 1\n",
157+
"Enter the entry for row: 0 col: 4 \n",
158+
"Enter the entry for row: 1 col: 0 \n",
159+
"Enter the entry for row: 1 col: 1 \n",
160+
"Enter the entry for row: 1 col: 2 \n",
161+
"Enter the entry for row: 1 col: 3 \n",
162+
"Enter the entry for row: 1 col: 4 \n",
163+
"Enter the entry for row: 2 col: 0 \n",
164+
"Enter the entry for row: 2 col: 1 \n",
165+
"Enter the entry for row: 2 col: 2 \n",
166+
"Enter the entry for row: 2 col: 3 \n",
167+
"Enter the entry for row: 2 col: 4 \n",
168+
"Enter the entry for row: 3 col: 0 \n",
169+
"Enter the entry for row: 3 col: 1 \n",
170+
"Enter the entry for row: 3 col: 2 \n",
171+
"Enter the entry for row: 3 col: 3 \n",
172+
"Enter the entry for row: 3 col: 4 \n"
165173
]
166174
}
167175
],
168176
"source": [
169177
"Bd = (set([0,1,2,3]), set([0,1,2,3,4]))\n",
170178
"Bf = {}\n",
171179
"B=Mat(Bd, Bf)\n",
172-
"Mat.input_Matrix(B)\n",
180+
"#Mat.input_Matrix(B)\n",
173181
"\n",
174-
"print(B)"
182+
"import random"
175183
]
176184
},
177185
{
178186
"cell_type": "code",
179-
"execution_count": 7,
187+
"execution_count": 70,
180188
"metadata": {
181189
"collapsed": false
182190
},
@@ -185,20 +193,33 @@
185193
"name": "stdout",
186194
"output_type": "stream",
187195
"text": [
188-
"\n",
189-
" 1 2 3 4\n",
190-
" -----------------\n",
191-
" 0 | one 0 0 0\n",
192-
" 1 | one one 0 0\n",
193-
" 2 | one one one 0\n",
194-
" 3 | one 0 one one\n",
195-
"\n"
196+
"[0, 0, one, 0, 0, 0]\n",
197+
"0\n"
196198
]
197199
}
198200
],
199201
"source": [
200-
"B\n",
201-
"print(transformation(B))"
202+
"a0 = list2vec([one,one,0,one,0,one])\n",
203+
"b0 = list2vec([one,one,0,0,0,one])\n",
204+
"\n",
205+
"import random\n",
206+
"def randGF2() : return random.randint(0,1)*one\n",
207+
"\n",
208+
"# Task 7.7.1\n",
209+
"def choose_secret_vector(s,t):\n",
210+
" # generate the random 6 vector u\n",
211+
" u_list = [randGF2() for i in range(6)]\n",
212+
" u_vec = list2vec(u_list)\n",
213+
" if (a0*u_vec) != s or (b0 * u_vec) != t:\n",
214+
" choose_secret_vector(s,t)\n",
215+
" \n",
216+
" return u_vec\n",
217+
"\n",
218+
"print ([randGF2() for i in range(6)])\n",
219+
"#choose_secret_vector(one,one)\n",
220+
"\n",
221+
"print ( choose_secret_vector(one,0))\n",
222+
"\n"
202223
]
203224
}
204225
],

0 commit comments

Comments
 (0)