diff options
| author | J08nY | 2024-08-26 15:02:48 +0200 |
|---|---|---|
| committer | J08nY | 2024-08-26 15:02:48 +0200 |
| commit | 303f2081e7e1348588d2e30f30571e6f1bc3a48e (patch) | |
| tree | 210105e2d641c9be4a55c1c163cb717e786166ec /re/zvp.ipynb | |
| parent | 5ced69e2785aad660fedd462366ee4b9a2ae51d1 (diff) | |
| download | pyecsca-notebook-master.tar.gz pyecsca-notebook-master.tar.zst pyecsca-notebook-master.zip | |
Diffstat (limited to 're/zvp.ipynb')
| -rw-r--r-- | re/zvp.ipynb | 185 |
1 files changed, 1 insertions, 184 deletions
diff --git a/re/zvp.ipynb b/re/zvp.ipynb index b0d6265..8b11024 100644 --- a/re/zvp.ipynb +++ b/re/zvp.ipynb @@ -17,8 +17,7 @@ " - [Computing ZVP points](#Computing-ZVP-points)\n", " - [Remapping](#Remapping)\n", " - [Distinguishing map and distinguishing tree building](#Distinguishing-map-and-distinguishing-tree-building)\n", - " - [Evaluation](#Evaluation)\n", - " - [Miscellaneous analysis](#Miscellaneous-analysis)\n" + " - [Evaluation](#Evaluation)\n" ] }, { @@ -1315,188 +1314,6 @@ ] }, { - "cell_type": "markdown", - "id": "07151071-33ed-4f24-8b47-73fc1feda2d7", - "metadata": {}, - "source": [ - "## Miscellaneous analysis" - ] - }, - { - "cell_type": "code", - "id": "b78f99d6-46b9-44bb-b9b4-5df7fc4fa990", - "metadata": { - "scrolled": true - }, - "source": [ - "p = set()\n", - "for node in PreOrderIter(expanded.root):\n", - " if isinstance(node.dmap_input, Poly):\n", - " print(node.dmap_input, [len(child.cfgs) for child in node.children])\n", - " print(\"\\t\", \"\\n\\t\".join(\", \".join(f\"({cfg[0]} {cfg[1]})\" for cfg in child.cfgs) for child in node.children))\n", - " p.add(node.dmap_input)\n", - "print(\"---\")\n", - "for pp in p:\n", - " print(pp)\n", - " for formula, fset in factor_sets_nonhomo.items():\n", - " if pp in fset:\n", - " print(formula)" - ], - "outputs": [], - "execution_count": null - }, - { - "cell_type": "code", - "id": "1bd71766-4633-4136-b00a-e42fa304ff92", - "metadata": { - "scrolled": true - }, - "source": [ - "rev_point_map = {}\n", - "for (poly, params_cat, k), (points, affine_params) in all_points_filtered.items():\n", - " for point in points:\n", - " poly_set = rev_point_map.setdefault((point, affine_params), set())\n", - " poly_set.add((poly, params_cat, k))\n", - "\n", - "for (point, affine_params), poly_set in rev_point_map.items():\n", - " if len(poly_set) > 1:\n", - " print(point, affine_params.curve.parameters, f\"p={affine_params.curve.prime}\") \n", - " cond = affine_params.name.split(\"=\")[1].split(\"[\")[0] if \"=\" in affine_params.name else \"\"\n", - " polys_mapped = set()\n", - " for poly, params_cat, k in poly_set:\n", - " mapd = eliminate_y(poly, affine_params.curve.model)\n", - " polys_mapped.add(mapd)\n", - " print(poly.as_expr(), \"|\", params_cat, \"|\", k)\n", - " #for formula, fset in factor_sets.items():\n", - " # if poly in fset and (cond in formula.coordinate_model.name or \"-\" not in formula.coordinate_model.name):\n", - " # print(\"\\t\", formula)\n", - " print(\"->\")\n", - " for poly in polys_mapped:\n", - " p = Poly(poly, domain=ZZ)\n", - " print(p.factor_list())\n", - " print(\"------\")\n", - " else:\n", - " print(\".\", end=\"\") #poly_set, point)" - ], - "outputs": [], - "execution_count": null - }, - { - "cell_type": "code", - "id": "d38370e9-c222-4f7e-9a08-d4e299083f87", - "metadata": { - "scrolled": true - }, - "source": [ - "for node in PreOrderIter(tree_remapped.root):\n", - " if node.dmap_input:\n", - " pad = \" \" * node.depth\n", - " poly_set = rev_point_map[node.dmap_input]\n", - " point, affine_params = node.dmap_input\n", - " print(pad, point, affine_params.name, affine_params.curve.parameters, f\"p={affine_params.curve.prime}\") \n", - " chain = chain_map[affine_params]\n", - " print(pad, chain)\n", - " cond = affine_params.name.split(\"=\")[1].split(\"[\")[0] if \"=\" in affine_params.name else \"\"\n", - " true_formulas = set()\n", - " for poly, params_cat, k in poly_set:\n", - " print(pad, poly.as_expr(), \"|\", params_cat, \"|\", k)\n", - " for formula, fset in factor_sets.items():\n", - " if poly in fset and (cond in formula.coordinate_model.name or \"-\" not in formula.coordinate_model.name):\n", - " kvar = (\"add\", (1, k)) if formula.shortname == \"add\" else (\"dbl\", (k, ))\n", - " print(pad, \"\\t\", formula, \"*\" if kvar in chain else \"not\")\n", - " if kvar in chain:\n", - " true_formulas.add(formula)\n", - " for child in node.children:\n", - " print(pad, child.response)\n", - " for cfg in child.cfgs:\n", - " if child.response == True:\n", - " print(pad, \"ok\" if true_formulas.intersection(cfg) else \"nok\", cfg)\n", - " elif child.response == False:\n", - " print(pad, \"ok\" if not true_formulas.intersection(cfg) else \"nok\", cfg)\n", - " else:\n", - " print(pad, cfg)\n", - " print(\"\")\n", - " print(\"------\")" - ], - "outputs": [], - "execution_count": null - }, - { - "cell_type": "code", - "id": "d327e346-9c82-4e50-9357-ba66b3c511ed", - "metadata": { - "scrolled": true - }, - "source": [ - "for coord_name, coords in model.coordinates.items():\n", - " total = 1\n", - " print(coord_name)\n", - " for formula_group, formula_class in zip(formula_groups[coords], formula_classes):\n", - " lf = len(formula_group)\n", - " print(\"\\t\", formula_class.shortname, lf)\n", - " for formula in formula_group:\n", - " print(\"\\t\", formula)\n", - " total *= lf\n", - " print(\"\\t\", total)" - ], - "outputs": [], - "execution_count": null - }, - { - "cell_type": "code", - "id": "f98fca35-5c01-434d-95b5-0ba81ab37721", - "metadata": {}, - "source": [ - "for tree in (tree_remapped, tree_count, tree_position):\n", - " same = 0\n", - " for leaf in tree.leaves:\n", - " cds = set()\n", - " for c in leaf.cfgs:\n", - " cds.add(c[0].coordinate_model)\n", - " cds.add(c[1].coordinate_model)\n", - " same += len(cds) == 1\n", - " print(same / len(tree.leaves))" - ], - "outputs": [], - "execution_count": null - }, - { - "cell_type": "code", - "id": "af01658f-6c95-483c-9d8d-ce6f34566cee", - "metadata": { - "scrolled": true - }, - "source": [ - "tree_counter = Counter()\n", - "for node in LevelOrderIter(tree_count.root):\n", - " if isinstance(node.response, int):\n", - " tree_counter[node.response] += 1\n", - " if node.children:\n", - " print(list(map(lambda n: n.response, node.children)))\n", - "fig, ax = plt.subplots(figsize=(10, 3))\n", - "ax.bar(tree_counter.keys(), tree_counter.values(), width=1);" - ], - "outputs": [], - "execution_count": null - }, - { - "cell_type": "code", - "id": "cc814452-04d8-4285-8df9-496c96e668e7", - "metadata": {}, - "source": [ - "dmap_counter = Counter()\n", - "for col in dmap_count.mapping:\n", - " dmap_counter.update(dmap_count.mapping[col])\n", - "\n", - "del dmap_counter[-1]\n", - "del dmap_counter[0]\n", - "fig, ax = plt.subplots(figsize=(10, 3))\n", - "ax.bar(dmap_counter.keys(), dmap_counter.values(), width=1);" - ], - "outputs": [], - "execution_count": null - }, - { "cell_type": "code", "id": "892e02c7-8c39-4467-91ff-b6ae265684aa", "metadata": {}, |
