-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
250 lines (214 loc) · 7.34 KB
/
index.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
248
249
250
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>cry 2</title>
<link rel="stylesheet" type="text/css" href="src/css/style.css">
<!-- highlight.js -->
<link rel="stylesheet" type="text/css" href="src/css/default.css">
<script src="src/js/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body>
<div class="nav">
<h1>cry 2</h1>
<h3>the cipher</h3>
<a href="https://github.com/Niaev/cry2-web" target="_blank">
<img src="src/img/github-corner.png" alt="Fork me on Github">
</a>
</div>
<div class="main-content container">
<div class="row">
<div class="col form-input">
<textarea id="input" rows="10" placeholder="input message"></textarea><br>
<input type="password" id="key" placeholder="key"><br>
<button id="enc">encrypt</button>
<button id="dec">decrypt</button>
</div>
<div class="col form-input">
<textarea id="output" rows="10" placeholder="output message" readonly></textarea><br>
<button id="copy">copy to clipboard</button>
</div>
</div>
<br>
<div class="read-me">
<h1><a href="cry2-web.herokuapp.com">cry 2</a></h1>
<p><b>cry 2</b> se refere a uma cifra que criei para aprender algumas funções do Javascript e alguns conceitos de criptografia.</p>
<h2>Como funciona?</h2>
<p>Pode-se dizer que <b>cry 2</b> é uma <b>criptografia de chave simétrica</b>, isto é, um método que necessita de um <b>texto original</b> e uma <b>chave</b>, sendo o primeiro um texto qualquer que será criptografado e o segundo um conjunto de caracteres que será utilizado para cifrar e decifrar o <b>texto original</b>. Cada informação para a cifragem é solicitada no formulário disponível em <a href="https://cry2-web.herokuapp.com/">cry2-web.herokuapp.com</a>.</p>
<p>É possível observar nas <a href="https://github.com/Niaev/cry2-web/blob/master/src/js/source.js#L5">linhas 5 e 6 do arquivo <code>source.js</code></a> o seguinte trecho de código:</p>
<pre>
<code class="js">
// banco de caracteres <br>
var alfanum = 'abcdefghijklmnopqrstuvwxyzáàãâéèêíìîóòõôúùûçABCDEFGHIJKLMNOPQRSTUVWXYZÁÀÃÂÉÈÊÍÌÎÓÒÕÔÚÙÛÇ !\"#$%&\'()*+,-./:;<=>?';
</code>
</pre>
<p>A variável <code>alfanum</code>, citada no trecho de código acima, é uma string que contém todos os caracteres que podem ser utilizados no <b>texto original</b> e na <b>chave</b>. Pois é, números não são bem-vindos aqui, mas eu já explico o motivo.</p>
<p>Ao clicar em <code>Encript.</code>, o <b>texto original</b> e a <b>chave</b> tem seus caracteres separados um a um e são comparados aos caracteres da variável <code>alfanum</code>, assim recebem o índice correspondente ao caractere equivalente presente nessa variável.</p>
<table>
<tr>
<th>Texto original</th>
<th>Chave</th>
</tr>
<tr>
<td>Olá, mundo</td>
<td>chave</td>
</tr>
</table>
<p><b>Texto original</b></p>
<table>
<tr>
<th>O</th>
<th>l</th>
<th>á</th>
<th>,</th>
<th> </th>
<th>m</th>
<th>u</th>
<th>n</th>
<th>d</th>
<th>o</th>
</tr>
<tr>
<td>58</td>
<td>11</td>
<td>26</td>
<td>100</td>
<td>88</td>
<td>12</td>
<td>20</td>
<td>13</td>
<td>3</td>
<td>14</td>
</tr>
</table>
<p><b>Chave</b></p>
<table>
<tr>
<th>c</th>
<th>h</th>
<th>a</th>
<th>v</th>
<th>e</th>
</tr>
<tr>
<td>2</td>
<td>7</td>
<td>0</td>
<td>21</td>
<td>4</td>
</tr>
</table>
<p>Essas sequencias de números são transformadas em arrays:</p>
<table>
<tr>
<th>Texto original</th>
<th>Chave</th>
</tr>
<tr>
<td>[ 58, 11, 26, 100, 88, 12, 20, 13, 3, 14 ]</td>
<td>[ 2, 7, 0, 21, 4 ]</td>
</tr>
</table>
<p>Então essas <i>arrays</i> são combinadas pela operação XOR (em javascript representada pelo operador <code>^</code>), letra por letra. Nesse caso, a <b>chave</b> é menor que o <b>texto original</b>, então ela se repete o número de vezes suficiente para criptografar toda a mensagem:</p>
<table>
<tr>
<th>58</th>
<th>11</th>
<th>26</th>
<th>100</th>
<th>88</th>
<th>12</th>
<th>20</th>
<th>13</th>
<th>3</th>
<th>14</th>
</tr>
<tr>
<td>2</td>
<td>7</td>
<td>0</td>
<td>21</td>
<td>3</td>
<td>2</td>
<td>7</td>
<td>0</td>
<td>21</td>
<td>4</td>
</tr>
</table>
<p>Resultado:</p>
<table>
<tr>
<th>56</th>
<th>12</th>
<th>26</th>
<th>113</th>
<th>92</th>
<th>14</th>
<th>19</th>
<th>13</th>
<th>22</th>
<th>10</th>
</tr>
</table>
<p>Os novos números gerados são transformados em caracteres de acordo com os índices correspondentes na variável <code>alfanum</code>. Repare que a variável <code>alfanum</code> tem 110 caracteres, isto é, o seu último caractere tem índice <code>109</code> e que o quarto número do resultado acima é <code>113</code>, maior que o maior índice dentro de <code>alfanum</code>. Nesse caso, <code>113</code> não será transformado em caractere, no texto final ficará representado dessa forma. Então, temos o <b>texto cifrado</b>, resultado final da cifragem:</p>
<table>
<tr>
<th>56</th>
<th>12</th>
<th>26</th>
<th>113</th>
<th>92</th>
<th>14</th>
<th>19</th>
<th>13</th>
<th>22</th>
<th>10</th>
</tr>
<tr>
<td>M</td>
<td>m</td>
<td>á</td>
<td>113</td>
<td>$</td>
<td>o</td>
<td>t</td>
<td>n</td>
<td>w</td>
<td>k</td>
</tr>
</table>
<table>
<tr>
<th>Texto cifrado</th>
</tr>
<tr>
<td>Mmá113$otnwk</td>
</tr>
</table>
<p>O processo reverso, de decifragem, efetuado ao clicar em <code>Decript.</code>, solicita um <b>texto cifrado</b> e uma <b>chave</b>, tendo como resultado o <b>texto original</b>. O método de cifragem e de decifragem são quase iguais, tendo como diferença, na decifragem, o algoritmo que detecta um número no <b>texto cifrado</b>, já que só aparecerão números maiores que 109, todos os números estarão apresentados em trios, esse algoritmo detecta os próximos dois números, formando um trio na hora de decifrar, sendo esse trio, transformado em somente um caractere ao final do processo de decifragem. Eis aqui o motivo para não permitir números nessa criptografia.</p>
<h2>Faça bom uso :)</h2>
</div>
<!--br>
<h1>cry 2 mirrors</h1>
<ul>
<li>
IPFS - <a href="https://ipfs.io/ipfs/Qmbr3UH877ktx6kXi1ahppAHLYBBLkYKeGBddLN36N5s19/">Qmbr3UH877ktx6kXi1ahppAHLYBBLkYKeGBddLN36N5s19</a>
</li>
<li>
Heroku App - <a href="https://cry2-web.herokuapp.com/">https://cry2-web.herokuapp.com/</a>
</li>
</ul>
<br>
<h1>Source code</h1>
<a href="https://github.com/Niaev/cry2-web">https://github.com/Niaev/cry2-web</a>
<br><br-->
</div>
<div class="foot">
<a href="https://kopimi.com/kopimi/"><img src="src/img/kopimi.png"></a><br>
Developed by <b>Niaev</b>
</div>
</body>
<script src="src/js/source.js"></script>
</html>