Skip to content

Commit d691df4

Browse files
committed
docstring added to cryptography
1 parent 27332fa commit d691df4

File tree

5 files changed

+621
-402
lines changed

5 files changed

+621
-402
lines changed

cryptography/des_key_generation.ipynb

Lines changed: 0 additions & 158 deletions
This file was deleted.

cryptography/extended_eucledian.ipynb

Lines changed: 60 additions & 29 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": 8,
66
"id": "8561e0a7",
77
"metadata": {},
88
"outputs": [
@@ -26,7 +26,7 @@
2626
},
2727
{
2828
"cell_type": "code",
29-
"execution_count": 2,
29+
"execution_count": 7,
3030
"id": "12f36b2f",
3131
"metadata": {},
3232
"outputs": [
@@ -36,27 +36,38 @@
3636
"21"
3737
]
3838
},
39-
"execution_count": 2,
39+
"execution_count": 7,
4040
"metadata": {},
4141
"output_type": "execute_result"
4242
}
4343
],
4444
"source": [
45-
"def eucld_gcd(a,b):\n",
46-
" if(a < b):\n",
47-
" a , b = b , a\n",
48-
" if(b==0):\n",
45+
"def eucld_gcd(a, b):\n",
46+
" \"\"\"\n",
47+
" Computes the greatest common divisor (GCD) of two integers using the Euclidean algorithm.\n",
48+
"\n",
49+
" Parameters:\n",
50+
" a (int): The first integer.\n",
51+
" b (int): The second integer.\n",
52+
"\n",
53+
" Returns:\n",
54+
" int: The greatest common divisor of a and b.\n",
55+
" \"\"\"\n",
56+
" if a < b:\n",
57+
" a, b = b, a\n",
58+
" if b == 0:\n",
4959
" return a\n",
50-
" r = a%b\n",
51-
" if(r==0):\n",
60+
" r = a % b\n",
61+
" if r == 0:\n",
5262
" return b\n",
53-
" return eucld_gcd(b,r)\n",
63+
" return eucld_gcd(b, r)\n",
64+
"\n",
5465
"eucld_gcd(252,105)"
5566
]
5667
},
5768
{
5869
"cell_type": "code",
59-
"execution_count": 3,
70+
"execution_count": 9,
6071
"id": "c060ee17",
6172
"metadata": {},
6273
"outputs": [
@@ -66,45 +77,65 @@
6677
"[1, -48]"
6778
]
6879
},
69-
"execution_count": 3,
80+
"execution_count": 9,
7081
"metadata": {},
7182
"output_type": "execute_result"
7283
}
7384
],
7485
"source": [
7586
"import numpy as np\n",
76-
"def ext_eucld(a,b):\n",
87+
"\n",
88+
"def ext_eucld(a, b):\n",
89+
" \"\"\"\n",
90+
" Computes the extended Euclidean algorithm to find the greatest common divisor (GCD)\n",
91+
" of two integers, and also the coefficients (x, y) of the equation:\n",
92+
" a*x + b*y = GCD(a, b)\n",
93+
"\n",
94+
" This method returns the coefficients (x, y) such that a*x + b*y = GCD(a, b).\n",
95+
"\n",
96+
" Parameters:\n",
97+
" a (int): The first integer.\n",
98+
" b (int): The second integer.\n",
99+
"\n",
100+
" Returns:\n",
101+
" list: A list of two integers [x, y] where x and y are the coefficients for the linear\n",
102+
" combination of a and b that equals their GCD.\n",
103+
" \"\"\"\n",
77104
" swap = False\n",
78-
" if(a < b):\n",
79-
" a , b = b , a\n",
80-
" swap = True\n",
81-
" def eucld(a,b):\n",
82-
" if(b==0 or b==1):\n",
105+
" if a < b:\n",
106+
" a, b = b, a\n",
107+
" swap = True\n",
108+
"\n",
109+
" def eucld(a, b):\n",
110+
" if b == 0 or b == 1:\n",
83111
" return []\n",
84112
" ls = []\n",
85-
" while b!=1:\n",
86-
" r = a%b\n",
87-
" if(r==0):\n",
113+
" while b != 1:\n",
114+
" r = a % b\n",
115+
" if r == 0:\n",
88116
" return ls\n",
89-
" idx = (a-r)//b\n",
117+
" idx = (a - r) // b\n",
90118
" ls.append(idx)\n",
91119
" a = b\n",
92120
" b = r\n",
93121
" return ls\n",
94-
" \n",
95-
" row = np.array([[1,0],[0,1]])\n",
96-
" ls = eucld(a,b)\n",
122+
"\n",
123+
" row = np.array([[1, 0], [0, 1]])\n",
124+
" ls = eucld(a, b)\n",
97125
" for i in ls:\n",
98-
" row = np.append(row, [row[-2] - i*row[-1]] ,axis=0)\n",
99-
" if(swap):\n",
126+
" row = np.append(row, [row[-2] - i * row[-1]], axis=0)\n",
127+
" \n",
128+
" if swap:\n",
100129
" return list(row[-1])[::-1]\n",
130+
" \n",
101131
" return list(row[-1])\n",
102-
"ext_eucld(97,2)"
132+
"\n",
133+
"ext_eucld(97, 2)\n"
103134
]
104135
},
105136
{
106137
"cell_type": "code",
107-
"execution_count": 4,
138+
"execution_count": 10,
108139
"id": "d3edd1f6",
109140
"metadata": {},
110141
"outputs": [

0 commit comments

Comments
 (0)