Remove the bug
This commit is contained in:
parent
5fca4cd283
commit
0e50709c23
|
@ -1,12 +1,5 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
|
@ -713,7 +706,7 @@
|
|||
"3. Select $e$ randomly with $gcd(e, \\varphi(n)) = 1$.\n",
|
||||
"4. Compute $d = e−1 \\mod \\varphi(n)$.\n",
|
||||
"5. The public key is the pair $n$ and $e$.\n",
|
||||
"6. The private key consists of the values $p$, $q$ and $d$.\n",
|
||||
"6. The private key consists of the values $p$, $q$ (or $n = pq$) and $d$.\n",
|
||||
"\n",
|
||||
"### Encryption\n",
|
||||
"\n",
|
||||
|
@ -723,13 +716,13 @@
|
|||
"\n",
|
||||
"### Decryption\n",
|
||||
"\n",
|
||||
"The private key for decryption is KD = d (values p and q are not used here).\n",
|
||||
"1. Compute D(C,KD) = Cd mod n = M."
|
||||
"The private key for decryption is $KD = d$ (values $p$ and $q$ are not used here).\n",
|
||||
"1. Compute $D(C,KD) = Cd \\mod n = M$."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 24,
|
||||
"execution_count": 14,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
|
@ -785,15 +778,13 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 22,
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"C = M^e (mod n) = 50^102900819 (mod 604604729) = 2488\n",
|
||||
"\n",
|
||||
"Ciphertext: 2488\n"
|
||||
]
|
||||
}
|
||||
|
@ -809,28 +800,25 @@
|
|||
"\n",
|
||||
"M = 50\n",
|
||||
"C = rsa_encrypt(M, rsa_keys)\n",
|
||||
"print(f\"C = M^e (mod n) = {M}^{e} (mod {n}) = {C}\\n\")\n",
|
||||
"print(f\"Ciphertext: {C}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 23,
|
||||
"execution_count": 16,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"M = C^d (mod n) = 2488^1 (mod 604604729) = 50\n",
|
||||
"\n",
|
||||
"Message: 50\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"def rsa_decrypt(C, rsa_keys):\n",
|
||||
" # private key\n",
|
||||
" # Private key\n",
|
||||
" p = rsa_keys['p']\n",
|
||||
" q = rsa_keys['q']\n",
|
||||
" d = rsa_keys['d']\n",
|
||||
|
@ -840,7 +828,6 @@
|
|||
" return square_and_multiply(C,d,n)\n",
|
||||
"\n",
|
||||
"M = rsa_decrypt(C, rsa_keys)\n",
|
||||
"print(f\"M = C^d (mod n) = {C}^{d} (mod {n}) = {M}\\n\")\n",
|
||||
"print(f\"Message: {M}\")"
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue