-
Notifications
You must be signed in to change notification settings - Fork 7
/
RSA.html
231 lines (213 loc) · 12.7 KB
/
RSA.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<!DOCTYPE html>
<html>
<!-- the forms did not work from the start -->
<head>
<link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Merriweather" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Anton" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Abel" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Monoton" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<!-- TITLE AND CUSTOM CSS -->
<title> RSA </title>
<link rel="stylesheet" href="css/cony.css">
</head>
<body>
<!-- ENTER HEADER HERE -->
<div class="header">
<h1 style="color: white"><b>Number theory</b></h1>
<p style="color: white">Theory Of Numbers</p>
</div>
<div class="topnav">
<div id="mySidenav" class="sidenav">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">←</a>
<a href="https://www.amazon.com/s/ref=nb_sb_noss_2/144-7551219-7280505?url=search-alias%3Daps&field-keywords=number+theory">Shop</a>
<a href='#'>Books</a>
<a href='Devs.html'>Developers</a>
<a href='#' id="feed">Feedback</a>
</div><a style="font-size:20px;cursor:pointer ;color:white ; padding-bottom: 8px" onclick="openNav()">☰</a>
<a href="index.html">Home</a>
<div class="dropdown">
<button class="dropbtn">
Primes
<!--<i class="fa fa-caret-down"></i>-->
</button>
<div class="dropdown-content">
<a href="Primality.html">Introduction</a>
<a href="PrimeFact.html">Prime Factors</a>
<a href="RSA.html">RSA Encryption</a>
</div>
</div>
<div class="dropdown">
<button class="dropbtn">
Modular Arithmetic
<!--<i class="fa fa-caret-down"></i>-->
</button>
<div class="dropdown-content">
<a href="welcome.html">Introduction</a>
<a href="ModularAddMulSub.html">Modular Arithmetic</a>
<a href="congo.html">Modular Congruency</a>
</div>
</div>
<div class="dropdown">
<button class="dropbtn">
Algorithms
<!--<i class="fa fa-caret-down"></i>-->
</button>
<div class="dropdown-content">
<a href="bubble.html">Bubble Sort</a>
</div>
</div>
</div>
<div class="w3-container">
<button class="w3-button w3-xlarge w3-circle w3-red w3-card-4" id="myBtn">+</button>
</div>
<!-- ENTER CONTENT HERE-->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<textarea rows="6" cols="50" placeholder="Give your reviews..." style="color:black"></textarea>
<span class="close">×</span>
<button class="button" type="button" onclick="submit()" style="height:45px;width:200px ;padding:10px;font-size: 18px"><span>Submit</span></button>
</div>
</div>
<div class="row">
<div class="leftcolumn">
<div class="card">
<h2>
<span style="margin-left: 300px"><b>RSA Encryption</b></span>
</h2>
<h3 style="font-family: 'Raleway'"><b>Prequisites</b></h3>
<h2 style="font-family: 'Raleway'">Modulo P</h2>
<b>
<p style="font-size: 18px">The Set:<br>
<span style="margin-left: 250px ;font-size:23px ;font-family: 'Raleway'">
<b><i>Z(p) = { 0 , 1 , 2 , 3 , 4 , . . . , p-1 }</i></b>
</span>
<br>
</p>
</b>
<p>
Is called the set of integers modulo p (or mod p for short). It is a set that contains Integers from 0 up until p-1.
<br><b>Example: Z10={0,1,2,3,4,5,6,7,8,9}</b>
</p>
<h2 style="font-family: 'Raleway'">Multiplicative Inverse And The Greatest Common Divisor</h2>
<br>
<br>
<p style="font-size: 18px">A multiplicative inverse for x is a number that when multiplied by x, will equal 1. The multiplicative inverse of x is written as x<sup>-1</sup> and is defined as so:</p>
<p style="margin-left: 350px"><b>x . x<sup>-1</sup> = 1</b></p>
<p><b>The greatest common divisor (gcd)</b> between two numbers is the largest integer that will divide both numbers. For example, gcd(4,10)=2.</p>
<p style="font-size: 20px"> The interesting thing is that if two numbers have a gcd of 1, then the smaller of the two numbers has a multiplicative inverse in the modulo of the larger number.
<br>
</p>
<br>
<p><b>Example</b>: Lets work in the set Z9, then 4 <b> ∈</b> Z9 and <b>gcd(4 , 9) = 1</b>. Therefore 4 has a multiplicative inverse (written 4<sup>-1</sup>) in <b>mod </b>9, which is 7. And indeed, 4 . 7 = 28 = 1 <b>mod</b> 9. But not all numbers have inverses. For instance, 3 <b> ∈</b> Z9 but 3<sup>-1</sup> does not exist! This is because <b>gcd(3 , 9)=3 ≠ 1.</b></p>
<h2 style="font-family: 'Raleway'">Euler's Totient</h2>
<p style="font-size: 20px">Euler's Totient is the number of elements that have a multiplicative inverse in a set of modulo integers. The totient is denoted using the Greek symbol phi <b>ϕ</b>.the totient is just the count of the number of elements that have their gcd with the modulus equal to 1. This brings us to an important equation regarding the totient and prime numbers:</p>
<br>
<p style="margin-left: 350px"><b> p </b><b>∈</b> P , <b>ϕ(p) = (p-1)</p></b>
<br>
<p><b>EXAMPLE :</b> ϕ(7) = |{0 , 1 , . . . , 6 }| = 6</p>
<br>
<br>
<h2 style="font-family: 'Raleway' ; font-size:38px"><b>R S A</b></h2>
<p style="font-size: 20px">With the above background, we have enough tools to describe RSA and show how it works. RSA is actually a set of two algorithms:
<br>
<ol style="font-size: 20px;font-family: 'Raleway'">
<li> <b>Key Generation</b>: A key generation algorithm.</li>
<li><b>RSA Function Evaluation</b>: A function F that takes as input a point x and a key k and produces either an encrypted result or plaintext, depending on the input and the key.</li>
</ol>
</p>
</b>
</b>
</b>
<h2 style="font-family: 'Raleway' ; font-size:38px">Key Generation</h2>
<p style="font-size: 20px">The key generation algorithm is the most complex part of RSA. The aim of the key generation algorithm is to generate both the public and the private RSA keys. Sounds simple enough! Unfortunately, weak key generation makes RSA very vulnerable to attack. So it has to be done correctly. Here is what has to happen in order to generate secure RSA keys</p>
<ol style="font-size: 20px;font-family: 'Raleway'">
<li><b>Large Prime Number Generation:</b> Two large prime numbers <b>p</b> and <b>q</b> need to be generated. These numbers are very large: At least 512 digits, but 1024 digits is considered safe.</li>
<li><b>Modulus : </b> From the two large numbers, a modulus n is generated by multiplying <b>p</b> and <b>q</b>.</li>
<li><b>Totient : </b> The totient of n,<b>ϕ(n)</b> is calculated. <b> n = p * q</b></li>
<li><b> Public Key (e) : </b> A prime number is calculated from the range <b>[ 3, ϕ(n) )</b> that has a greatest common divisor of 1 with ϕ(n).</li>
<li><b>Private Key (d): </b> Because the prime in step 4 has a gcd of 1 with ϕ(n), we are able to determine it's inverse with respect to <b>modϕ(n)</b>.</li>
</ol>
<br>
<br>
<h2 style="font-family: 'Raleway' ; font-size:38px">R S A Function Evaluation</h2>
<p style="font-size: 20px">This is the process of transforming a plaintext message into ciphertext, or vice-versa. The RSA function, for message m and key k is evaluated as follows:
<br>
<span style="margin-left:350px ;font-size:20px"><b><i>F(m,k) = m<sup>k</sup> mod (n)</i></b></span></p>
<p style="font-size: 20px"><b>Encryption : </b> F(m,e) = m<sup>e</sup> mod n = <b>c</b> <b><i>(cipher)</i></b> where m is the <b>message</b> , e is the <b>public key</b> and n is <b>modulus</b></p>
<p style="font-size: 20px"><b>Decryption :</b> F(c,d) = c<sup>d</sup> mod n = m the <b><i>message</i></b></p>
</div>
<div class="card">
<h2 style="font-family: 'Raleway' ; font-size:38px">R S A Keygen</h2>
<br>
<br>
<div style="margin-left: 250px">
<form>
<input type="number" id="data1" placeholder="P" required>
<input type="number" id="data2" placeholder="Q" required>
<input type="number" id="pub" placeholder="Public Key" required>
<input type="number" id="pri" placeholder=" Private Key">
</form>
<br>
<input type="number" id="n" placeholder="Modulus">
<input type="number" id="e" placeholder="Euler Totient">
<p>
<button style="margin-left: 50px" class="button" onclick="keygen()">Get Keys</button>
<p id="ans" style="font-family: Merriweather;margin-left: 60px"><b></b></p>
</p>
<form>
<input type="number" id="da" placeholder="Message">
<br>
<input type="number" id="pubk" placeholder="Public Key">
<br>
<input type="number" id="en" placeholder="Encoded Message">
</form>
<br>
<p>
<button style="margin-left: 50px" class="button" onclick="ecode()">Encode</button>
<p id="ans" style="font-family: Merriweather;margin-left: 60px"><b></b></p>
</p>
<form>
<input type="number" id="dd" placeholder="Encoded Message">
<br>
<input type="number" id="pke" placeholder="Private Key">
<br>
<input type="number" id="dec" placeholder="Decoded Message">
</form>
<br>
<p>
<button style="margin-left: 50px" class="button" onclick="dcode()">Decode</button>
</p>
</div>
</div>
</div>
<div class="sticky">
<div class="card">
<h2 style="font-family: Merriweather">References</h2>
<div>
<a href="https://ocw.mit.edu/courses/mathematics/18-785-number-theory-i-fall-2016/"><img src="css//img//mitocw_1024x768.jpg" alt="mitocw" style="height: 200px ; width: 200px"></a>
</div>
<p>MIT OpenCourseWare By Prof.Andrew Sutherland</p>
<a href="https://ocw.mit.edu/courses/mathematics/18-785-number-theory-i-fall-2016/">
<button class="button" id="mit"><span>Visit </span></button>
</a>
</div>
</div>
</div>
<!-- CUSTOM JS GOES HERE -->
<script src="js/rsa.js"></script>
<script type="text/javascript">
function openNav() {
document.getElementById("mySidenav").style.width = "15%";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
</script>
</body>
</html>