From d6c61d988bfa4255baf9cdae42db59ebee38363f Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Tue, 25 May 2021 17:10:49 +0200 Subject: Added files --- .../.ipynb_checkpoints/Homework3-checkpoint.ipynb | 179 +++++++++++++++++++++ .../.ipynb_checkpoints/solution-checkpoint.ipynb | 166 +++++++++++++++++++ 2 files changed, 345 insertions(+) create mode 100644 src/Homework3/.ipynb_checkpoints/Homework3-checkpoint.ipynb create mode 100644 src/Homework3/.ipynb_checkpoints/solution-checkpoint.ipynb (limited to 'src/Homework3/.ipynb_checkpoints') diff --git a/src/Homework3/.ipynb_checkpoints/Homework3-checkpoint.ipynb b/src/Homework3/.ipynb_checkpoints/Homework3-checkpoint.ipynb new file mode 100644 index 0000000..13bad44 --- /dev/null +++ b/src/Homework3/.ipynb_checkpoints/Homework3-checkpoint.ipynb @@ -0,0 +1,179 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "*For this exercise you should have received this text in .ipynb format. Complete the exercises by modifying this file, and submit the modified version*" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Exercise 1**\n", + "\n", + "Use SageMath to solve the following problems:\n", + "\n", + "(a) Find the roots of the following polynomial over $\\mathbb Q$:\n", + "\\begin{align*}\n", + " p = 4 x^{7} + 4 x^{6} + 3 x^{5} - 13 x^{4} - 13 x^{3} - 9 x^{2} + 3 x + 3 \\in \\mathbb Q[x]\n", + "\\end{align*}\n", + "\n", + "(b) Find the roots of the same polynomial $p$ over $\\mathbb R$ and over $\\mathbb C$.\n", + "\n", + "(c) Find the determinant, the trace and the characteristic polynomial of the following matrix:\n", + "\\begin{align*}\n", + "A=\\left(\\begin{array}{rrrr}\n", + "-1 & 1 & -1 & 0 \\\\\n", + "1 & \\frac{1}{2} & 1 & 0 \\\\\n", + "\\frac{1}{2} & -\\frac{1}{2} & -2 & 1 \\\\\n", + "0 & 0 & 1 & 1\n", + "\\end{array}\\right)\n", + "\\end{align*}\n", + "\n", + "(d) Find a solution to the linear system $A\\mathbf x =\\mathbf v$, where $A$ is the matrix above and $\\mathbf v=(1, 2, 3, 4)$.\n", + "\n", + "Write your code in the cell below." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Exercise 2**\n", + "\n", + "After exchanging messages with the RSA protocol seen in class, Alice and Bob decide to meet and play their favorite game: flip a coin. They like this game very much because it does not take long to set it up and they have exactly the same chances of winning.\n", + "\n", + "Unfortunately, due to the COVID-19 pandemic they cannot meet in person, and despite being good friends they don't trust each other enough to play this game via Webex call. Luckily, Alice is an expert in cryptography and she knows how to play this game using the Chinese remainder theorem.\n", + "\n", + "The game plays out as follows:\n", + "\n", + "(A1) Alice picks two large prime numbers $p$ and $q$, she computes $n=pq$ and sends $n$ to Bob, keeping $p$ and $q$ secret.\n", + "\n", + "(B1) Bob picks a random number $a$ with $1, line 7)", + "output_type": "error", + "traceback": [ + "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m7\u001b[0m\n\u001b[1;33m def B1(n):\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m expected an indented block\n" + ] + } + ], + "source": [ + "# Alice needs this to compute the square roots\n", + "from sage.rings.finite_rings.integer_mod import square_root_mod_prime\n", + "\n", + "def A1():\n", + " # This function must return two distinct primes and their product.\n", + " \n", + "def B1(n):\n", + " # This function must return a random integer a\n", + " # with 1