{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b0111eb4",
   "metadata": {},
   "source": [
    "# TP1: Chiffrement basé sur les réseaux euclidiens\n",
    "\n",
    "Ce TP vous introduira à l'implémentation de schémas de chiffrement basés sur les réseaux vus en court: le chiffrement de Regev, et le chiffrement Dual\\-Regev. Les deux schémas à implémenter ont été montrés sûrs en supposant la difficulté du problème Learning with Errors.\n",
    "\n",
    "### 0.1. Paquetages et notations\n",
    "\n",
    "On vous joint ici un ensemble de paquetages $\\textsf{Sage}$ pouvant vous être utile lors de vos implémentations.\n",
    "\n",
    "- [Distributions Gaussiennes Discrètes](https://doc.sagemath.org/html/en/reference/stats/sage/stats/distributions/)\n",
    "- [LWE](https://doc.sagemath.org/html/en/reference/cryptography/sage/crypto/lwe.html)\n",
    "\n",
    "On rappelle également les différentes notations décrites dans ce TP:\n",
    "\n",
    "- On dénote par $\\mathbb{Z}_q := \\mathbb{Z}/q\\mathbb{Z}$ l'ensemble des entiers modulo $q$,\n",
    "- $x \\xleftarrow{\\$} S$ décrit un tirage uniforme dans l'ensemble fini $S$,\n",
    "- $x \\leftarrow \\mathcal{D}_{S,\\sigma}$ décrit une distribution gaussienne dans l'ensemble $S$ d'écart-type $\\sigma$, par défaut la distribution est centrée en $0$.\n",
    "\n",
    "# 1 - Distributions de probabilités\n",
    "\n",
    "### Exercice 1\n",
    "Afin d'étudier la distribution uniforme, tirer $m$ éléments de $\\mathbb{Z}_q$ et visualiser la distribution en sortie, avec un $\\texttt{plot}$. (prenez $q = 3,10,100; m=10^2,10^3,10^4$)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "857835bd",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "5afca946",
   "metadata": {},
   "source": [
    "### Exercice 2\n",
    "\n",
    "Afin d'étudier la distribution gaussienne, tirer $m$ éléments de $\\mathcal{D}_{\\mathbb{R},\\sigma}$ et visualiser la distribution en sortie, avec un $\\texttt{plot}$. (prenez $\\sigma = 10,10^2,10^3; m=10^3$)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a8287d10",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "dba2b562",
   "metadata": {},
   "source": [
    "### Exercice 3\n",
    "\n",
    "Etudiez maintenant la distribution gaussienne discrète, tirer $m$ éléments de $\\mathcal{D}_{\\mathbb{Z},\\sigma}$ et visualiser la distribution en sortie, avec un $\\texttt{plot}$. (prenez $\\sigma = 10,10^2,10^3; m=10^3$)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8afe037c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "14499eae",
   "metadata": {},
   "source": [
    "# 2 - Schémas de chiffrement fondamentaux basés sur les réseaux\n",
    "\n",
    "## Exercice 4 - Chiffrement de Regev"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b6c1acc2",
   "metadata": {},
   "outputs": [],
   "source": [
    "def RegevGenerator(security_parameter):\n",
    "    return params"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "554c7957",
   "metadata": {},
   "outputs": [],
   "source": [
    "def RegevKeyGen():\n",
    "    return pk,sk"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3a9db6fc",
   "metadata": {},
   "outputs": [],
   "source": [
    "def RegevEncrypt(pk,b):\n",
    "    return ciphertext"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "efbfed31",
   "metadata": {},
   "outputs": [],
   "source": [
    "def RegevDecrypt(sk,c):\n",
    "    return plaintext"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7ba5556b",
   "metadata": {},
   "source": [
    "## Exercice 5 - Chiffrement Dual-Regev"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3126fc63",
   "metadata": {},
   "outputs": [],
   "source": [
    "def DualGenerator(security_parameter):\n",
    "    return params"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c0579a2c",
   "metadata": {},
   "outputs": [],
   "source": [
    "def DualKeyGen():\n",
    "    return pk,sk"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e85bfa2a",
   "metadata": {},
   "outputs": [],
   "source": [
    "def DualEncrypt(pk,b):\n",
    "    return ciphertext"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "616cd791",
   "metadata": {},
   "outputs": [],
   "source": [
    "def DualDecrypt(sk,c):\n",
    "    return plaintext"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "db52bbf4",
   "metadata": {},
   "source": [
    "# Aller plus loin\n",
    "\n",
    "### Exercice 6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cbc57ac0",
   "metadata": {},
   "outputs": [],
   "source": [
    "%timeit -n 1000 fonction_a_evaluer()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a54d1b93",
   "metadata": {},
   "source": [
    "### Exercice 7"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4a745b4e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "SageMath 9.5",
   "language": "sage",
   "name": "sagemath"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
