-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathelgamal.html
247 lines (232 loc) · 11.6 KB
/
elgamal.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<!DOCTYPE HTML>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<meta name="description" content="A online ElGamal encryption/decryption tool. This tool will help you understand how ElGamal encryption works.">
<title>ElGamal Encryption Playground</title>
<link rel="canonical" href="https://www.debjitbiswas.com/elgamal/" />
<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.6.0/katex.min.css">
<link type="text/css" rel="stylesheet" href="css/elgamal.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.6.0/katex.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.6.0/contrib/auto-render.min.js"></script>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand">ElGamal Encryption Playground</span>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#" data-toggle="modal" data-target=".bs-about-modal-sm">About</a></li>
<li><a href="https://github.com/debjitbis08/elgamal-demo">Github</a></li>
</ul>
</div>
</div>
</nav>
<div class="modal fade bs-about-modal-sm" tabindex="-1" role="dialog" aria-labelledby="about">
<div class="modal-dialog modal-md" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">About</h4>
</div>
<div class="modal-body">
<section>
<p>This is a small application you can use to understand how Elgamal encryption works. This is a toy implementation so please don't try huge numbers or use for serious work.</p>
</section>
<section>
<h3>Source code and Reporting Bugs</h3>
<p>
The complete source for this application is available on
<a target="_blank" href="https://github.com/debjitbis08/elgamal-demo">GitHub</a>.
Please report any bugs on the Github
<a target="_blank" href="https://github.com/debjitbis08/elgamal-demo/issues">issue tracker</a>.
</p>
</section>
</div>
</div>
</div>
</div>
<div id="wrapper" class="container clearfix" style="padding-top:80px;">
<div class="row">
<div class="col-md-4">
<div class="panel panel-default machine clearfix" id="aliceMachine">
<div class="panel-heading"><h3 class="panel-title">Alice's Machine</h3></div>
<div class="panel-body main">
<ul class="errors"></ul>
<form>
<div class="form-group" id="prime">
<label for="txtPrime">
Enter a prime \(p\)
<span class="glyphicon glyphicon-info-sign" title="A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself."></span>
</label>
<div class="input-group">
<input type="text" class="form-control" id="txtPrime"/>
<div class="input-group-btn">
<button id="getGenerators" class="btn btn-default helpers" type="button">Get Generators</button>
</div>
</div>
<span class="errorInfo">Please enter a prime number</span>
</div>
<div class="form-group" id="generator">
<label for="txtG">
Choose \(g\)
<span class="glyphicon glyphicon-info-sign" title="Primitive root of p will be a number such that when x goes from 1 to p-1 then g^x (mod p) goes through all the numbers in the set [1, 2,...,(p-1)] in some order"></span>
</label>
<div id="generatorInfo">Click <button class="btn btn-xs btn-default" type="button">Get Generator</button> button above to see list of generators here</div>
<div id="selectG"></div>
<span class="errorInfo">Not a valid generator</span>
</div>
<div class="form-group" id="privateKey">
<label for="txtPrivateKey">
Enter Private Key \(x\)
<span class="glyphicon glyphicon-info-sign" title="A number greater than 0 and less than p - 1"></span>
</label>
<div class="input-group">
<input type="text" class="form-control" id="txtPrivateKey"/>
<div class="input-group-btn">
<button id="getRandomPrivateKey" class="btn btn-default helpers" type="button">Get Random Key</button>
</div>
</div>
<span class="errorInfo">Number should be greater than 0 and less than (p-1)</span>
</div>
<p>\(h\) is calculated as \(h = g^x \ mod \ p\)</p>
<button id="getPublicKey" class="btn btn-success" type="button">
Generate & Publish Public Key <span class="glyphicon glyphicon-arrow-right"></span>
</button>
</form>
<div class="panel panel-default" style="margin-top: 10px;">
<div class="panel-body">
<div id="messageDisplay">
<div class="inbox-empty" style="display: block">
You have no messages.
</div>
<div class="inbox-has-message" style="display: none">
<div>You received a message from Bob. <button id="decrypt" class="btn btn-primary btn-sm" type="button">Decrypt</button></div>
<div class="data" style="font-weight: bold;margin-top:10px;"></div>
</div>
</div>
</div>
</div>
<div class="panel panel-default" style="margin-top: 10px;">
<div class="panel-body">
<p>
Message is decrypted using
\[s = c{_1}^x\ mod\ p\]
\[m = c{_2}\ .\ s^{-1}\ mod\ p\] which can be rewritten \(\dagger\) as
\[m = c{_2}\ .\ s^{p-2}\ mod\ p\]
\(\dagger\) See <a href="http://en.wikipedia.org/wiki/Euler's_theorem" target="_blank">Euler's Theorem</a>
</p>
</div>
</div>
<div class="extrainfo"></div>
</div>
</div>
</div>
<div class="col-md-4">
<div id="wire">
<div class="wire-data">
<div id="keyDisplay" class="display">
Alice's Public Key<br/>
<span class="data">--</span>
</div>
<div id="encryptedMsg" class="display">
Bob's encrypted message<br/>
<span class="data">--</span>
</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="panel panel-default machine clearfix" id="bobMachine">
<div class="panel-heading"><h3 class="panel-title">Bob's Machine</h3></div>
<div class="panel-body main">
<form>
<div class="form-group" id="encryptPrivate">
<label for="txtEncryptPrivate">
Private Key for Encryption \(r\)
<span class="glyphicon glyphicon-info-sign" title="Should be greater than or equal to 0 and less than p - 1."></span>
</label>
<div class="input-group">
<input type="text" class="form-control" id="txtEncryptPrivate"/>
<div class="input-group-btn">
<button id="getRandomEncyptKey" class="btn btn-default helpers" type="button">Get Random Key</button>
</div>
</div>
<span class="errorInfo">Should be greater than or equal to 0 and less than p - 1</span>
</div>
<div class="form-group" id="message">
<label for="txtMessage">
Message \(m\)
<span class="glyphicon glyphicon-info-sign" title="Should be greater than 0 and less than or equal to p."></span>
</label>
<input type="text" class="form-control" id="txtMessage"/>
<span class="errorInfo">Should be greater than 0 and less than p.</span>
</div>
<p>Encrypted message is calculated as \((c{_1}, c{_2}) = (g^r \ mod \ p, (h^r m)\ mod \ p) \)</p>
<button id="encrypt" class="btn btn-success" type="button">
<span class="glyphicon glyphicon-arrow-left"></span> Encrypt & Send
</button>
</form>
<div class="extrainfo"></div>
</div>
</div>
</div>
</div>
<div id="references">
<h3>References</h3>
<ul class="list-unstyled">
<li>
<a href="http://en.wikipedia.org/wiki/ElGamal_encryption" target="_blank">
http://en.wikipedia.org/wiki/ElGamal_encryption
</a>
</li>
<li>
<a href="http://ritter.vg/security_adventures_elgamal.html" target="_blank">
http://ritter.vg/security_adventures_elgamal.html
</a>
</li>
<li>
<a href="http://www.bluetulip.org/programs/primitive.html" target="_blank">
http://www.bluetulip.org/programs/primitive.html
</a>
</li>
<li>
<a href="http://cmsc414.wordpress.com/2009/09/23/el-gamal-examples/" target="_blank">
http://cmsc414.wordpress.com/2009/09/23/el-gamal-examples/
</a>
</li>
</ul>
</div>
<hr>
<footer class="footer clearfix">
<p class="pull-left">Copyright © 2024 Debjit Biswas</p>
</footer>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
<script src="js/primes.js"></script>
<script src="js/elgamal.js"></script>
<script src="js/machines.js"></script>
<!--
<script>
if (/debjitbiswas\.com/.test(window.location.href)) {
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-12282646-2', 'auto');
ga('send', 'pageview');
}
</script>
-->
</body>
</html>